BlueGit

timfa questward

Skip npm install on deploy when package manifests are unchanged

Hash package.json + package-lock.json into node_modules/.questward-npm-stamp
after install; the next start skips npm when the hash still matches.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
74be9c50963959812cdabd3ec62aee5074296f66
Parent
e0365245
2 files changed +36 −3
deploy/README.md +3 −1
@@ -6,7 +6,9 @@ On **every** service start (clean midnight restart, crash, or power loss recover
6 6
7 7 1. `git fetch` + `git reset --hard origin/<branch>`
8 8 2. `git pull --ff-only`
9 3. `npm install --omit=dev`
9 3. `npm install --omit=dev` — **skipped** when `package.json` + `package-lock.json`
10 match the stamp written under `node_modules/.questward-npm-stamp` after the last
11 successful install (node_modules survives hard-reset because it is gitignored)
10 12 4. `git submodule update --init --recursive`
11 13 5. `npm run build:client` (concatenates FrameworkV3 → `client/frameworkv3/js/framework.js`)
12 14 6. start `node --experimental-sqlite server/src/index.js`
@@ -6,7 +6,9 @@ On **every** service start (clean midnight restart, crash, or power loss recover
6
6
71. `git fetch` + `git reset --hard origin/<branch>`
71. `git fetch` + `git reset --hard origin/<branch>`
82. `git pull --ff-only`
82. `git pull --ff-only`
93. `npm install --omit=dev`
93. `npm install --omit=dev` — **skipped** when `package.json` + `package-lock.json`
10 match the stamp written under `node_modules/.questward-npm-stamp` after the last
11 successful install (node_modules survives hard-reset because it is gitignored)
104. `git submodule update --init --recursive`
124. `git submodule update --init --recursive`
115. `npm run build:client` (concatenates FrameworkV3 → `client/frameworkv3/js/framework.js`)
135. `npm run build:client` (concatenates FrameworkV3 → `client/frameworkv3/js/framework.js`)
126. start `node --experimental-sqlite server/src/index.js`
146. start `node --experimental-sqlite server/src/index.js`
deploy/start-server.sh +33 −2
@@ -17,8 +17,39 @@ git pull --ff-only origin "$BRANCH" || true
17 17 DEPLOY_DIR="$(cd "$(dirname "$0")" && pwd)"
18 18 chmod +x "$DEPLOY_DIR/start-server.sh" "$DEPLOY_DIR/install-service.sh" "$DEPLOY_DIR/update-if-requested.mjs" 2>/dev/null || true
19 19
20 echo "[deploy] npm install…"
21 npm install --omit=dev
20 # Skip npm install when package manifests are unchanged since the last successful install.
21 # Stamp lives under node_modules/ (gitignored) so it survives hard-reset/pull.
22 NPM_STAMP="node_modules/.questward-npm-stamp"
23 npm_manifest_hash ()
24 {
25 # Prefer sha256sum; fall back to shasum (macOS) / openssl.
26 if command -v sha256sum >/dev/null 2>&1
27 then
28 cat package.json package-lock.json | sha256sum | awk '{ print $1 }'
29 elif command -v shasum >/dev/null 2>&1
30 then
31 cat package.json package-lock.json | shasum -a 256 | awk '{ print $1 }'
32 else
33 cat package.json package-lock.json | openssl dgst -sha256 | awk '{ print $NF }'
34 fi
35 }
36
37 WANT_HASH="$(npm_manifest_hash)"
38 HAVE_HASH=""
39 if [[ -f "$NPM_STAMP" ]]
40 then
41 HAVE_HASH="$(tr -d '[:space:]' < "$NPM_STAMP" || true)"
42 fi
43
44 if [[ -d node_modules && -n "$HAVE_HASH" && "$HAVE_HASH" == "$WANT_HASH" ]]
45 then
46 echo "[deploy] npm install skipped (package.json / package-lock.json unchanged)"
47 else
48 echo "[deploy] npm install…"
49 npm install --omit=dev
50 mkdir -p node_modules
51 printf '%s\n' "$WANT_HASH" > "$NPM_STAMP"
52 fi
22 53
23 54 echo "[deploy] Submodules…"
24 55 git submodule update --init --recursive
@@ -17,8 +17,39 @@ git pull --ff-only origin "$BRANCH" || true
17DEPLOY_DIR="$(cd "$(dirname "$0")" && pwd)"
17DEPLOY_DIR="$(cd "$(dirname "$0")" && pwd)"
18chmod +x "$DEPLOY_DIR/start-server.sh" "$DEPLOY_DIR/install-service.sh" "$DEPLOY_DIR/update-if-requested.mjs" 2>/dev/null || true
18chmod +x "$DEPLOY_DIR/start-server.sh" "$DEPLOY_DIR/install-service.sh" "$DEPLOY_DIR/update-if-requested.mjs" 2>/dev/null || true
19
19
20echo "[deploy] npm install…"
20# Skip npm install when package manifests are unchanged since the last successful install.
21npm install --omit=dev
21# Stamp lives under node_modules/ (gitignored) so it survives hard-reset/pull.
22NPM_STAMP="node_modules/.questward-npm-stamp"
23npm_manifest_hash ()
24{
25 # Prefer sha256sum; fall back to shasum (macOS) / openssl.
26 if command -v sha256sum >/dev/null 2>&1
27 then
28 cat package.json package-lock.json | sha256sum | awk '{ print $1 }'
29 elif command -v shasum >/dev/null 2>&1
30 then
31 cat package.json package-lock.json | shasum -a 256 | awk '{ print $1 }'
32 else
33 cat package.json package-lock.json | openssl dgst -sha256 | awk '{ print $NF }'
34 fi
35}
36
37WANT_HASH="$(npm_manifest_hash)"
38HAVE_HASH=""
39if [[ -f "$NPM_STAMP" ]]
40then
41 HAVE_HASH="$(tr -d '[:space:]' < "$NPM_STAMP" || true)"
42fi
43
44if [[ -d node_modules && -n "$HAVE_HASH" && "$HAVE_HASH" == "$WANT_HASH" ]]
45then
46 echo "[deploy] npm install skipped (package.json / package-lock.json unchanged)"
47else
48 echo "[deploy] npm install…"
49 npm install --omit=dev
50 mkdir -p node_modules
51 printf '%s\n' "$WANT_HASH" > "$NPM_STAMP"
52fi
22
53
23echo "[deploy] Submodules…"
54echo "[deploy] Submodules…"
24git submodule update --init --recursive
55git submodule update --init --recursive