Skip to content

fix(package-manager): pick the projects that run their own lifecycle scripts pnpm's way - #13398

Merged
zkochan merged 3 commits into
mainfrom
fix-13358
Jul 26, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix-13358

Conversation

@zkochan

@zkochan zkochan commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #13358.

The issue asked which projects should run their own lifecycle scripts for a targeted update <pkg>, and reported that pnpm runs them and pacquet does not. Rather than read the TypeScript source, I ran it: 17 invocations across a 3-project workspace, a 2-project workspace, a root-only workspace and a plain project, each project stamping a file from postinstall, with the lockfile pinned below the manifest range so every update had real work to do.

The report turns out to be half right. pnpm does not run the scripts of the project you targeted — what the reporter saw was the workspace root, which pnpm's recursive dispatch pushes into the mutated importers as a plain mutation: 'install' whenever the selection leaves it out. The full rule pnpm follows, which reproduces all 17 observations:

A project runs its own preinstall/install/postinstall/prepare when the run's mutated-importer set — the projects the command was pointed at, plus the workspace root when it isn't among them — covers only part of the workspace; when that set covers the whole workspace, only the projects whose own mutation is a full install run them. remove runs none, anywhere.

The decision on this issue was to mirror the TypeScript CLI in every case, so this PR changes pacquet only; the TypeScript CLI is untouched and gets the same matrix as tests.

Measured behavior in a root + packages/a + packages/b workspace, before and after:

invocation pnpm (TS) pacquet before pacquet after
at root: update root root, a, b root
at root: update <pkg> root — root
at root: update --latest root root, a, b root
at root: add <pkg> root — root
at root: remove <pkg> — — —
at root: install root, a, b root, a, b root, a, b
in a: update root, a root, a, b root, a
in a: update <pkg> root, a — root, a
in a: update --latest root, a root, a, b root, a
in a: add <pkg> root, a — root, a
in a: install root, a, b root, a, b root, a, b
-r update root, a, b root, a, b root, a, b
-r update <pkg> — — —
--filter a update root, a a a ⚠️
--filter a update <pkg> root, a — a ⚠️
--filter a add <pkg> root, a — a ⚠️

In a 2-project workspace (root + one member), update <pkg> run in the member runs the root's scripts and not the member's in both stacks — the mutated set covers the whole workspace there, so the partial mutation is filtered out. That is the exact scenario the issue opened on.

⚠️ The three --filter rows still differ, by the workspace root only, and not because of lifecycle scripts: under --filter, pnpm installs the workspace root alongside the filtered projects and pacquet does not install it at all. Running the root's scripts without linking its dependencies would be worse than skipping them, so this PR leaves those rows alone and the materialization divergence is filed separately as #13397.

Squash Commit Body

pacquet decided which projects fire their own preinstall / install /
postinstall / prepare from one `is_full_install` flag: every project the
run materialized ran them for a selector-less `install` or `update`, and
no project ran them for `add` or a targeted `update <pkg>`.

pnpm decides per project, from the mutated-importer list its command
layer builds — the projects the command was pointed at, plus the
workspace root, which the recursive dispatch pushes in as a plain
`mutation: 'install'` whenever the selection leaves it out. A project
runs its scripts when that list covers only part of the workspace, or,
when it covers the whole workspace, when its own mutation is a full
install. The rule was read off the TypeScript CLI by running it, not off
its source: 17 invocations across four workspace shapes, each project
stamping a file from `postinstall`.

Replace the flag with `ProjectMutation`, which names pnpm's mutation kind
(`InstallWorkspace`, `InstallSelected`, `InstallSome`, `NoInstall`), and
select the projects from it. `ProjectMutation::is_full_install()` keeps
the old flag's other four uses — the scope log, the optimistic
repeat-install gate, the resolution-skipped message and the
`--no-optional` exclusion — unchanged.

What changes for users: `update <pkg>` and `add <pkg>` in a workspace
stop skipping the workspace root's scripts, `update` at a workspace root
stops running the other members' scripts, and `update --latest` stops
running the project's own scripts (it rewrites named dependency specs,
so pnpm makes it `installSome` like `update <pkg>`).

The TypeScript CLI is unchanged; it gets the same matrix as e2e tests so
the contract is pinned on both sides.

Closes pnpm/pnpm#13358.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    (The TypeScript CLI already behaves this way and is the reference here; it
    gains the matrix as tests. Only pacquet's behavior changes.)
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests. (9 pacquet integration tests, 8 TypeScript e2e
    tests, covering the same matrix in both stacks.)
  • Updated the documentation if needed.

Written by an agent (Claude Code, claude-opus-5).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Behavior Changes
    • Lifecycle scripts now run consistently for projects affected by full or partial workspace changes.
    • Workspace root scripts run when workspace commands modify another project.
    • Targeted updates plus package additions/removals trigger scripts only for affected projects.
    • pnpm update --latest no longer runs the project’s own lifecycle scripts.
    • Recursive updates now avoid running scripts for unrelated projects, while argumentless recursive updates run across the workspace.

…pm's way

pacquet decided which projects fire their own preinstall / install /
postinstall / prepare from one `is_full_install` flag: every project the
run materialized ran them for a selector-less `install` or `update`, and
no project ran them for `add` or a targeted `update <pkg>`.

pnpm decides per project, from the mutated-importer list its command
layer builds — the projects the command was pointed at, plus the
workspace root, which the recursive dispatch pushes in as a plain
`mutation: 'install'` whenever the selection leaves it out. A project
runs its scripts when that list covers only part of the workspace, or,
when it covers the whole workspace, when its own mutation is a full
install. The rule was read off the TypeScript CLI by running it, not off
its source: 17 invocations across a 3-project workspace, a 2-project
workspace, a root-only workspace and a plain project, each project
stamping a file from `postinstall`.

Replace the flag with `ProjectMutation`, which names pnpm's mutation
kind (`InstallWorkspace`, `InstallSelected`, `InstallSome`, `NoInstall`),
and select the projects from it. `ProjectMutation::is_full_install()`
keeps the old flag's other four uses — the scope log, the optimistic
repeat-install gate, the resolution-skipped message and the
`--no-optional` exclusion — unchanged.

What changes for users: `update <pkg>` and `add <pkg>` in a workspace
stop skipping the workspace root's scripts, `update` at a workspace root
stops running the other members' scripts, and `update --latest` stops
running the project's own scripts (it rewrites named dependency specs,
so pnpm makes it `installSome` like `update <pkg>`).

The TypeScript CLI is unchanged; it gets the same matrix as e2e tests so
the contract is pinned on both sides.

One divergence in the same area is left alone, because it is not about
lifecycle scripts: under `--filter`, pnpm installs the workspace root
alongside the filtered projects and pacquet does not install it at all,
so pacquet cannot run its scripts either. Filed separately.

Closes #13358.
Copilot AI review requested due to automatic review settings July 26, 2026 01:24

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 26, 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: e1234e30-cf66-477c-8a69-8ef3845911cc

📥 Commits

Reviewing files that changed from the base of the PR and between 5e60feb and 8ee589f.

📒 Files selected for processing (1)
  • pnpm11/pnpm/test/install/lifecycleScripts.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm11/pnpm/test/install/lifecycleScripts.ts

📝 Walkthrough

Walkthrough

The install pipeline now uses ProjectMutation instead of a full-install boolean. Command entry points classify mutations, and lifecycle scripts are selected from affected workspace projects. Rust and TypeScript tests cover update, add, remove, recursive, and latest-update scenarios.

Changes

Lifecycle mutation behavior

Layer / File(s) Summary
Mutation model and lifecycle selection
pnpm/crates/package-manager/src/install.rs, pnpm/crates/package-manager/src/install/tests.rs, pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs
Adds ProjectMutation, replaces Install.is_full_install, and computes lifecycle-script projects from mutation scope.
Command mutation wiring
pnpm/crates/package-manager/src/{add,remove,update}.rs, pnpm/crates/cli/src/cli_args/*, pnpm/crates/napi/src/install.rs, pnpr/crates/pnpr/src/resolver/resolve.rs
Passes explicit mutation modes through install-family commands and package-manager entry points.
Workspace lifecycle coverage
pnpm/crates/cli/tests/lifecycle_scripts.rs, pnpm11/pnpm/test/install/lifecycleScripts.ts, .changeset/project-lifecycle-scripts-follow-the-mutated-projects.md
Adds stamp-based workspace tests and documents lifecycle behavior for targeted, bare, recursive, add, remove, and --latest operations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Update
  participant Install
  participant WorkspaceProjects
  User->>Update: run update command
  Update->>Install: pass ProjectMutation
  Install->>WorkspaceProjects: determine mutated projects
  Install->>WorkspaceProjects: run selected lifecycle scripts
Loading

Assessment against linked issues

Objective Addressed Explanation
Targeted workspace updates run the project’s own lifecycle scripts consistently with pnpm [#13358] ✅

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13030 — Both modify filtered workspace install interpretation and lifecycle-script selection.
  • pnpm/pnpm#13153 — Both update lifecycle-script handling in pnpm/crates/package-manager/src/install.rs.
  • pnpm/pnpm#13176 — Both extend workspace lifecycle-script test coverage.

Suggested labels: product: pacquet, product: pnpr

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13358

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.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Align lifecycle-script execution with pnpm mutated-importer rules

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Replace full-install boolean with per-command mutation semantics (pnpm-compatible).
• Run project lifecycle scripts only for pnpm-equivalent mutated projects in workspaces.
• Add regression tests covering update/add/remove/workspace-root/recursive cases.
Diagram

graph TD
  A["CLI commands (install/update/add/remove/etc)"] --> B["Install options"] --> C["ProjectMutation"] --> D["Install::run"] --> E{"Select projects\nfor lifecycle scripts"} --> F["projects_running_own_scripts"] --> G["Run lifecycle scripts"]

  subgraph Legend
    direction LR
    _mod["Module/step"] ~~~ _dec{"Decision"}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Extend the existing is_full_install boolean with extra flags
  • ➕ Smaller surface change in function signatures and option structs
  • ➕ Less mechanical churn across call sites
  • ➖ Hard to represent pnpm's nuanced workspace-root 'push-in' behavior and workspace-coverage gating cleanly
  • ➖ Tends to accumulate boolean combinations that are difficult to reason about and test
2. Compute an explicit mutated-importer set in the CLI layer and pass it through
  • ➕ Matches pnpm’s conceptual model more directly (a list of mutated importers)
  • ➕ Could support future parity work where mutation differs per importer
  • ➖ More plumbing and data-structure overhead throughout the stack
  • ➖ Still requires careful rules to reconcile “materialized” vs “mutated” projects
3. Always run scripts only for the active project (never workspace root push-in)
  • ➕ Simple and predictable from a pacquet-centric perspective
  • ➕ Reduces surprising script runs in large workspaces
  • ➖ Would intentionally diverge from pnpm behavior and fail parity expectations for pnpm CLI users
  • ➖ Does not resolve the reported mismatch motivating this PR

Recommendation: Keep the PR’s approach: introducing ProjectMutation and centralizing the selection logic in projects_running_own_scripts makes the pnpm parity rule explicit, testable, and reusable across commands. The alternatives either reintroduce boolean-combinator complexity or require heavier plumbing without clear near-term benefit.

Files changed (19) +679 / -166

Bug fix (14) +197 / -74
dedupe.rsMark dedupe as a workspace full install via ProjectMutation +2/-2

Mark dedupe as a workspace full install via ProjectMutation

• Updates Install options wiring to use ProjectMutation::InstallWorkspace instead of a boolean full-install flag, preserving prior behavior while aligning with the new API.

pnpm/crates/cli/src/cli_args/dedupe.rs

deploy.rsMark deploy as a workspace full install via ProjectMutation +2/-2

Mark deploy as a workspace full install via ProjectMutation

• Switches deploy’s Install configuration from is_full_install to mutation=InstallWorkspace to match the updated installer contract.

pnpm/crates/cli/src/cli_args/deploy.rs

fetch.rsMark fetch as non-installing for lifecycle purposes +2/-2

Mark fetch as non-installing for lifecycle purposes

• Updates fetch to pass ProjectMutation::NoInstall, reflecting that it materializes without installing manifests and should not trigger project lifecycle scripts.

pnpm/crates/cli/src/cli_args/fetch.rs

import.rsMark import as non-installing for lifecycle purposes +2/-2

Mark import as non-installing for lifecycle purposes

• Updates import to pass ProjectMutation::NoInstall so the installer does not treat it as a full install for lifecycle gating.

pnpm/crates/cli/src/cli_args/import.rs

install.rsInstall CLI uses ProjectMutation instead of is_full_install +7/-9

Install CLI uses ProjectMutation instead of is_full_install

• Replaces the hard-coded full-install boolean with ProjectMutation::InstallWorkspace for install flows, including pnpr-based inner install paths.

pnpm/crates/cli/src/cli_args/install.rs

link.rsMark link as NoInstall mutation +2/-2

Mark link as NoInstall mutation

• Updates link to pass ProjectMutation::NoInstall to avoid treating link operations as manifest installs for lifecycle-script execution.

pnpm/crates/cli/src/cli_args/link.rs

prune.rsMark prune as a workspace full install via ProjectMutation +2/-2

Mark prune as a workspace full install via ProjectMutation

• Switches prune’s Install configuration to mutation=InstallWorkspace, matching prior full-install semantics under the new API.

pnpm/crates/cli/src/cli_args/prune.rs

rebuild.rsMark rebuild as NoInstall mutation +2/-2

Mark rebuild as NoInstall mutation

• Updates rebuild’s Install configuration to use ProjectMutation::NoInstall; rebuild remains a dependency-build operation rather than a manifest install.

pnpm/crates/cli/src/cli_args/rebuild.rs

install.rsN-API engine install wiring uses ProjectMutation +9/-3

N-API engine install wiring uses ProjectMutation

• Replaces the engine’s is_full_install logic with ProjectMutation, treating EngineMode::Install as InstallWorkspace and other modes as NoInstall for lifecycle gating.

pnpm/crates/napi/src/install.rs

add.rsAdd uses InstallSome mutation to reflect partial manifest rewrite +3/-6

Add uses InstallSome mutation to reflect partial manifest rewrite

• Updates add to set mutation=InstallSome, aligning lifecycle-script behavior with pnpm’s installSome semantics in both workspace and non-workspace paths.

pnpm/crates/package-manager/src/add.rs

install.rsIntroduce ProjectMutation and pnpm-like script selection +139/-27

Introduce ProjectMutation and pnpm-like script selection

• Adds the ProjectMutation enum and migrates Install to carry mutation instead of is_full_install. Implements projects_running_own_scripts to select lifecycle-script projects based on pnpm’s mutated-importer coverage rules, including implicit workspace-root inclusion and materialization constraints.

pnpm/crates/package-manager/src/install.rs

remove.rsRemove uses NoInstall mutation (uninstallSome) +3/-3

Remove uses NoInstall mutation (uninstallSome)

• Updates remove to pass mutation=NoInstall, reflecting pnpm’s uninstallSome behavior and ensuring no project lifecycle scripts are run for removals.

pnpm/crates/package-manager/src/remove.rs

update.rsUpdate computes mutation from selectors/--latest +20/-10

Update computes mutation from selectors/--latest

• Adds update_mutation() to map selector-less update to InstallSelected and targeted/--latest updates to InstallSome. Wires the computed mutation into Install options so lifecycle scripts mirror pnpm behavior.

pnpm/crates/package-manager/src/update.rs

resolve.rspnpr resolver uses ProjectMutation::InstallWorkspace +2/-2

pnpr resolver uses ProjectMutation::InstallWorkspace

• Updates pnpr resolver’s Install configuration to pass mutation=InstallWorkspace, maintaining full-install behavior under the new Install struct field.

pnpr/crates/pnpr/src/resolver/resolve.rs

Tests (3) +476 / -91
lifecycle_scripts.rsAdd workspace matrix tests for lifecycle script execution +249/-0

Add workspace matrix tests for lifecycle script execution

• Adds new tests asserting which workspace projects run postinstall across targeted update, bare update, root update, recursive update, add, and remove, including the special case where the workspace root is implicitly installed.

pnpm/crates/cli/tests/lifecycle_scripts.rs

tests.rsUpdate installer tests to use ProjectMutation +94/-90

Update installer tests to use ProjectMutation

• Mechanically migrates many Install invocations from is_full_install to mutation=InstallWorkspace (or InstallSome where appropriate), preserving existing test semantics under the new API.

pnpm/crates/package-manager/src/install/tests.rs

lifecycleScripts.tsAdd pnpm TypeScript CLI tests for mutated-importer lifecycle rules +133/-1

Add pnpm TypeScript CLI tests for mutated-importer lifecycle rules

• Extends pnpm’s TS test suite with new cases validating postinstall behavior for targeted update, argumentless update, update --latest, and several workspace scenarios (single member, larger workspace, and recursive updates).

pnpm11/pnpm/test/install/lifecycleScripts.ts

Documentation (2) +6 / -1
project-lifecycle-scripts-follow-the-mutated-projects.mdDocument pnpm-aligned lifecycle script behavior in pacquet +5/-0

Document pnpm-aligned lifecycle script behavior in pacquet

• Adds a changeset describing the new rules for which projects run lifecycle scripts across install-family commands, including workspace-root behavior and update --latest semantics.

.changeset/project-lifecycle-scripts-follow-the-mutated-projects.md

install_with_fresh_lockfile.rsUpdate docs to reference ProjectMutation::is_full_install +1/-1

Update docs to reference ProjectMutation::is_full_install

• Adjusts internal documentation to point to ProjectMutation::is_full_install as the canonical full-install gate for behaviors like optional dependency exclusion.

pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs

@zkochan

zkochan commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

(The automatic review was skipped due to the rate limit.)


Written by an agent (Claude Code, claude-opus-5).

@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

@zkochan: I’ll review the changes in #13398.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@greptile-apps

greptile-apps Bot commented Jul 26, 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: "test(pnpm): cover the workspace-member m..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.05     11.7±0.06ms    32.0 MB/sec    1.00     11.1±0.09ms    33.7 MB/sec
packument/parse                1.00     36.0±0.04µs  1843.4 MB/sec    1.03     36.9±0.11µs  1797.2 MB/sec
tarball/download_dependency    1.00      2.1±0.06ms  2025.0 KB/sec    1.06      2.3±0.05ms  1902.0 KB/sec

@qodo-code-review

qodo-code-review Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 32 rules

Grey Divider


Remediation recommended

1. TS helpers declared before use ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
New top-level function declarations (projectManifest, prepareInstalledWorkspace, etc.) are
declared before any call site in the same file. This violates the requirement that TypeScript
function declarations appear only after their first usage.
Code

pnpm11/pnpm/test/install/lifecycleScripts.ts[R480-515]

+function projectManifest (name: string): ProjectManifest {
+  return {
+    name,
+    version: '1.0.0',
+    dependencies: { [DEP]: '^100.0.0' },
+    scripts: {
+      postinstall: 'node -e "require(\'fs\').writeFileSync(\'ran-postinstall.txt\',\'\')"',
+    },
+  }
+}
+
+/** A workspace whose root and `packages/*` members all stamp a file from `postinstall`, installed once with the stamps then cleared. */
+function prepareInstalledWorkspace (members: string[]): void {
+  preparePackages(members.map((name) => ({
+    location: `packages/${name}`,
+    package: projectManifest(name),
+  })))
+  fs.writeFileSync('package.json', JSON.stringify(projectManifest('root')))
+  writeYamlFileSync('pnpm-workspace.yaml', { packages: ['packages/*'] })
+
+  execPnpmSync(['install'], { expectSuccess: true })
+  clearPostinstallStamps(members)
+}
+
+function clearPostinstallStamps (members: string[]): void {
+  for (const dir of ['.', ...members.map((name) => path.join('packages', name))]) {
+    fs.rmSync(path.join(dir, 'ran-postinstall.txt'), { force: true })
+  }
+}
+
+function projectsThatRanPostinstall (members: string[]): string[] {
+  return ['root', ...members].filter((project) => {
+    const dir = project === 'root' ? '.' : path.join('packages', project)
+    return fs.existsSync(path.join(dir, 'ran-postinstall.txt'))
+  })
+}
Relevance

⭐⭐⭐ High

This repo enforces the TS “declare functions only after first use” ordering rule and has accepted
fixes.

PR-#12964
PR-#13133
PR-#12954

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The file defines function projectManifest, function prepareInstalledWorkspace, `function
clearPostinstallStamps, and function projectsThatRanPostinstall` and only later calls them from
tests (e.g., prepareInstalledWorkspace(['a'])). This is exactly the disallowed ordering described
by the checklist.

Rule 713432: Declare TypeScript functions only after their first usage
pnpm11/pnpm/test/install/lifecycleScripts.ts[480-568]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Top-level function declarations are placed before their first usage in the file.

## Issue Context
The policy requires that TypeScript `function foo(...) {}` declarations appear only after at least one usage in the same file. The new helper functions are declared before the tests that call them.

## Fix Focus Areas
- pnpm11/pnpm/test/install/lifecycleScripts.ts[480-515]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Repeated path normalization 🐞 Bug ➹ Performance
Description
projects_running_own_scripts() repeatedly lexical_normalize()s paths and scans all workspace
projects to compute covers_workspace, adding avoidable allocations/work to add/update runs in
large workspaces. This is on an install-family hot path and scales with workspace size even when the
mutated set is obviously smaller.
Code

pnpm/crates/package-manager/src/install.rs[R4096-4126]

+    let mutated_dirs = match selected_dirs {
+        Some(selected_dirs) => {
+            selected_dirs.iter().map(|dir| pacquet_fs::lexical_normalize(dir)).collect()
+        }
+        None => HashSet::from([pacquet_fs::lexical_normalize(active_project_dir)]),
+    };
+    // pnpm's recursive dispatch pushes the workspace root into the
+    // mutated importers as a plain `mutation: 'install'` whenever the
+    // selection leaves it out, so the root installs in full — and runs
+    // its own scripts — even when the command was pointed elsewhere.
+    let workspace_root = pacquet_fs::lexical_normalize(workspace_root);
+    let root_was_pushed_in = !mutated_dirs.contains(&workspace_root);
+    let is_pushed_root = |project_dir: &Path| root_was_pushed_in && project_dir == workspace_root;
+    // A run that mutates only part of the workspace materializes the rest
+    // from the lockfile alone; pnpm runs the scripts of everything it did
+    // mutate, whatever the mutation. Only when the mutated set covers the
+    // whole workspace does the `mutation === 'install'` filter decide.
+    let covers_workspace = project_manifests.iter().all(|(project_dir, _)| {
+        let project_dir = pacquet_fs::lexical_normalize(project_dir);
+        mutated_dirs.contains(&project_dir) || is_pushed_root(&project_dir)
+    });
+    materialized_project_manifests
+        .iter()
+        .filter(|(project_dir, _)| {
+            let project_dir = pacquet_fs::lexical_normalize(project_dir);
+            let pushed_root = is_pushed_root(&project_dir);
+            if !pushed_root && !mutated_dirs.contains(&project_dir) {
+                return false;
+            }
+            !covers_workspace || full_install || pushed_root
+        })
Relevance

⭐⭐ Medium

Repo sometimes accepts redundant-work optimizations, but also rejects similar micro-optimizations as
not worth complexity.

PR-#13170
PR-#13173

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The helper currently constructs a normalized mutated_dirs set, then normalizes every workspace
project dir again for covers_workspace, and normalizes every materialized project dir again during
filtering—each step allocates new PathBufs and repeats component-walking.

pnpm/crates/package-manager/src/install.rs[4096-4129]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`projects_running_own_scripts()` normalizes the same paths multiple times and does a full `project_manifests.iter().all(...)` scan to compute `covers_workspace`.

### Issue Context
This helper runs at the end of install-family commands (notably `add` / `update` / targeted updates). In large workspaces, extra per-project allocations/normalization adds measurable overhead.

### Fix Focus Areas
- pnpm/crates/package-manager/src/install.rs[4096-4129]

### Suggested fix
- Normalize each path at most once:
 - Precompute a normalized `HashSet<PathBuf>` for `mutated_dirs`.
 - Avoid normalizing `project_dir` multiple times inside `covers_workspace` and the final `.filter(...)`.
- Add a cheap short-circuit for `covers_workspace` when possible (e.g., if `mutated_dirs.len() + pushed_root_count < project_manifests.len()` then `covers_workspace` is definitely false), so the “partial workspace” path avoids a full scan.
- Keep behavior identical; this is purely reducing repeated work.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Alias breaks root detection 🐞 Bug ⛨ Security
Description
Root push-in detection relies on lexical_normalize() equality, but nearby code documents that
lexical path mismatches (e.g. symlink/realpath aliases) require canonical fallback to reliably
identify the same directory. If the workspace root path and selected project dirs differ only by
such an alias, root_was_pushed_in/is_pushed_root can be computed incorrectly and include the
root in the “pushed root runs scripts” exception when it shouldn’t, changing which lifecycle scripts
execute.
Code

pnpm/crates/package-manager/src/install.rs[R4106-4108]

+    let workspace_root = pacquet_fs::lexical_normalize(workspace_root);
+    let root_was_pushed_in = !mutated_dirs.contains(&workspace_root);
+    let is_pushed_root = |project_dir: &Path| root_was_pushed_in && project_dir == workspace_root;
Relevance

⭐ Low

Very similar “use realpath/normalize to avoid alias mismatches” security finding was rejected
previously.

PR-#13173

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
projects_running_own_scripts uses lexical equality to decide root_was_pushed_in and to identify
the pushed root, while ProjectDirMatcher in the same file documents/handles the exact class of
lexical mismatches that can occur in practice. Additionally, workspace root discovery explicitly
notes it does not realpath the start dir, increasing the likelihood of alias forms entering the
pipeline.

pnpm/crates/package-manager/src/install.rs[4106-4126]
pnpm/crates/package-manager/src/install.rs[4030-4058]
pnpm/crates/workspace/src/root_finder.rs[4-8]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`projects_running_own_scripts()` decides whether the workspace root was “pushed in” via a `HashSet` membership test and then checks `project_dir == workspace_root` after `lexical_normalize()`. This is not robust to symlink/realpath aliases, which can make the same directory compare unequal.

### Issue Context
In this PR, lifecycle-script execution is controlled by `root_was_pushed_in`/`pushed_root`. A false positive here can cause the workspace root’s scripts to run under the `pushed_root` exception in cases where pnpm would treat the root as already-selected (not pushed).

The same file already has `ProjectDirMatcher` that explicitly falls back to `std::fs::canonicalize` to handle lexical mismatches (e.g. `/tmp` vs `/private/tmp`).

### Fix Focus Areas
- pnpm/crates/package-manager/src/install.rs[4030-4058]
- pnpm/crates/package-manager/src/install.rs[4106-4126]

### Suggested fix
- Make the “is workspace root selected?” check robust:
 - Keep the fast path: if normalized paths match, treat as equal.
 - Otherwise, fall back to canonical comparison (like `ProjectDirMatcher`) at least for the workspace root membership decision.
   - Example approach: compute `workspace_root_canon = canonicalize(workspace_root_norm).ok()` once; when `mutated_dirs` doesn’t contain `workspace_root_norm`, scan `mutated_dirs` and compare `canonicalize(dir)` to `workspace_root_canon` until a match.
- Similarly, make `is_pushed_root` use the same equivalence (lexical-or-canonical) so root identification is stable.
- Keep filesystem touches minimal (canonicalize workspace root once; only canonicalize other dirs when the lexical check fails).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only declares a bump for pacquet, but this PR also changes the published pnpm
TypeScript package (tests under pnpm11/pnpm/). This violates the requirement to include pnpm in
changesets for TS package changes and to explicitly declare the pnpm bump type.
Code

.changeset/project-lifecycle-scripts-follow-the-mutated-projects.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

⭐ Low

Similar “add pnpm entry to changeset” suggestions were repeatedly rejected in recent PRs.

PR-#13391
PR-#13377
PR-#13285

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changeset front-matter lists only pacquet (no pnpm entry), while the PR also modifies the
pnpm package source tree under pnpm11/pnpm/, which the checklist requires to be covered by
changesets that include pnpm with a valid bump type.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
Rule 713441: Require changeset for TypeScript package changes
.changeset/project-lifecycle-scripts-follow-the-mutated-projects.md[1-3]
pnpm11/pnpm/test/install/lifecycleScripts.ts[470-600]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new changeset was added, but it does not declare a version bump for the `pnpm` package even though this PR changes the published `pnpm` TypeScript package.

## Issue Context
The PR modifies `pnpm11/pnpm/test/install/lifecycleScripts.ts`, which is part of the published `pnpm` package. Per policy, affected published TS packages must be included in a changeset, and the changeset must explicitly declare the `pnpm` bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/project-lifecycle-scripts-follow-the-mutated-projects.md[1-3]
- pnpm11/pnpm/test/install/lifecycleScripts.ts[470-600]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@codecov-commenter

codecov-commenter commented Jul 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.32%. Comparing base (7a77822) to head (8ee589f).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
pnpm/crates/napi/src/install.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13398      +/-   ##
==========================================
+ Coverage   87.25%   87.32%   +0.06%     
==========================================
  Files         540      542       +2     
  Lines       92662    93242     +580     
==========================================
+ Hits        80855    81422     +567     
- Misses      11807    11820      +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… use

The repo's TypeScript style relies on hoisting and declares functions
below their call sites; the new helpers in the lifecycle-scripts e2e
suite were sitting above the tests that use them.
Copilot AI review requested due to automatic review settings July 26, 2026 01:32

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

Thanks — went through the four findings. One was real and is fixed; the other three I'm declining, with reasons.

1. TS helpers declared before use — fixed in 46ddbb9. prepareInstalledWorkspace, projectsThatRanPostinstall, projectManifest and clearPostinstallStamps now sit below the tests that call them, each after its own first use. (const DEP stays above the tests — it is not hoisted.)

2. Repeated path normalization — declining. projects_running_own_scripts runs once per install, not per package, and lexical_normalize is a pure path/string operation with no syscalls. For a workspace of N projects it is ~2N normalizations, which is noise next to resolving and linking the dependency graph. The micro-benchmarks on this PR show no movement outside variance. Restructuring to normalize once would trade this for an extra allocated set without a measurable win, so it does not clear the bar of "the hot path affected" in REVIEW_GUIDE.md.

3. Changeset missing a pnpm entry — declining. The implementation is Rust-only; the only TypeScript file the PR touches is pnpm11/pnpm/test/install/lifecycleScripts.ts, which is a test and is not part of the published pnpm artifact. Per the changeset rules for the Rust products, a change whose implementation is Rust-only targets pacquet and must not name pnpm — adding it would cut a pnpm release for a change that alters nothing users install. Test-only commits landing without a changeset is the existing practice here (e.g. 0e18137).

4. Alias breaks root detection — declining, and it is empirically refuted. macOS is exactly the platform where this class of bug shows up: its temp dirs live under /var/folders/..., which is a symlink to /private/var/folders/.... The new workspace tests all depend on the root push-in decision, and Rust CI / Test / macos is green on this commit — so no aliasing mismatch reaches this code in practice.

That is not an accident. Every path the function compares comes out of the same discovery pipeline: workspace_root is derived by walking up from the active manifest's own directory, the --filter selection is discovered from that same root, and build_project_manifests_list already runs the active manifest through ProjectDirMatcher and stores the active form in the list. Adding a canonicalize fallback would put a syscall per project on the install path to defend against a mismatch the pipeline cannot produce. Qodo also rates this one Low and notes that the sibling finding was rejected on #13173.


Written by an agent (Claude Code, claude-opus-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 46ddbb9

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@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.

🧹 Nitpick comments (1)
pnpm11/pnpm/test/install/lifecycleScripts.ts (1)

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

Add TS lifecycle-script coverage for workspace member mutations.

The TS suite still lacks a counterpart to the Rust workspace-root-vs-member tests: argumentless update run from packages/a, plus equivalent add and remove workspace-member script behavior (add should run the member and root; remove should run no project scripts). Add these cases under the existing workspace lifecycle test section so pnpm and pacquet lifecycle semantics stay covered in both stacks.

🤖 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/test/install/lifecycleScripts.ts` around lines 562 - 600, Add
TypeScript lifecycle tests alongside the existing workspace update cases in the
relevant test section: cover argumentless update executed with cwd set to
packages/a, and add equivalent workspace-member cases for add and remove. Assert
that add runs the mutated member and workspace root scripts, while remove runs
no project scripts, using the existing prepareInstalledWorkspace, execPnpmSync,
and projectsThatRanPostinstall helpers.

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.

Nitpick comments:
In `@pnpm11/pnpm/test/install/lifecycleScripts.ts`:
- Around line 562-600: Add TypeScript lifecycle tests alongside the existing
workspace update cases in the relevant test section: cover argumentless update
executed with cwd set to packages/a, and add equivalent workspace-member cases
for add and remove. Assert that add runs the mutated member and workspace root
scripts, while remove runs no project scripts, using the existing
prepareInstalledWorkspace, execPnpmSync, and projectsThatRanPostinstall helpers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0f1a8fcd-f5d9-4fbe-9322-daa03924b7f9

📥 Commits

Reviewing files that changed from the base of the PR and between f892e3d and 5e60feb.

📒 Files selected for processing (19)
  • .changeset/project-lifecycle-scripts-follow-the-mutated-projects.md
  • pnpm/crates/cli/src/cli_args/dedupe.rs
  • pnpm/crates/cli/src/cli_args/deploy.rs
  • pnpm/crates/cli/src/cli_args/fetch.rs
  • pnpm/crates/cli/src/cli_args/import.rs
  • pnpm/crates/cli/src/cli_args/install.rs
  • pnpm/crates/cli/src/cli_args/link.rs
  • pnpm/crates/cli/src/cli_args/prune.rs
  • pnpm/crates/cli/src/cli_args/rebuild.rs
  • pnpm/crates/cli/tests/lifecycle_scripts.rs
  • pnpm/crates/napi/src/install.rs
  • pnpm/crates/package-manager/src/add.rs
  • pnpm/crates/package-manager/src/install.rs
  • pnpm/crates/package-manager/src/install/tests.rs
  • pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs
  • pnpm/crates/package-manager/src/remove.rs
  • pnpm/crates/package-manager/src/update.rs
  • pnpm11/pnpm/test/install/lifecycleScripts.ts
  • pnpr/crates/pnpr/src/resolver/resolve.rs

…ite too

The Rust suite pinned the member-side cases — an argumentless update, an
add, and a remove run inside a workspace member — while the TypeScript
suite only covered the ones driven from the workspace root. Both stacks
now assert the same matrix.
Copilot AI review requested due to automatic review settings July 26, 2026 01:39
@zkochan

zkochan commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

Good catch on the missing TypeScript cases — the Rust suite pinned the member-side mutations and the TypeScript one only covered the root-side ones, which is exactly the asymmetry the two-stack rule exists to prevent. Added in 8ee589f:

  • an argumentless update run inside packages/a → root and a run their scripts
  • add inside packages/a → root and a
  • remove inside packages/a → no project runs any

All three assert the behavior I measured from the TypeScript CLI before writing the fix, and they match the corresponding pacquet tests one for one. test/install/lifecycleScripts.ts is 36/36 green locally.


Written by an agent (Claude Code, claude-opus-5).

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 8ee589f

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 8ee589f4e8b8

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.522 ± 0.121 2.392 2.722 1.66 ± 0.19
pacquet@main 2.477 ± 0.106 2.341 2.619 1.63 ± 0.19
pnpr@HEAD 1.516 ± 0.161 1.350 1.794 1.00
pnpr@main 1.560 ± 0.134 1.373 1.771 1.03 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.52179448324,
      "stddev": 0.12106186450266923,
      "median": 2.47231985284,
      "user": 1.50871442,
      "system": 1.26030374,
      "min": 2.39193085484,
      "max": 2.7219641358400004,
      "times": [
        2.39193085484,
        2.5110391838400004,
        2.7219641358400004,
        2.63746679784,
        2.6500995238400002,
        2.4207364618400002,
        2.41595625184,
        2.4287353828400002,
        2.60641571784,
        2.4336005218400003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.47652597774,
      "stddev": 0.10596126486024735,
      "median": 2.44765682284,
      "user": 1.51261822,
      "system": 1.2621773399999998,
      "min": 2.3408104948400004,
      "max": 2.6192484048400004,
      "times": [
        2.54694899884,
        2.61343781484,
        2.4255736688400003,
        2.6192484048400004,
        2.38832357184,
        2.58643147784,
        2.39631080284,
        2.3408104948400004,
        2.37843456584,
        2.46973997684
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5156632912399999,
      "stddev": 0.16099976084817247,
      "median": 1.4643575653399998,
      "user": 1.04113712,
      "system": 1.10412184,
      "min": 1.34967262484,
      "max": 1.79426415684,
      "times": [
        1.79426415684,
        1.35122855884,
        1.45176225384,
        1.43202773484,
        1.61478253684,
        1.35021764884,
        1.47695287684,
        1.71773960584,
        1.6179849148399998,
        1.34967262484
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.55981287974,
      "stddev": 0.13396286111064856,
      "median": 1.5428949313399998,
      "user": 1.05207352,
      "system": 1.0849951399999997,
      "min": 1.3726588498399999,
      "max": 1.7708723948399998,
      "times": [
        1.47776416184,
        1.65094566184,
        1.7058211968399999,
        1.7708723948399998,
        1.5469984268399999,
        1.65385299884,
        1.50156166784,
        1.3788620028399998,
        1.5387914358399999,
        1.3726588498399999
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 250.5 ± 8.5 236.9 267.8 1.00
pacquet@main 251.1 ± 6.2 242.5 264.5 1.00 ± 0.04
pnpr@HEAD 274.4 ± 7.5 264.7 285.5 1.10 ± 0.05
pnpr@main 266.6 ± 5.6 259.0 276.7 1.06 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.25052603264,
      "stddev": 0.00845286892253747,
      "median": 0.25010881954,
      "user": 0.20372523999999997,
      "system": 0.52669928,
      "min": 0.23687362104,
      "max": 0.26776634404,
      "times": [
        0.23687362104,
        0.24934279404,
        0.24497295904000002,
        0.25197382204,
        0.24315369904,
        0.26776634404,
        0.24825897704000002,
        0.25761752304,
        0.25087484504,
        0.25442574204
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.25106876104000003,
      "stddev": 0.0062425906331238035,
      "median": 0.25190404554,
      "user": 0.21334694,
      "system": 0.50890498,
      "min": 0.24252927404000002,
      "max": 0.26446180104,
      "times": [
        0.25419693204,
        0.24369931404,
        0.25332529304,
        0.24252927404000002,
        0.24688871104000001,
        0.24883585204,
        0.25287423504,
        0.25093385604,
        0.26446180104,
        0.25294234204
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.27442592714,
      "stddev": 0.007497128669582505,
      "median": 0.27410104954000003,
      "user": 0.21809953999999995,
      "system": 0.53055638,
      "min": 0.26474739804,
      "max": 0.28549884404000003,
      "times": [
        0.26967950104,
        0.26725046404,
        0.28549884404000003,
        0.27416322104,
        0.27403887804,
        0.26689118904000003,
        0.27542469204000003,
        0.28269291804,
        0.26474739804,
        0.28387216604000004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.26661003684,
      "stddev": 0.005633704540482327,
      "median": 0.26525319854,
      "user": 0.21350843999999997,
      "system": 0.52844188,
      "min": 0.25902871604,
      "max": 0.27667554504,
      "times": [
        0.27266097704000003,
        0.27667554504,
        0.27133965304,
        0.26000115304,
        0.26834784704000003,
        0.25902871604,
        0.26294450804,
        0.26459557204,
        0.26524630604,
        0.26526009104000003
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.769 ± 0.020 2.725 2.796 1.75 ± 0.15
pacquet@main 2.765 ± 0.019 2.722 2.789 1.75 ± 0.15
pnpr@HEAD 1.627 ± 0.167 1.436 1.826 1.03 ± 0.14
pnpr@main 1.582 ± 0.139 1.429 1.808 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.7687076511399997,
      "stddev": 0.019565309660373235,
      "median": 2.7676338660399997,
      "user": 1.76507178,
      "system": 1.23775718,
      "min": 2.7250625295399997,
      "max": 2.79600662554,
      "times": [
        2.78318474054,
        2.76848792754,
        2.76677980454,
        2.78982420454,
        2.76265807854,
        2.7250625295399997,
        2.76438756054,
        2.75996140054,
        2.77072363954,
        2.79600662554
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.76469657614,
      "stddev": 0.01949054909359711,
      "median": 2.7647898510399997,
      "user": 1.67533088,
      "system": 1.2923426800000002,
      "min": 2.72160072254,
      "max": 2.78925998454,
      "times": [
        2.78925998454,
        2.7602827845399998,
        2.77998030954,
        2.75173010754,
        2.78554619354,
        2.76420560754,
        2.72160072254,
        2.77162133754,
        2.76537409454,
        2.7573646195399997
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.6265927342400002,
      "stddev": 0.16698047757522827,
      "median": 1.66848413954,
      "user": 1.0217077799999998,
      "system": 1.13683518,
      "min": 1.4364349605400002,
      "max": 1.82610391054,
      "times": [
        1.45632874254,
        1.4364349605400002,
        1.76996865754,
        1.75251090254,
        1.43772739854,
        1.82610391054,
        1.44067270354,
        1.70369700754,
        1.80921178754,
        1.6332712715400002
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.58227484184,
      "stddev": 0.13872787192182828,
      "median": 1.5471807315400001,
      "user": 1.03975978,
      "system": 1.10981878,
      "min": 1.42922179654,
      "max": 1.8084502085400003,
      "times": [
        1.5635733145400001,
        1.48411631754,
        1.5307881485400001,
        1.4404591125400001,
        1.49603840054,
        1.78306816254,
        1.7164036845400001,
        1.8084502085400003,
        1.42922179654,
        1.5706292725400002
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 597.2 ± 12.2 571.8 610.7 2.01 ± 0.08
pacquet@main 578.9 ± 14.2 554.8 605.0 1.95 ± 0.08
pnpr@HEAD 301.9 ± 4.3 295.8 306.3 1.02 ± 0.04
pnpr@main 296.6 ± 9.6 286.0 320.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.59721191836,
      "stddev": 0.012196347869592413,
      "median": 0.59896629166,
      "user": 0.7211229,
      "system": 0.6729346799999999,
      "min": 0.5717513131599999,
      "max": 0.61068536316,
      "times": [
        0.60119905716,
        0.5717513131599999,
        0.60764336616,
        0.59140379116,
        0.59673352616,
        0.60622102516,
        0.61068536316,
        0.59613638516,
        0.60656716416,
        0.5837781921599999
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.57885893566,
      "stddev": 0.01419468981698491,
      "median": 0.57825267916,
      "user": 0.6958366999999999,
      "system": 0.67697008,
      "min": 0.55475049716,
      "max": 0.60499059216,
      "times": [
        0.58802303816,
        0.57939515616,
        0.59193983816,
        0.56458756216,
        0.57711020216,
        0.60499059216,
        0.57199675416,
        0.57352308216,
        0.55475049716,
        0.58227263416
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.30189972066,
      "stddev": 0.00430357989829006,
      "median": 0.30332702616000007,
      "user": 0.1871061,
      "system": 0.53403808,
      "min": 0.29576706616000004,
      "max": 0.30631900416,
      "times": [
        0.30434574616000004,
        0.29581494616000004,
        0.30210726916,
        0.30512329716000003,
        0.30230830616000004,
        0.29635857816,
        0.30584966216000004,
        0.30500333116,
        0.30631900416,
        0.29576706616000004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.29661006106000004,
      "stddev": 0.009623474252759678,
      "median": 0.29584924016,
      "user": 0.18715579999999996,
      "system": 0.51164188,
      "min": 0.28599912116000004,
      "max": 0.32002952716000005,
      "times": [
        0.29295234716,
        0.28926834416,
        0.32002952716000005,
        0.29630555716,
        0.29627017116000004,
        0.28876491916,
        0.29818530016,
        0.28599912116000004,
        0.29542830916,
        0.30289701416000003
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.900 ± 0.012 1.883 1.924 6.32 ± 0.16
pacquet@main 1.893 ± 0.014 1.872 1.918 6.30 ± 0.16
pnpr@HEAD 0.306 ± 0.009 0.299 0.329 1.02 ± 0.04
pnpr@main 0.301 ± 0.007 0.285 0.312 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.89978418208,
      "stddev": 0.012481940488737343,
      "median": 1.8973538485800001,
      "user": 0.94463864,
      "system": 0.7427184,
      "min": 1.8834786805800001,
      "max": 1.9241809035800002,
      "times": [
        1.91334954058,
        1.9241809035800002,
        1.89784561758,
        1.89587896058,
        1.8834786805800001,
        1.9070459855800002,
        1.8968620795800002,
        1.90238353458,
        1.88603759958,
        1.8907789185800001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.8930866585800004,
      "stddev": 0.013860887815290032,
      "median": 1.88995922158,
      "user": 0.93597284,
      "system": 0.736191,
      "min": 1.8721828305800001,
      "max": 1.9177988435800002,
      "times": [
        1.8797158095800002,
        1.8905423435800002,
        1.9177988435800002,
        1.90829004058,
        1.88835414758,
        1.90530578158,
        1.8721828305800001,
        1.8949404975800002,
        1.88937609958,
        1.8843601915800001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.30642740498,
      "stddev": 0.009106705443218649,
      "median": 0.30191702758,
      "user": 0.20615834,
      "system": 0.5274665,
      "min": 0.29928455458000003,
      "max": 0.32910120058000003,
      "times": [
        0.30230109458,
        0.30106540258000003,
        0.30771427958,
        0.30134643058,
        0.30693380258,
        0.30111293158,
        0.31388139258000003,
        0.29928455458000003,
        0.30153296058,
        0.32910120058000003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.30067315548,
      "stddev": 0.0071874767118806585,
      "median": 0.30037510908,
      "user": 0.20353643999999999,
      "system": 0.5247358999999999,
      "min": 0.28452798658,
      "max": 0.31226423258,
      "times": [
        0.30038809858,
        0.30507962658,
        0.30018056858000003,
        0.30335454458,
        0.30500898458000003,
        0.28452798658,
        0.29586144058,
        0.30036211958000003,
        0.31226423258,
        0.29970395258
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 364.1 ± 16.5 345.4 395.3 4.27 ± 0.22
pacquet@main 354.2 ± 6.8 346.4 366.1 4.15 ± 0.12
pnpr@HEAD 85.4 ± 1.9 82.3 88.1 1.00
pnpr@main 85.9 ± 2.1 81.1 89.7 1.01 ± 0.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.36409105666,
      "stddev": 0.016489685817161103,
      "median": 0.36134254476,
      "user": 0.35289209999999993,
      "system": 0.06051667999999999,
      "min": 0.34541988176,
      "max": 0.39534141776000004,
      "times": [
        0.39534141776000004,
        0.34897711776,
        0.34541988176,
        0.38398530176,
        0.35696547276,
        0.35943487376,
        0.36918972076,
        0.34593977776,
        0.36325021576,
        0.37240678676
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.35423660726000006,
      "stddev": 0.006809720535654438,
      "median": 0.35117917626,
      "user": 0.3514711,
      "system": 0.050469780000000006,
      "min": 0.34638418276,
      "max": 0.36610479176,
      "times": [
        0.35183794476,
        0.36610479176,
        0.35124460976,
        0.35009131176,
        0.35059214276,
        0.35111374276,
        0.35003763076,
        0.36069394076,
        0.36426577476,
        0.34638418276
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.08536589415393939,
      "stddev": 0.0019007853547955672,
      "median": 0.08578795176000001,
      "user": 0.020419984848484854,
      "system": 0.008162477575757575,
      "min": 0.08227464876,
      "max": 0.08809385676,
      "times": [
        0.08631669676,
        0.08578795176000001,
        0.08237135076,
        0.08560025976,
        0.08678673976,
        0.08656244876000001,
        0.08709531976,
        0.08762374276,
        0.08806678576,
        0.08540051376,
        0.08537962476000001,
        0.08515069476,
        0.08583064276,
        0.08274175676000001,
        0.08253904576,
        0.08531036376000001,
        0.08763104676,
        0.08427318476000001,
        0.08310488876,
        0.08791766576,
        0.08601053076,
        0.08250224676,
        0.08306927276,
        0.08441766576,
        0.08637488576,
        0.08621811076000001,
        0.08332781776,
        0.08778259176,
        0.08653370376,
        0.08227464876,
        0.08809385676,
        0.08638102676000001,
        0.08259742476
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.08586068348727274,
      "stddev": 0.002139775535686925,
      "median": 0.08638970376,
      "user": 0.020703227272727276,
      "system": 0.007786092121212122,
      "min": 0.08107694676,
      "max": 0.08970639776,
      "times": [
        0.08617492976,
        0.08665653476,
        0.08629867276,
        0.08387112976,
        0.08699637376,
        0.08740948976,
        0.08680560476,
        0.08937378276,
        0.08622821976,
        0.08721775976,
        0.08815780676,
        0.08606943076,
        0.08365992176,
        0.08683777576,
        0.08428591876000001,
        0.08587470476,
        0.08107694676,
        0.08712244976,
        0.08496829176000001,
        0.08657424076,
        0.08234353776,
        0.08248161776,
        0.08739406076,
        0.08674335776,
        0.08295179176,
        0.08862670876,
        0.08764983176,
        0.08584743476000001,
        0.08217368876,
        0.08300797676,
        0.08970639776,
        0.08638970376,
        0.08642646176
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.525 ± 0.139 4.420 4.790 1.30 ± 0.05
pacquet@main 4.545 ± 0.105 4.434 4.673 1.30 ± 0.04
pnpr@HEAD 3.535 ± 0.113 3.429 3.756 1.01 ± 0.04
pnpr@main 3.494 ± 0.058 3.433 3.593 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.52513435926,
      "stddev": 0.13939844420975084,
      "median": 4.44329509126,
      "user": 1.6626364999999996,
      "system": 1.37356664,
      "min": 4.42014265176,
      "max": 4.79005313976,
      "times": [
        4.58844177276,
        4.43376620976,
        4.44318482376,
        4.53687414276,
        4.42167661576,
        4.42014265176,
        4.79005313976,
        4.42964229776,
        4.443405358760001,
        4.74415657976
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.544596654059999,
      "stddev": 0.10511306770048523,
      "median": 4.54876060376,
      "user": 1.6879963999999998,
      "system": 1.3056076400000003,
      "min": 4.43352153676,
      "max": 4.67260929276,
      "times": [
        4.62826104476,
        4.66824991876,
        4.67260929276,
        4.437191325760001,
        4.60925681476,
        4.43933905176,
        4.43909522376,
        4.43352153676,
        4.63017793876,
        4.4882643927600006
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5349776866600005,
      "stddev": 0.11313046894759231,
      "median": 3.4871423117600004,
      "user": 1.1615248999999999,
      "system": 1.20813614,
      "min": 3.42897577576,
      "max": 3.7556594397600005,
      "times": [
        3.45209361876,
        3.5846673787600003,
        3.70198356776,
        3.47711459876,
        3.42897577576,
        3.44348100976,
        3.46564805576,
        3.5429833967600004,
        3.7556594397600005,
        3.4971700247600004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.4939939490600005,
      "stddev": 0.05769059381018632,
      "median": 3.4695377627600004,
      "user": 1.1311449999999998,
      "system": 1.2339777399999998,
      "min": 3.4328918147600005,
      "max": 3.5930666377600002,
      "times": [
        3.4649472787600004,
        3.4731369727600003,
        3.4622685247600002,
        3.4874134167600004,
        3.4659385527600004,
        3.5766109337600005,
        3.4350240927600004,
        3.4328918147600005,
        3.54864126576,
        3.5930666377600002
      ]
    }
  ]
}

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13398
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,725.06 ms
(-0.32%)Baseline: 2,733.77 ms
3,280.53 ms
(83.07%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,883.48 ms
(-0.39%)Baseline: 1,890.90 ms
2,269.08 ms
(83.01%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
571.75 ms
(-0.46%)Baseline: 574.39 ms
689.27 ms
(82.95%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
345.42 ms
(-1.15%)Baseline: 349.45 ms
419.33 ms
(82.37%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,391.93 ms
(+1.39%)Baseline: 2,359.14 ms
2,830.96 ms
(84.49%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,420.14 ms
(-0.10%)Baseline: 4,424.38 ms
5,309.25 ms
(83.25%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
236.87 ms
(-3.87%)Baseline: 246.41 ms
295.69 ms
(80.11%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13398
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,436.43 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
299.28 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
295.77 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
82.27 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,349.67 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,428.98 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
264.75 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan
zkochan merged commit 208e5af into main Jul 26, 2026
36 checks passed
@zkochan
zkochan deleted the fix-13358 branch July 26, 2026 07:20
kairosci added a commit to kairosci/pnpm that referenced this pull request Jul 27, 2026
…scripts pnpm's way (pnpm#13398)

pacquet decided which projects fire their own preinstall / install /
postinstall / prepare from one `is_full_install` flag: every project the
run materialized ran them for a selector-less `install` or `update`, and
no project ran them for `add` or a targeted `update <pkg>`.

pnpm decides per project, from the mutated-importer list its command
layer builds — the projects the command was pointed at, plus the
workspace root, which the recursive dispatch pushes in as a plain
`mutation: 'install'` whenever the selection leaves it out. A project
runs its scripts when that list covers only part of the workspace, or,
when it covers the whole workspace, when its own mutation is a full
install. The rule was read off the TypeScript CLI by running it, not off
its source: 17 invocations across four workspace shapes, each project
stamping a file from `postinstall`.

Replace the flag with `ProjectMutation`, which names pnpm's mutation kind
(`InstallWorkspace`, `InstallSelected`, `InstallSome`, `NoInstall`), and
select the projects from it. `ProjectMutation::is_full_install()` keeps
the old flag's other four uses — the scope log, the optimistic
repeat-install gate, the resolution-skipped message and the
`--no-optional` exclusion — unchanged.

What changes for users: `update <pkg>` and `add <pkg>` in a workspace
stop skipping the workspace root's scripts, `update` at a workspace root
stops running the other members' scripts, and `update --latest` stops
running the project's own scripts (it rewrites named dependency specs,
so pnpm makes it `installSome` like `update <pkg>`).

The TypeScript CLI is unchanged; it gets the same matrix as e2e tests so
the contract is pinned on both sides.

Closes pnpm#13358.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pacquet: a targeted update <selector> skips the project's own lifecycle scripts, pnpm runs them

3 participants