From f6cf8c51f7a01825e3786417e1eefc5d16009132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sun, 20 Sep 2020 16:54:13 +0100 Subject: [PATCH] fix(ci): use npm ci to install node packages --- .travis.yml | 4 ++-- Dockerfile | 2 +- demo/Dockerfile | 2 +- ui/Makefile | 26 +++++++++++++++----------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79df7fc99..981c90368 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ __defaults_go: &DEFAULTS_GO go: "1.15.2" cache: directories: - - ui/node_modules + - "$HOME/.npm" # https://restic.net/blog/2018-09-02/travis-build-cache - $HOME/.cache/go-build - $HOME/gopath/pkg/mod @@ -21,7 +21,7 @@ __defaults_js: &DEFAULTS_JS install: [] cache: directories: - - ui/node_modules + - "$HOME/.npm" env: - NODE_ENV=test diff --git a/Dockerfile b/Dockerfile index be67af52c..a5f0ea835 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM node:12.18.4-alpine as nodejs-builder RUN mkdir -p /src/ui COPY ui/package.json ui/package-lock.json /src/ui/ ENV NODE_ENV=production -RUN cd /src/ui && npm install +RUN cd /src/ui && npm ci RUN apk add make git COPY ui /src/ui RUN make -C /src/ui build diff --git a/demo/Dockerfile b/demo/Dockerfile index acf968440..7e67eb5f9 100644 --- a/demo/Dockerfile +++ b/demo/Dockerfile @@ -2,7 +2,7 @@ FROM node:12.18.4-alpine as nodejs-builder RUN mkdir -p /src/ui COPY ui/package.json ui/package-lock.json /src/ui/ ENV NODE_ENV=production -RUN cd /src/ui && npm install +RUN cd /src/ui && npm ci RUN apk add make git COPY ui /src/ui RUN make -C /src/ui build diff --git a/ui/Makefile b/ui/Makefile index ee4467027..34f192d0f 100644 --- a/ui/Makefile +++ b/ui/Makefile @@ -3,17 +3,21 @@ # based on http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) -NODE_PATH := $(shell npm bin) -PATH := $(PATH):$(NODE_PATH) -SHELL := env PATH=$(PATH) /bin/sh - -$(NODE_PATH)/%: package.json package-lock.json - @export D="$*"; \ - if [ "$*" = "commitlint-travis" ]; then export D="@commitlint/travis-cli" ; fi; \ - if [ "$*" = "build-storybook" ]; then export D="@storybook/react" ; fi; \ - if [ "$*" = "percy-storybook" ]; then export D="@percy-io/percy-storybook" ; fi; \ - if [ -d "$(CURDIR)/node_modules/$$D" ] && [ ! -x "$@" ]; then (echo "resetting node_modules" && npm ci); else npm install ; fi - @if [ -x $@ ]; then touch -c $@ ; else echo "missing script: $@" ; exit 1; fi +NODE_PATH := $(shell npm bin) +NODE_MODULES := $(shell dirname `npm bin`) +NODE_INSTALL := $(NODE_MODULES)/.install + +PATH := $(PATH):$(NODE_PATH) +SHELL := env PATH=$(PATH) /bin/sh + +.DEFAULT_GOAL := build/index.html + +$(NODE_INSTALL): package.json package-lock.json + @if [ -e $(NODE_INSTALL) ]; then npm install ; else npm ci; fi + touch $@ + +$(NODE_PATH)/%: $(NODE_INSTALL) + @if [ ! -x $@ ]; then echo "missing script: $@" ; exit 1; fi build/index.html: $(NODE_PATH)/react-scripts $(call rwildcard, public src, *) @rm -fr node_modules/.cache/eslint-loader