From bfc4039b3e1171b596889f48473f9a0492c2f85f Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 12 Sep 2019 10:47:58 +0200 Subject: [PATCH] Use and ship package-lock.json npm install has been generating package-lock.json [1] for long enough for us to start relying on it. Replace the unreliable and hacky `$NODE_MODULES_TEST` file with just comparing package.json against package-lock.json to decide when to run npm install. This will finally avoid unnecessary `npm install` runs, but start to run these when git switching branches that have a different package.json. Ship package-lock.json in release tarballs, so that node_modules/ can be reconstructed exactly as it was when making the release. [1] https://docs.npmjs.com/files/package-lock.json Closes #222 --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a73b823..dbc77c0 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ TEST_OS = centos-7 endif export TEST_OS VM_IMAGE=$(CURDIR)/test/images/$(TEST_OS) -# one example directory from `npm install` to check if that already ran -NODE_MODULES_TEST=node_modules/po2json +# stamp file to check if/when npm install ran +NODE_MODULES_TEST=package-lock.json # one example file in dist/ from webpack to check if that already ran WEBPACK_TEST=dist/index.html @@ -85,18 +85,18 @@ devel-install: $(WEBPACK_TEST) ln -s `pwd`/dist ~/.local/share/cockpit/$(PACKAGE_NAME) # when building a distribution tarball, call webpack with a 'production' environment -# ship a stub node_modules/ so that `make` works without re-running `npm install` +# we don't ship node_modules for license and compactness reasons; we ship a +# pre-built dist/ (so it's not necessary) and ship packge-lock.json (so that +# node_modules/ can be reconstructed if necessary) dist-gzip: NODE_ENV=production dist-gzip: all cockpit-$(PACKAGE_NAME).spec if type appstream-util >/dev/null 2>&1; then appstream-util validate-relax --nonet *.metainfo.xml; fi mv node_modules node_modules.release - mkdir -p $(NODE_MODULES_TEST) touch -r package.json $(NODE_MODULES_TEST) touch dist/* tar czf cockpit-$(PACKAGE_NAME)-$(VERSION).tar.gz --transform 's,^,cockpit-$(PACKAGE_NAME)/,' \ --exclude cockpit-$(PACKAGE_NAME).spec.in \ - $$(git ls-files) cockpit-$(PACKAGE_NAME).spec dist/ node_modules - rm -rf node_modules + $$(git ls-files) package-lock.json cockpit-$(PACKAGE_NAME).spec dist/ mv node_modules.release node_modules srpm: dist-gzip cockpit-$(PACKAGE_NAME).spec