Skip to content

feat: cache node_modules keyed on lockfile hash to skip npm ci#1

Draft
goastler wants to merge 1 commit into
mainfrom
feat/cache-node-modules
Draft

feat: cache node_modules keyed on lockfile hash to skip npm ci#1
goastler wants to merge 1 commit into
mainfrom
feat/cache-node-modules

Conversation

@goastler

Copy link
Copy Markdown
Member

What

Adds a separate node_modules cache keyed strictly on the lockfile hash and skips npm ci on an exact hit.

  • restore_npm_cache: new node_modules restore with key node-modules-<os>-<arch>-<hashFiles('**/package-lock.json')> and no restore-keys (exact match only — a tree from a different lockfile would be wrong). Exposes node-modules-cache-hit output.
  • npm: skips npm ci when node-modules-cache-hit == 'true'; falls back to npm ci on a miss.
  • save_npm_cache: saves **/node_modules under the same exact key, plus cleanup of stale node_modules caches.

Why

npm ci deletes node_modules and reinstalls from scratch (~2 min). Caching node_modules only pays off paired with skipping the reinstall. A miss falls back to npm ci, so it is always safe.

Caveats

  • The cache is written by save_npm_cache (run on main), readable by all PRs. Lockfile-unchanged PRs hit and skip npm ci; lockfile-changing PRs miss until main re-primes after merge.

Add a separate node_modules cache (exact lockfile-hash key, no fuzzy
fallback) to restore_npm_cache/save_npm_cache, and skip 'npm ci' in the
npm action on an exact hit. 'npm ci' wipes node_modules and reinstalls,
so caching it only pays off paired with skipping the reinstall, saving
~2 min per run when the lockfile is unchanged. A miss falls back to
'npm ci', so it is always safe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant