Skip to content

Commit def7374

Browse files
committed
Only install ui dependencies when necessary
1 parent de837e3 commit def7374

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

ui/DockerfileDev

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ ENV NODE_ENV=development
55
ARG GITHUB_TOKEN
66
ENV GITHUB_TOKEN=${GITHUB_TOKEN}
77

8-
98
RUN apk add --no-cache git bash \
109
&& npm update -g npm
1110

ui/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/scripts/install-dependencies.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# The files that, when changed, trigger an install.
6+
LOCK_FILES="package.json package-lock.json"
7+
8+
# The file into which the latest install hash is stored.
9+
HASH_FILE="node_modules/.deps-lock_hash"
10+
11+
# The file that marks the node version that was used for the latest install.
12+
NODE_MARKER_FILE="node_modules/.deps-node_$(node -v)"
13+
14+
# Compute the hash of the current and latest dependencies.
15+
current_hash="$(cat $LOCK_FILES 2>/dev/null | sha256sum | awk '{print $1}')"
16+
stored_hash="$(cat "$HASH_FILE" 2>/dev/null || true)"
17+
18+
if [ ! -d node_modules ] || [ "$current_hash" != "$stored_hash" ] || [ ! -f "$NODE_MARKER_FILE" ]; then
19+
# Reinstall if the lock files or node version changed, or if there simply is no `node_modules` directory.
20+
echo "Dependencies out of date -> running install"
21+
npm ci
22+
printf "%s" "$current_hash" > "$HASH_FILE"
23+
: > "$NODE_MARKER_FILE"
24+
else
25+
echo "Dependencies up of date -> skipping install"
26+
fi

ui/start.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/bin/bash
22

3+
set -e
4+
35
# Install latest dependencies.
4-
npm ci --no-audit
6+
scripts/install-dependencies.sh
57

68
# Remove previous build output.
7-
rm -r dist/*
9+
rm -rf dist/*
810

911
# Start the development server.
1012
npm run start

0 commit comments

Comments
 (0)