Skip to content

feat: add calculateFingerprint pnpmfile hook - #13690

Closed
everett1992 wants to merge 2 commits into
pnpm:mainfrom
everett1992:extra-checksum-hook
Closed

everett1992 wants to merge 2 commits into
pnpm:mainfrom
everett1992:extra-checksum-hook

Conversation

@everett1992

@everett1992 everett1992 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a new pnpmfile hook, calculateFingerprint, that returns a fingerprint of any external state the pnpmfile's behavior depends on — for example, the state of a custom package source used by a custom resolver. The value is recorded in the workspace state file after installs and compared by checkDepsStatus, so the verify-deps-before-run and optimistic-repeat-install fast paths invalidate when it changes and a full install (including shouldRefreshResolution hooks) runs.

Why

Follow-up to #9516 / #10995. The custom resolver API's shouldRefreshResolution hook exists for package sources where content can change behind an unchanged name@version, but both fast paths use checkDepsStatus, which only examines local files (manifests, lockfile, patches, pnpmfile mtimes). A pnpmfile whose hooks read external state can be logically changed while every local file is unchanged — so under the pnpm 11 defaults (optimisticRepeatInstall: true, verifyDepsBeforeRun: install), resolver-refresh users silently go stale, which #10995 could only warn about. Running shouldRefreshResolution per lockfile entry inside the fast path was rejected there as too expensive; this hook is the cheap alternative — one author-controlled value, one comparison.

Design notes

  • Fingerprint, not a boolean "changed?": only pnpm knows when an install actually succeeds, and the record must advance only then. A self-comparing hook would have to commit its own "last seen" state at check time — corrupting it when the triggered install fails, when verifyDepsBeforeRun is warn/error/declined prompt, or when two processes race. The recorded value advances only inside updateWorkspaceState after a successful install, like every other staleness input. The cost is that hooks must be deterministic for unchanged state.
  • Workspace state file, not the lockfile: the value may be machine-specific (absolute paths, local mtimes), so it must never enter a committed file. This is also why the existing pnpmfileChecksum (lockfile-recorded content hash) can't carry it.
  • Multiple pnpmfiles may define the hook; the cooked hook combines their values sorted by file path, since pnpmfiles load concurrently.
  • The comparison sits early in _checkDepsStatus (after the settings/configDependencies checks, before any filesystem work) and only runs when a hook exists or a value was recorded, so projects without the hook pay nothing.

Pacquet parity

Deliberately not ported. Pacquet does not run pnpmfiles, and its optimistic-repeat-install fast path is uniformly unaware of hook effects today (the patchesOrHooksAreModified port does not exist yet); guarding only this field would be an inconsistent slice of that pre-existing gap. The schema change is tolerated as-is: serde ignores the unknown fingerprint field on read, and if a pacquet install rewrites the state without it, pnpm sees the missing fingerprint on its next run, invalidates, and re-records — fail-safe in the extra-install direction, never toward staleness. Fast-path hook awareness for pacquet (this field plus pnpmfiles mtime checks) is proposed as follow-up.

Testing

  • @pnpm/hooks.pnpmfile: hook cooking — absent, single, and multiple pnpmfiles (passed in reverse order to prove the deterministic sort).
  • @pnpm/deps.status: all four comparison edge cases (changed, newly appeared, removed, unchanged-continues-past).
  • End-to-end against the rebuilt bundle: install records the fingerprint in the workspace state; repeat install short-circuits; a changed value forces a full install and re-records; pnpm run triggers the verify-deps install; pnpm-lock.yaml stays untouched throughout.

Docs PR: pnpm/pnpm.io#860.


Written by an agent (Kiro, claude-fable-5), directed and reviewed by @everett1992.

Summary by CodeRabbit

  • New Features

    • Added support for calculating fingerprints from pnpm hooks to track external dependency resolution changes.
    • Fingerprints are saved with workspace state and evaluated during dependency freshness checks.
    • Supports multiple fingerprint sources with deterministic results and asynchronous calculation.
  • Bug Fixes

    • Dependency checks now trigger a full install when the recorded fingerprint changes, is added, or removed.
    • Fingerprint calculation failures now clearly mark dependencies as outdated.
  • Documentation

    • Documented the new fingerprint hook and its availability limitations.

@everett1992
everett1992 requested a review from zkochan as a code owner August 6, 2026 23:53
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 28a2c340-3529-44ad-ae54-b7710e7db62a

📥 Commits

Reviewing files that changed from the base of the PR and between 1853160 and 55fbc56.

📒 Files selected for processing (2)
  • pnpm11/deps/status/src/checkDepsStatus.ts
  • pnpm11/deps/status/test/checkDepsStatus.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm11/deps/status/src/checkDepsStatus.ts
  • pnpm11/deps/status/test/checkDepsStatus.test.ts

📝 Walkthrough

Walkthrough

The PR adds a calculateFingerprint pnpmfile hook. pnpm stores the combined result in workspace state and compares it during dependency status checks. Fingerprint changes mark dependencies outdated and trigger a full install.

Changes

Pnpmfile fingerprint freshness

Layer / File(s) Summary
Collect and combine pnpmfile fingerprints
pnpm11/hooks/pnpmfile/src/*, pnpm11/hooks/pnpmfile/test/index.ts
Adds optional fingerprint hooks, deterministic source-path ordering, concurrent execution, JSON-encoded results, and coverage for empty, single, and multiple hooks.
Persist fingerprints during installation
pnpm11/workspace/state/src/*, pnpm11/installing/commands/src/installDeps.ts, .changeset/fingerprint-hook.md
Adds the optional workspace-state fingerprint and passes calculated fingerprints through single-project, standard, and recursive installation paths.
Compare fingerprints during dependency status checks
pnpm11/deps/status/src/checkDepsStatus.ts, pnpm11/deps/status/test/checkDepsStatus.test.ts
Marks dependencies outdated when fingerprints change or calculation fails. Tests cover changed, added, removed, unchanged, and failed fingerprints, plus later patch validation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Pnpmfile
  participant CookedHooks
  participant InstallDeps
  participant WorkspaceState
  participant CheckDepsStatus

  Pnpmfile->>CookedHooks: provide calculateFingerprint
  CookedHooks-->>InstallDeps: return combined fingerprint
  InstallDeps->>WorkspaceState: store fingerprint after installation
  CheckDepsStatus->>CookedHooks: calculate current fingerprint
  CheckDepsStatus->>WorkspaceState: compare with stored fingerprint
  CheckDepsStatus-->>InstallDeps: report outdated when fingerprints differ
Loading

Possibly related PRs

  • pnpm/pnpm#13418: Both changes add pnpmfile-derived state validation to dependency freshness checks.
  • pnpm/pnpm#13463: Both changes modify dependency freshness verification using pnpmfile or lockfile state.

Suggested labels: product: pnpm@11

Suggested reviewers: zkochan

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (3): Last reviewed commit: "fix: invalidate deterministically when t..." | Re-trigger Greptile

Comment thread hooks/pnpmfile/src/requireHooks.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
hooks/pnpmfile/src/requireHooks.ts (1)

223-223: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the redundant section label.

Line 223 repeats the following code. Remove this comment. The comment at Lines 230-231 already documents the required ordering invariant.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@hooks/pnpmfile/src/requireHooks.ts` at line 223, Remove the redundant
“calculateFingerprint” comment near the fingerprint logic, while preserving the
implementation and the existing ordering-invariant documentation later in the
section.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/fingerprint-hook.md:
- Around line 9-11: Update the calculateFingerprint release note in the
changeset to replace the historical rationale with a concise statement that this
hook is unavailable in pacquet, while preserving the description of its
TypeScript CLI behavior.

In `@hooks/pnpmfile/src/requireHooks.ts`:
- Around line 229-236: The combined fingerprint produced by
cookedHooks.calculateFingerprint must use an unambiguous structured encoding:
replace newline joining of checksums with JSON.stringify(checksums) in
hooks/pnpmfile/src/requireHooks.ts lines 229-236. Update the expected
fingerprint format in hooks/pnpmfile/test/index.ts lines 119-125 and add
coverage for distinct hook results containing newlines that would collide under
concatenation.

---

Nitpick comments:
In `@hooks/pnpmfile/src/requireHooks.ts`:
- Line 223: Remove the redundant “calculateFingerprint” comment near the
fingerprint logic, while preserving the implementation and the existing
ordering-invariant documentation later in the section.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5163189e-0d8a-4aa1-8ea2-4b07b5c96bef

📥 Commits

Reviewing files that changed from the base of the PR and between 8ae2e28 and 5872eda.

⛔ Files ignored due to path filters (2)
  • hooks/pnpmfile/test/__fixtures__/fingerprintA.js is excluded by !**/__fixtures__/**
  • hooks/pnpmfile/test/__fixtures__/fingerprintB.js is excluded by !**/__fixtures__/**
📒 Files selected for processing (10)
  • .changeset/fingerprint-hook.md
  • deps/status/src/checkDepsStatus.ts
  • deps/status/test/checkDepsStatus.test.ts
  • hooks/pnpmfile/src/Hooks.ts
  • hooks/pnpmfile/src/requireHooks.ts
  • hooks/pnpmfile/test/index.ts
  • installing/commands/src/installDeps.ts
  • workspace/state/src/createWorkspaceState.ts
  • workspace/state/src/types.ts
  • workspace/state/src/updateWorkspaceState.ts

Comment thread .changeset/fingerprint-hook.md Resolved
A pnpmfile can now export hooks.calculateFingerprint, returning a
fingerprint of external state its behavior depends on (e.g. a custom
package source used by a custom resolver). The value is recorded in the
workspace state file after installs and compared by checkDepsStatus, so
the verify-deps-before-run and optimistic-repeat-install fast paths
invalidate when it changes and a full install (including
shouldRefreshResolution hooks) runs.

The fingerprint is deliberately never written to the lockfile, so it
may be machine-specific. Multiple pnpmfiles combine as a JSON array
sorted by file path, keeping component boundaries unambiguous.

Pacquet is deliberately untouched. It does not run pnpmfiles, and its
optimistic-repeat-install fast path is uniformly unaware of hook
effects today; guarding only this field would be an inconsistent slice
of that pre-existing gap. The schema change is tolerated as-is: serde
ignores the unknown fingerprint field on read, and a pacquet rewrite of
the state without it makes pnpm invalidate and re-record on its next
run - fail-safe toward an extra install, never toward staleness.

Closes the gap warned about in pnpm#10995.
@everett1992
everett1992 force-pushed the extra-checksum-hook branch from 5872eda to 1853160 Compare August 7, 2026 00:22
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pnpm11/hooks/pnpmfile/src/requireHooks.ts (1)

223-223: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the restating comment.

// calculateFingerprint repeats the following condition. Remove it because it documents no contract or invariant.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm11/hooks/pnpmfile/src/requireHooks.ts` at line 223, Remove the redundant
`// calculateFingerprint` comment immediately before the repeated condition,
leaving the surrounding logic unchanged.

Sources: Coding guidelines, Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pnpm11/deps/status/src/checkDepsStatus.ts`:
- Around line 257-267: The fingerprint hook call in
pnpm11/deps/status/src/checkDepsStatus.ts lines 257-267 must catch thrown or
rejected calculateFingerprint failures and return upToDate: false instead of
allowing the broad status-check catch to produce undefined; add a regression
test in pnpm11/deps/status/test/checkDepsStatus.test.ts lines 516-665 with a
rejected hook and assert upToDate is false.

---

Nitpick comments:
In `@pnpm11/hooks/pnpmfile/src/requireHooks.ts`:
- Line 223: Remove the redundant `// calculateFingerprint` comment immediately
before the repeated condition, leaving the surrounding logic unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 85f06daf-e097-43af-b1da-1e6f814c9fd8

📥 Commits

Reviewing files that changed from the base of the PR and between 8ae2e28 and 1853160.

⛔ Files ignored due to path filters (2)
  • pnpm11/hooks/pnpmfile/test/__fixtures__/fingerprintA.js is excluded by !**/__fixtures__/**
  • pnpm11/hooks/pnpmfile/test/__fixtures__/fingerprintB.js is excluded by !**/__fixtures__/**
📒 Files selected for processing (10)
  • .changeset/fingerprint-hook.md
  • pnpm11/deps/status/src/checkDepsStatus.ts
  • pnpm11/deps/status/test/checkDepsStatus.test.ts
  • pnpm11/hooks/pnpmfile/src/Hooks.ts
  • pnpm11/hooks/pnpmfile/src/requireHooks.ts
  • pnpm11/hooks/pnpmfile/test/index.ts
  • pnpm11/installing/commands/src/installDeps.ts
  • pnpm11/workspace/state/src/createWorkspaceState.ts
  • pnpm11/workspace/state/src/types.ts
  • pnpm11/workspace/state/src/updateWorkspaceState.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/fingerprint-hook.md

…fails

A throwing hook previously fell into checkDepsStatus's outer catch,
yielding upToDate: undefined - which runDepsStatusCheck can treat as
"unknown" and skip the install for. Catch at the call site and return
upToDate: false so a broken hook always invalidates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant