Repository navigation
Conversation
📝 WalkthroughWalkthroughThe PR adds asynchronous ChangesPacking hooks and published manifests
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant PackApi
participant NodeHooks
participant Pnpmfile
participant Tarball
CLI->>PackApi: api(PackOptions with hooks)
PackApi->>NodeHooks: apply beforePacking
NodeHooks->>Pnpmfile: beforePacking(manifest, dir, context)
Pnpmfile-->>NodeHooks: updated manifest
NodeHooks-->>PackApi: transformed manifest
PackApi->>Tarball: compute packlist and write tarball
Assessment against linked issues
Out-of-scope changes
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
pnpm11/pnpm/bundle-deps.tsParsing error: "parserOptions.project" has been provided for 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. Comment |
PR Summary by QodoFix published pnpm manifest to omit bundled dependency fields across pnpm & pacquet
AI Description
Diagram
High-Level Assessment
Files changed (16)
|
PR Code Suggestions ✨Latest suggestions up to 8bdec82 Warning
Previous suggestionsSuggestions up to commit 77812a5
|
|||||||||||||||||||||||
The published `pnpm` package bundles its runtime dependencies into
`dist/node_modules`, so its manifest must not declare `dependencies` or
`devDependencies` — otherwise pnpm installs them a second time, and the
internal-only devDependencies (e.g. `@pnpm/test-ipc-server`) aren't
published, so the install 404s. pnpm 11.11.0 published with neither field.
The workspace `.pnpmfile.cjs` `beforePacking` hook drops these fields when
packing, but the release for 11.12.0 ran a pnpm 12 alpha (pacquet) that
does not yet honor `beforePacking`, so the fields leaked into the published
manifest and broke installs.
This fixes the pnpm 12 gap and adds a stopgap for it:
1. pacquet now honors `beforePacking` pnpmfile hooks during pack/publish,
so once the release runs a pnpm that includes this, the hook drops the
fields as intended:
- PnpmfileHooks::before_packing (trait default no-op) plus a worker JS
branch and NodeJsHooks impl, called as `beforePacking(pkg, dir, ctx)`
with pnpm's `?? manifest` fallback.
- pack::api is now async; it loads the workspace-root and
config-dependency pnpmfiles (via a resolve_pnpmfile_paths helper
shared with the updateConfig hook) and applies beforePacking to the
published manifest before the file list is computed, so a hook may
still change files/bin/dependency fields. The async change ripples
through pack::run, dispatch_query::pack, publish, and the napi bridge.
2. As a temporary workaround until the release runs such a pnpm,
bundle-deps.ts (the CLI's prepublishOnly) strips dependencies and
devDependencies from the on-disk manifest after building the bundle.
pack re-reads the manifest after prepublishOnly, so the fields never
reach the tarball regardless of the beforePacking gap.
Integration tests drive the real binary through `pnpm pack` with a
`.pnpmfile.cjs` beforePacking hook, including the release shape a
workspace-root pnpmfile applied to a `--filter`-selected sub-package.
Closes #12955.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Micro-Benchmark ResultsLinux |
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
The unified release flow (#12949) requires a changeset for Rust changes. The TypeScript and pacquet sides fix different things and get different release notes, so they are separate changeset files: "pnpm" for the published-manifest dependency strip, and "pacquet" for applying the beforePacking hook during pack/publish (the napi bindings bump with pacquet through its fixed group). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #12964 +/- ##
==========================================
- Coverage 85.26% 85.25% -0.01%
==========================================
Files 486 486
Lines 77280 77368 +88
==========================================
+ Hits 65890 65962 +72
- Misses 11390 11406 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Addresses a review note: the extracted stripBundledDependenciesFromManifest helper was declared before its only call site, against the repo's declare-after-use rule. It's a trivial final step in the script, so inline it after createDistNodeModules() instead of adding an out-of-order helper. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Confidence Score: 5/5Safe to merge; the async propagation through pack/publish is consistent, the napi shim correctly guards with an empty hook list, and integration tests exercise the hook path end-to-end. The change is a targeted bug fix with a clear root cause and two complementary remediation layers. The beforePacking hook wiring follows the exact same pattern as the existing readPackage and filterLog hooks. The block_on usage in napi is safe because before_packing_hooks is hard-coded to empty there. Integration tests verify the packed manifest reflects hook modifications in all three relevant configurations. No files require special attention. The pnpm11/pnpm/bundle-deps.ts stopgap has a clear removal marker in its inline comment; the Rust changes are well-tested. Reviews (2): Last reviewed commit: "perf(pack): load beforePacking pnpmfiles..." | Re-trigger Greptile |
|
Code review by qodo was updated up to the latest commit 8bdec82 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
pnpm/crates/cli/src/cli_args/pack.rs (1)
153-182: 🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy liftRecursive
pnpm pack -rreloads pnpmfile hooks per project — see consolidated comment.Each iteration of this loop calls
pack_options(which re-resolvespnpmfilesvia filesystem lookups) and thenapi(...), which reinitializes the hook worker for the same pnpmfile(s) from scratch every time. In a large monorepo with many selected packages, this repeats fs stats and Node-worker spin-up per package. Detailed in the consolidated comment below.Also applies to: 216-217
🤖 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 `@pnpm/crates/cli/src/cli_args/pack.rs` around lines 153 - 182, The recursive packing loop should reuse shared pnpmfile hook resolution and worker state instead of rebuilding them for every project. Update the `pack_options`/`api` flow used inside the `for root in chunk` loop to initialize the hooks once for the recursive operation and pass or reuse that state for each package while preserving each project’s existing pack options and results.pnpm/crates/pack/src/lib.rs (1)
265-267: 🔒 Security & Privacy | 🔴 Critical | ⚡ Quick winRe-run the version separator guard after
beforePacking.resolve_output()only validates--out; it does not reject/or\\inversion. Sincepublished_versioncomes from the hook-mutated manifest, a hook can inject path components into the default<name>-<version>.tgzpath and escapedest_dir.🤖 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 `@pnpm/crates/pack/src/lib.rs` around lines 265 - 267, Reapply the slash and backslash validation to the hook-mutated published version after beforePacking and before resolve_output constructs the default package path. Ensure the guard covers published_version, rejecting path components before the archive destination is derived, while preserving the existing InvalidPackageVersion error behavior.
🧹 Nitpick comments (1)
pnpm/crates/pack/src/tests.rs (1)
41-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftNo unit coverage of the
beforePackinghook path in this crate.Every fixture here sets
pnpmfiles: Vec::new(), soapply_before_packing's hook-loading/chaining/error-mapping logic inlib.rsis only exercised by the Node-process-backed CLI integration test (pnpm/crates/cli/tests/pack.rs), not by this crate's fast unit tests. This lines up with Codecov's reported missing coverage inpnpm/crates/pack/src/lib.rs.Consider adding a test double for
PnpmfileHooks(thePnpmfileHookstrait is already mocked elsewhere, e.g.RecordingHooksinresolving-deps-resolver/src/tests.rs) soapply_before_packing's ordering andPackError::BeforePackingmapping can be unit-tested without spinning a Node process — this likely requiresapply_before_packing/apito accept pre-loaded hooks rather than hardcodingfinder::load_pnpmfile_at. Perpnpm/AGENTS.md, dependency injection is justified here since the Node worker is an external-service branch that a real fixture can't exercise cheaply.Based on learnings/path instructions: "Prefer real fixtures... use dependency injection only for unreachable filesystem, time, process-global-state, or external-service branches."
Also applies to: 46-60
🤖 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 `@pnpm/crates/pack/src/tests.rs` around lines 41 - 44, Add fast unit coverage in the pack crate for apply_before_packing using a PnpmfileHooks test double, following the existing RecordingHooks pattern. Adjust api/apply_before_packing to accept pre-loaded hooks through dependency injection instead of always calling finder::load_pnpmfile_at, then test hook ordering and failures mapping to PackError::BeforePacking without starting Node. Keep real fixtures for paths that do not require the external-service seam.Source: 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 `@pnpm/crates/pack/src/lib.rs`:
- Around line 353-393: Cache the hooks loaded by finder::load_pnpmfile_at so
repeated apply_before_packing calls reuse the same loaded pnpmfile worker
instead of reinitializing it per package. Introduce or use a shared cache keyed
by pnpmfile path across the recursive packing flow, while preserving hook
execution order and per-invocation logging context in apply_before_packing.
---
Outside diff comments:
In `@pnpm/crates/cli/src/cli_args/pack.rs`:
- Around line 153-182: The recursive packing loop should reuse shared pnpmfile
hook resolution and worker state instead of rebuilding them for every project.
Update the `pack_options`/`api` flow used inside the `for root in chunk` loop to
initialize the hooks once for the recursive operation and pass or reuse that
state for each package while preserving each project’s existing pack options and
results.
In `@pnpm/crates/pack/src/lib.rs`:
- Around line 265-267: Reapply the slash and backslash validation to the
hook-mutated published version after beforePacking and before resolve_output
constructs the default package path. Ensure the guard covers published_version,
rejecting path components before the archive destination is derived, while
preserving the existing InvalidPackageVersion error behavior.
---
Nitpick comments:
In `@pnpm/crates/pack/src/tests.rs`:
- Around line 41-44: Add fast unit coverage in the pack crate for
apply_before_packing using a PnpmfileHooks test double, following the existing
RecordingHooks pattern. Adjust api/apply_before_packing to accept pre-loaded
hooks through dependency injection instead of always calling
finder::load_pnpmfile_at, then test hook ordering and failures mapping to
PackError::BeforePacking without starting Node. Keep real fixtures for paths
that do not require the external-service seam.
🪄 Autofix (Beta)
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: d4f92b95-5622-4e59-943e-15fb5601f209
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (17)
.changeset/pacquet-before-packing-hook.md.changeset/pnpm-publish-strip-bundled-deps.mdpnpm/crates/cli/src/cli_args/dispatch.rspnpm/crates/cli/src/cli_args/dispatch_query.rspnpm/crates/cli/src/cli_args/pack.rspnpm/crates/cli/src/cli_args/publish.rspnpm/crates/cli/src/cli_args/publish/tests.rspnpm/crates/cli/src/config_deps.rspnpm/crates/cli/tests/pack.rspnpm/crates/hooks/src/lib.rspnpm/crates/hooks/src/node_runtime.rspnpm/crates/hooks/src/worker.rspnpm/crates/napi/src/pack.rspnpm/crates/pack/Cargo.tomlpnpm/crates/pack/src/lib.rspnpm/crates/pack/src/tests.rspnpm11/pnpm/bundle-deps.ts
Review feedback (greptile, CodeRabbit): apply_before_packing loaded each pnpmfile via finder::load_pnpmfile_at on every api() call, so a recursive pack (pnpm pack -r / publish -r) in a workspace with a .pnpmfile.cjs re-spawned that pnpmfile's Node worker once per packed project. PackOptions now carries the loaded hooks (Vec<Arc<dyn PnpmfileHooks>>) instead of paths. The CLI loads them once — the recursive path before the per-project loop, like catalogs — and clones the Arcs into each project, so the worker (a lazily-spawned OnceCell inside NodeJsHooks) is spawned once and reused. apply_before_packing derives the pnpmfile path for logging and error context from PnpmfileHooks::source_path. Also reword the napi block_on comment to say the blocking tarball write does not tie up an async worker thread, and add a recursive-pack test asserting the workspace-root beforePacking hook runs for every project. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pnpm11/pnpm/bundle-deps.ts (1)
126-129: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the temporary nature and rationale of the manifest stripping.
The manifest field removal has no comment explaining why it's needed or that it's a temporary workaround. Per the REVIEW_GUIDE, the fix should live at the pack/publish flow layer (the
beforePackinghook), not in an ad-hoc call site. A brief comment would help future maintainers understand when this can be removed (i.e., when the TypeScript pnpm CLI gainsbeforePackinghook support).As per path instructions, REVIEW_GUIDE.md states: "this PR must solve the tarball/install regression by removing bundled
dependencies/devDependenciesfrom published manifests at the correct layer (pack/publish flow), not via ad-hoc call sites."💬 Suggested comment
createDistNodeModules() +// Temporary workaround: strip bundled dependencies/devDependencies from the +// published manifest so `npm install --omit=dev --omit=optional` succeeds on +// the extracted tarball. This should eventually be replaced by beforePacking +// hook support in the TypeScript pack/publish flow. const manifest = JSON.parse(fs.readFileSync(MANIFEST_PATH, 'utf8')) delete manifest.dependencies delete manifest.devDependencies fs.writeFileSync(MANIFEST_PATH, `${JSON.stringify(manifest, undefined, 2)}\n`)🤖 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/pnpm/bundle-deps.ts` around lines 126 - 129, Move the manifest dependency stripping from this ad-hoc call site into the pack/publish flow’s beforePacking hook, using the hook implementation as the change point. Add a brief comment documenting that removing dependencies and devDependencies is a temporary workaround for the tarball/install regression and can be removed once the TypeScript pnpm CLI supports beforePacking.Source: Path instructions
pnpm/crates/cli/tests/pack.rs (1)
120-171: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a regression test for the
beforePackinghook failure path.The three integration tests cover happy paths (hook rewrites manifest), but none exercise
PackError::BeforePackingwhen a hook throws. A.pnpmfile.cjsthat throws inbeforePackingshould fail the CLI with the pnpmfile path attributed; asserting that covers the error-mapping branch currently flagged as uncovered inpnpm/crates/pack/src/lib.rs.🧪 Suggested hook-failure test
+/// A `beforePacking` hook that throws surfaces a pack failure attributing +/// the offending pnpmfile. +#[test] +fn before_packing_hook_failure_fails_the_pack() { + let CommandTempCwd { pacquet, root, workspace, .. } = CommandTempCwd::init(); + fs::write( + workspace.join("package.json"), + json!({ "name": "pkg", "version": "1.0.0" }).to_string(), + ) + .expect("write package.json"); + fs::write( + workspace.join(".pnpmfile.cjs"), + r"module.exports = { + hooks: { + beforePacking () { + throw new Error('hook boom') + }, + }, +} +", + ) + .expect("write .pnpmfile.cjs"); + let out = workspace.join("tarballs"); + fs::create_dir_all(&out).expect("create out dir"); + + pacquet + .with_arg("pack") + .with_arg("--pack-destination") + .with_arg(out.to_str().expect("utf8 out dir")) + .assert() + .failure() + .stderr(predicates::str::contains("hook boom")); + + drop(root); +}🤖 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 `@pnpm/crates/cli/tests/pack.rs` around lines 120 - 171, Add a regression test alongside recursive_pack_applies_before_packing_hook_to_every_project that writes a .pnpmfile.cjs whose beforePacking hook throws, runs the pack CLI, and asserts failure with PackError::BeforePacking behavior, including attribution of the error to the pnpmfile path. Cover the CLI error output or structured failure details without changing the existing happy-path tests.
🤖 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.
Nitpick comments:
In `@pnpm/crates/cli/tests/pack.rs`:
- Around line 120-171: Add a regression test alongside
recursive_pack_applies_before_packing_hook_to_every_project that writes a
.pnpmfile.cjs whose beforePacking hook throws, runs the pack CLI, and asserts
failure with PackError::BeforePacking behavior, including attribution of the
error to the pnpmfile path. Cover the CLI error output or structured failure
details without changing the existing happy-path tests.
In `@pnpm11/pnpm/bundle-deps.ts`:
- Around line 126-129: Move the manifest dependency stripping from this ad-hoc
call site into the pack/publish flow’s beforePacking hook, using the hook
implementation as the change point. Add a brief comment documenting that
removing dependencies and devDependencies is a temporary workaround for the
tarball/install regression and can be removed once the TypeScript pnpm CLI
supports beforePacking.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ca59e54a-2057-4896-bfc1-ab8d24940aae
📒 Files selected for processing (8)
pnpm/crates/cli/src/cli_args/pack.rspnpm/crates/cli/src/cli_args/publish.rspnpm/crates/cli/src/config_deps.rspnpm/crates/cli/tests/pack.rspnpm/crates/napi/src/pack.rspnpm/crates/pack/src/lib.rspnpm/crates/pack/src/tests.rspnpm11/pnpm/bundle-deps.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- pnpm/crates/cli/src/cli_args/publish.rs
- pnpm/crates/cli/src/config_deps.rs

Summary
The published
[email protected]brokenpm install --omit=dev --omit=optionalon its own tarball: the manifest declareddependenciesand a largedevDependencieslist of internal-only packages (e.g.@pnpm/[email protected]) that aren't on the public registry, so the install 404s.11.11.0published with neither field.Root cause: the
pnpmpackage bundles its runtime deps intodist/node_modules, so its manifest is meant to be dep-less — the workspace.pnpmfile.cjsbeforePackinghook stripsdependencies/devDependencieswhen packing. The11.12.0release ran a pnpm 12 alpha (pacquet) that does not yet honorbeforePacking, so the fields leaked into the published manifest.This fixes the pnpm 12 gap and adds a stopgap for it:
beforePackingpnpmfile hooks during pack/publish. Once the release runs a pnpm that includes this, the hook drops the fields as intended.bundle-deps.ts(the CLI'sprepublishOnly) stripsdependencies/devDependenciesfrom the on-disk manifest after building the bundle.packre-reads the manifest afterprepublishOnly, so the fields never reach the tarball. This on-disk strip can be removed once the release publishes with abeforePacking-aware pnpm.Closes #12955.
Squash Commit Body
Checklist
pnpm/port. (Rust:beforePackingbridge — the actual fix; TS:bundle-deps.tsstopgap until the release runs abeforePacking-aware pnpm.)"pnpm": patchfor the published-manifest dependency strip, and"pacquet": patchfor pacquet applying thebeforePackinghook (@pnpm/napibumps with pacquet via its fixed group).pnpm/crates/cli/tests/pack.rsend-to-endbeforePackingtests; updated pack/publish unit tests for the asyncpack::api.)Written by an agent (Claude Code, claude-opus-4-8[1m]).
Summary by CodeRabbit
pnpm packandpnpm publishnow applybeforePackinghooks to package manifests before creating archives, including workspace-level hooks.beforePackinghooks.dependencies/devDependenciesthat could cause installs to pull internal-only packages.beforePackinghook fails.