Skip to content

Skip pnpm install in env setup when node_modules already matches - #3433

Merged
SawyerHood merged 1 commit into
mainfrom
env-setup-skip-unchanged-install
Sep 10, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
env-setup-skip-unchanged-install

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Summary

.bb-env-setup.sh runs pnpm install on every new environment. For a fresh git worktree that is necessary, but copy-on-write environments (reflink copy or Btrfs snapshot of the checkout, via the btrfs-cow provider plugin) arrive with node_modules already installed, and the install is a 5 to 15 s no-op.

This change hashes the install inputs (pnpm-lock.yaml, pnpm-workspace.yaml, package.json, .npmrc) and stores the hash at node_modules/.bb-env-setup-install-hash after a successful install. On the next run, if the stamp matches and node_modules/.pnpm exists, the install is skipped.

Because the stamp lives inside node_modules, it travels with a copied tree and disappears with a fresh worktree, so worktree provisioning is unchanged.

Behavior

Measured on a reflink copy of this repo (Linux, Btrfs):

Scenario Result
Copied tree, no stamp yet installs, 5.8 s, writes stamp
Copied tree, stamp matches skipped, 0.01 s
Lockfile changed installs, 6.3 s, rewrites stamp
No node_modules (fresh worktree) installs, 13.7 s, writes stamp

Other notes:

  • A failed pnpm install no longer writes a stamp, so the next environment retries. The hook still exits 0 in every case, as before.
  • Falls back to always installing when neither sha256sum nor shasum is available.
  • Existing checkouts get the stamp the first time the hook runs after this lands; running sh .bb-env-setup.sh in the project checkout once seeds it for copies made from it.

🤖 Generated with Claude Code

Copy-on-write environments arrive with node_modules already installed;
hash the install inputs into node_modules so setup can skip a no-op
install. Fresh worktrees and changed lockfiles still install as before.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@SawyerHood
SawyerHood merged commit 10bacbc into main Sep 10, 2026
16 checks passed
@SawyerHood
SawyerHood deleted the env-setup-skip-unchanged-install branch September 10, 2026 20:53
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