Skip to content

fix: respect workspace root ignores when packing - #12878

Merged
zkochan merged 5 commits into
pnpm:mainfrom
ychampion:fix-pack-workspace-root-gitignore
Jul 13, 2026
Merged

zkochan merged 5 commits into
pnpm:mainfrom
ychampion:fix-pack-workspace-root-gitignore

Conversation

@ychampion

@ychampion ychampion commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Squash Commit Body

Fixes pnpm/pnpm#12560.

Workspace package packing now passes workspace context into packlist only when the package is actually under that workspace root. That lets workspace-root .npmignore/.gitignore files affect sub-package packing while preserving package-only behavior for normal packlist calls and unrelated workspaceDir values.

The pacquet packlist and pack path use the same workspace-aware rules so the Rust port stays aligned with the TypeScript CLI.

Validation

  • corepack pnpm --filter @pnpm/releasing.commands test pnpm11/releasing/commands/test/publish/pack.ts -t 'workspace root gitignore' - passed\n- corepack pnpm --filter @pnpm/fs.packlist test - passed\n- cargo fmt --all -- --check - passed\n- cargo test -p pacquet-fs-packlist -- --nocapture - passed\n- cargo test -p pacquet-pack -- --nocapture - passed\n\n## Checklist\n\n- [x] The change is implemented in both the TypeScript CLI and the Rust pacquet/ port, or the description notes what still needs porting.\n- [x] 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.\n- [x] Added or updated tests.\n- [x] Updated the documentation if needed.\n

Summary by CodeRabbit

  • New Features

    • pnpm pack now uses workspace-root .npmignore and .gitignore when packaging workspace packages.
    • Workspace ignore rules are inherited correctly for workspace context, and .npmignore takes precedence over .gitignore.
  • Bug Fixes

    • Packing from the wrong directory (non-workspace context) no longer incorrectly applies workspace-root ignore rules.
  • Tests

    • Added coverage for workspace vs non-workspace packing scenarios, including precedence and file inclusion/exclusion assertions.

Written by an agent (Codex, gpt-5.5).

@ychampion
ychampion requested a review from zkochan as a code owner July 9, 2026 16:25
Copilot AI review requested due to automatic review settings July 9, 2026 16:25
@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 →

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 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

pnpm pack now passes workspace context through JavaScript and Rust packlist generation. Workspace packages inherit applicable workspace-root .npmignore or .gitignore rules, with tests covering matching, precedence, and unrelated workspace directories.

Changes

Workspace-aware package packing

Layer / File(s) Summary
pnpm11 packlist workspace context
pnpm11/fs/packlist/src/index.ts, pnpm11/fs/packlist/package.json
packlist accepts workspace context, resolves paths, checks subdirectory relationships, and conditionally passes workspace options to npm-packlist.
Rust workspace-aware ignore traversal
pnpm/crates/fs-packlist/src/lib.rs
Rust packlist generation accepts workspace_dir, loads inherited .npmignore or .gitignore rules, and keeps bundled dependency traversal package-local.
Pack API wiring and regression coverage
pnpm/crates/pack/src/lib.rs, pnpm/crates/pack/src/tests.rs, pnpm/crates/fs-packlist/src/tests.rs, pnpm11/releasing/commands/src/publish/pack.ts, pnpm11/releasing/commands/test/publish/pack.ts
Pack APIs forward workspace context, and tests verify workspace-root ignores, .npmignore precedence, and unrelated workspace directories.
Release metadata
.changeset/workspace-pack-gitignore.md
The changeset records patch releases and documents workspace-root ignore behavior.

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

Assessment against linked issues

Objective Addressed Explanation
[#12560] Exclude gitignored files when packing a package inside a workspace ✅

Suggested labels: product: pnpm@11, product: pacquet

Suggested reviewers: zkochan, copilot

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

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.

@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 (2)
pnpm11/fs/packlist/src/index.ts (1)

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

Use the shared is-subdir helper instead of the local duplicate.
This check already exists in the repo, so keep the containment logic centralized rather than reimplementing it here.

🤖 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/fs/packlist/src/index.ts` around lines 22 - 35, The containment check
in packlist is duplicating logic that already exists elsewhere in the repo.
Update packlist in the packlist module to use the shared is-subdir helper
instead of the local containment implementation, keeping the workspaceDir and
resolvedPkgDir decision centralized while preserving the existing packlistOpts
behavior.

Source: Coding guidelines

pacquet/crates/fs-packlist/src/tests.rs (1)

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

Consider adding a test for .npmignore precedence in the workspace root.

add_workspace_ignore_file selects .npmignore over .gitignore when both exist, but all workspace tests use only .gitignore. A test with a workspace-root .npmignore would guard the precedence logic against regressions.

♻️ Suggested additional test
+#[test]
+fn workspace_root_npmignore_takes_precedence_over_gitignore() {
+    let dir = tempdir().unwrap();
+    fs::write(dir.path().join(".gitignore"), "src/\n").unwrap();
+    fs::write(dir.path().join(".npmignore"), "dist/\n").unwrap();
+    let root = dir.path().join("packages").join("pkg");
+    fs::create_dir_all(&root).unwrap();
+    touch(&root, "package.json");
+    touch(&root, "dist/generated.js");
+    touch(&root, "src/index.js");
+
+    let manifest = json!({ "name": "x", "version": "0.0.0" });
+    let out = packlist_with_options(
+        &root,
+        &manifest,
+        PacklistOptions { workspace_dir: Some(dir.path()) },
+    )
+    .unwrap();
+
+    // .npmignore excludes dist/, .gitignore's src/ is ignored
+    assert!(!out.contains(&"dist/generated.js".to_string()), "{out:?}");
+    assert!(out.contains(&"src/index.js".to_string()), "{out:?}");
+}
🤖 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 `@pacquet/crates/fs-packlist/src/tests.rs` around lines 435 - 458, Add a
workspace-root ignore precedence test in tests.rs to cover
add_workspace_ignore_file behavior when both .npmignore and .gitignore exist.
Create a case around packlist_with_options and workspace_dir where the workspace
root has both files, with .npmignore taking precedence over .gitignore, and
assert the resulting packlist reflects the .npmignore rules rather than the
.gitignore rules. Use the existing
workspace_root_gitignore_excludes_workspace_package_files test pattern and the
add_workspace_ignore_file/packlist_with_options symbols to locate the right test
area.
🤖 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 `@pacquet/crates/fs-packlist/src/tests.rs`:
- Around line 435-458: Add a workspace-root ignore precedence test in tests.rs
to cover add_workspace_ignore_file behavior when both .npmignore and .gitignore
exist. Create a case around packlist_with_options and workspace_dir where the
workspace root has both files, with .npmignore taking precedence over
.gitignore, and assert the resulting packlist reflects the .npmignore rules
rather than the .gitignore rules. Use the existing
workspace_root_gitignore_excludes_workspace_package_files test pattern and the
add_workspace_ignore_file/packlist_with_options symbols to locate the right test
area.

In `@pnpm11/fs/packlist/src/index.ts`:
- Around line 22-35: The containment check in packlist is duplicating logic that
already exists elsewhere in the repo. Update packlist in the packlist module to
use the shared is-subdir helper instead of the local containment implementation,
keeping the workspaceDir and resolvedPkgDir decision centralized while
preserving the existing packlistOpts behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f55f734-358c-4d16-9e8b-1a264a21fb03

📥 Commits

Reviewing files that changed from the base of the PR and between c70e33e and 1d58d01.

📒 Files selected for processing (8)
  • .changeset/workspace-pack-gitignore.md
  • pacquet/crates/fs-packlist/src/lib.rs
  • pacquet/crates/fs-packlist/src/tests.rs
  • pacquet/crates/pack/src/lib.rs
  • pacquet/crates/pack/src/tests.rs
  • pnpm11/fs/packlist/src/index.ts
  • pnpm11/releasing/commands/src/publish/pack.ts
  • pnpm11/releasing/commands/test/publish/pack.ts

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 9, 2026
ychampion added a commit to ychampion/pnpm that referenced this pull request Jul 9, 2026
Use the shared subdirectory helper for workspace package containment, and add
pacquet coverage for workspace-root .npmignore precedence.

Constraint: CodeRabbit requested both follow-ups on pnpm#12878.
Rejected: keep local containment helper | duplicates repo dependency logic.
Confidence: high
Scope-risk: narrow
Directive: Keep workspace .gitignore and .npmignore cases covered.
Tested: corepack pnpm --filter fs.packlist test
Tested: cargo test -p pacquet-fs-packlist workspace_root_npmignore...
Tested: cargo test -p pacquet-fs-packlist
Tested: cargo fmt --all -- --check
Tested: git diff --check
Not-tested: full Rust workspace coverage job; unrelated rust-lld bus error.
Copilot AI review requested due to automatic review settings July 9, 2026 17:02

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.

@ychampion

ychampion commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressed the two CodeRabbit follow-ups in ff678e2:

  • switched the TS packlist containment check to the shared is-subdir helper, while keeping the root-package guard
  • added pacquet coverage for workspace-root .npmignore taking precedence over .gitignore

Validation:

  • corepack pnpm --filter fs.packlist test
  • cargo test -p pacquet-fs-packlist workspace_root_npmignore_takes_precedence_over_gitignore -- --nocapture
  • cargo test -p pacquet-fs-packlist -- --nocapture
  • cargo fmt --all -- --check
  • git diff --check

The current Pacquet coverage failure looks unrelated to this patch: rust-lld bus-error’d while compiling an unrelated pacquet-cli test binary before tests ran.


Written by an agent (Codex, gpt-5.5).

@codecov-commenter

codecov-commenter commented Jul 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.30508% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.35%. Comparing base (c70e33e) to head (ebd887b).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pacquet/crates/fs-packlist/src/lib.rs 98.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12878      +/-   ##
==========================================
- Coverage   85.36%   85.35%   -0.01%     
==========================================
  Files         453      453              
  Lines       70913    71129     +216     
==========================================
+ Hits        60533    60711     +178     
- Misses      10380    10418      +38     

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

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 202f1cb49881

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

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.045 ± 0.090 3.922 4.227 1.93 ± 0.13
pacquet@main 4.008 ± 0.140 3.868 4.223 1.92 ± 0.14
pnpr@HEAD 2.123 ± 0.122 1.964 2.365 1.02 ± 0.09
pnpr@main 2.091 ± 0.134 1.940 2.363 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.04467680114,
      "stddev": 0.09031362384898364,
      "median": 4.04873537294,
      "user": 3.92674212,
      "system": 3.4073684799999997,
      "min": 3.92182071094,
      "max": 4.22686728594,
      "times": [
        4.07040887894,
        4.12432752594,
        4.0286203809400005,
        4.22686728594,
        4.08552605994,
        3.98913067694,
        3.96281054694,
        3.92182071094,
        3.96840557994,
        4.06885036494
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.007850532440001,
      "stddev": 0.1395913805804727,
      "median": 3.94050554894,
      "user": 3.87860872,
      "system": 3.390073879999999,
      "min": 3.86799831794,
      "max": 4.22276206494,
      "times": [
        4.17255127894,
        3.87389811594,
        3.86799831794,
        4.1909672569400005,
        4.05076835194,
        3.89929867594,
        4.22276206494,
        3.91925016394,
        3.92503478894,
        3.95597630894
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.1226638064399994,
      "stddev": 0.12155865314878607,
      "median": 2.07377435744,
      "user": 2.74823122,
      "system": 2.90637518,
      "min": 1.96416431294,
      "max": 2.36501641694,
      "times": [
        2.36501641694,
        1.96416431294,
        2.05836521494,
        2.09455182194,
        2.06121008894,
        2.07627203794,
        2.07127667694,
        2.05451250894,
        2.20089202094,
        2.28037696394
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.0909331647399996,
      "stddev": 0.1338715795807494,
      "median": 2.03524020994,
      "user": 2.75307412,
      "system": 2.89897808,
      "min": 1.94030529494,
      "max": 2.3625102669399998,
      "times": [
        2.04424517094,
        2.01899759594,
        2.02553088194,
        2.02623524894,
        1.94030529494,
        2.11315777594,
        2.26996437894,
        1.97116273994,
        2.3625102669399998,
        2.13722229294
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 645.2 ± 14.7 627.1 673.1 1.00
pacquet@main 675.3 ± 31.0 645.3 737.6 1.05 ± 0.05
pnpr@HEAD 722.6 ± 65.1 678.3 899.6 1.12 ± 0.10
pnpr@main 723.9 ± 20.1 704.9 770.4 1.12 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6451713154000001,
      "stddev": 0.014670744181274668,
      "median": 0.6438180758000001,
      "user": 0.37910994,
      "system": 1.3128093600000001,
      "min": 0.6271159403000001,
      "max": 0.6731296543,
      "times": [
        0.6335331353,
        0.6369464233000001,
        0.6561368343,
        0.6360432273,
        0.6506897283,
        0.6535590513,
        0.6271159403000001,
        0.6299260503,
        0.6731296543,
        0.6546331093
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6753098011,
      "stddev": 0.03102396752128259,
      "median": 0.6666673193,
      "user": 0.40594063999999996,
      "system": 1.32950436,
      "min": 0.6453064043,
      "max": 0.7375876393,
      "times": [
        0.6492511983,
        0.6609284773,
        0.6745919953,
        0.6704758663,
        0.6520807723000001,
        0.7230217973,
        0.6453064043,
        0.6769950883,
        0.7375876393,
        0.6628587723
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.7225944738000001,
      "stddev": 0.0651106814495016,
      "median": 0.7021247938,
      "user": 0.4014194399999999,
      "system": 1.3586962599999999,
      "min": 0.6782801293,
      "max": 0.8995524083,
      "times": [
        0.6938562743,
        0.6782801293,
        0.6905705153,
        0.6880116813,
        0.7045498903,
        0.7089879433,
        0.6996996973,
        0.8995524083,
        0.7491861123,
        0.7132500863
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.7238659169,
      "stddev": 0.020075260396655567,
      "median": 0.7149335958,
      "user": 0.42128694,
      "system": 1.36651746,
      "min": 0.7049314183000001,
      "max": 0.7704071173,
      "times": [
        0.7355762793,
        0.7049314183000001,
        0.7081945663,
        0.7148014233000001,
        0.7150657683,
        0.7131262863,
        0.7342850133000001,
        0.7338125703,
        0.7084587263000001,
        0.7704071173
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.279 ± 0.032 4.234 4.329 1.98 ± 0.10
pacquet@main 4.296 ± 0.028 4.238 4.339 1.99 ± 0.10
pnpr@HEAD 2.159 ± 0.102 2.053 2.348 1.00
pnpr@main 2.231 ± 0.108 2.104 2.428 1.03 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.27899435576,
      "stddev": 0.031559136300764914,
      "median": 4.278023924459999,
      "user": 3.8432976599999997,
      "system": 3.3214852,
      "min": 4.234070851959999,
      "max": 4.32920266596,
      "times": [
        4.26387317996,
        4.27742878796,
        4.28109825796,
        4.284531696959999,
        4.32902732496,
        4.27861906096,
        4.2733940839599995,
        4.2386976469599995,
        4.234070851959999,
        4.32920266596
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.29569984486,
      "stddev": 0.027551288408503335,
      "median": 4.29735465996,
      "user": 3.8450591599999995,
      "system": 3.3520851,
      "min": 4.23787484996,
      "max": 4.33890196296,
      "times": [
        4.23787484996,
        4.293462884959999,
        4.310030611959999,
        4.307820201959999,
        4.28830685996,
        4.33890196296,
        4.27581616396,
        4.28293079796,
        4.32060767996,
        4.3012464349599995
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.1591921637600002,
      "stddev": 0.10248262486146335,
      "median": 2.1287513989600004,
      "user": 2.6160692599999997,
      "system": 2.831214,
      "min": 2.05307125096,
      "max": 2.3481686079600004,
      "times": [
        2.08571422796,
        2.05307125096,
        2.06612526496,
        2.32902024396,
        2.1276083689600003,
        2.1127258179600004,
        2.3481686079600004,
        2.18408817696,
        2.12989442896,
        2.1555052489600004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.2305007967600003,
      "stddev": 0.10782126386082076,
      "median": 2.2016992894600005,
      "user": 2.6020024599999996,
      "system": 2.8445989999999997,
      "min": 2.10425796196,
      "max": 2.4284018669600003,
      "times": [
        2.1809903689600003,
        2.38846765296,
        2.28049908396,
        2.10425796196,
        2.14964357796,
        2.1700302709600003,
        2.24541018796,
        2.22240820996,
        2.1348987859600004,
        2.4284018669600003
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.472 ± 0.021 1.447 1.516 2.15 ± 0.04
pacquet@main 1.465 ± 0.030 1.429 1.534 2.14 ± 0.05
pnpr@HEAD 0.683 ± 0.005 0.675 0.692 1.00
pnpr@main 0.714 ± 0.080 0.677 0.940 1.04 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.4723233588799998,
      "stddev": 0.02115163566789662,
      "median": 1.46936595318,
      "user": 1.4350744199999999,
      "system": 1.7275738400000002,
      "min": 1.44685898668,
      "max": 1.51637124068,
      "times": [
        1.44685898668,
        1.46832887468,
        1.45963628968,
        1.48095080568,
        1.46278560768,
        1.4704030316799999,
        1.51637124068,
        1.4762854106799999,
        1.49395369768,
        1.44765964368
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.4653002692800001,
      "stddev": 0.029942987123392308,
      "median": 1.45572321118,
      "user": 1.44443772,
      "system": 1.7361295399999999,
      "min": 1.42874119868,
      "max": 1.53421253468,
      "times": [
        1.53421253468,
        1.47922467968,
        1.4693143686799999,
        1.45502857768,
        1.45641784468,
        1.45002114168,
        1.45218486468,
        1.42874119868,
        1.43963737168,
        1.48822011068
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.6833559542799998,
      "stddev": 0.005361953252112363,
      "median": 0.6836801666800001,
      "user": 0.3637065199999999,
      "system": 1.28414544,
      "min": 0.67464739868,
      "max": 0.69206417168,
      "times": [
        0.68728458068,
        0.67464739868,
        0.68352586768,
        0.69206417168,
        0.6838344656800001,
        0.68145457168,
        0.67967171468,
        0.68966027768,
        0.68390487568,
        0.67751161868
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.7139234397800001,
      "stddev": 0.07972258843093814,
      "median": 0.6905073446800001,
      "user": 0.38408032,
      "system": 1.2811824400000003,
      "min": 0.67748269268,
      "max": 0.93989400168,
      "times": [
        0.69277166568,
        0.68278840568,
        0.69704418768,
        0.67748269268,
        0.69524554668,
        0.69931791568,
        0.68824302368,
        0.68216139268,
        0.93989400168,
        0.68428556568
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.176 ± 0.036 3.130 3.237 4.70 ± 0.08
pacquet@main 3.193 ± 0.047 3.122 3.268 4.72 ± 0.10
pnpr@HEAD 0.676 ± 0.009 0.659 0.689 1.00
pnpr@main 0.693 ± 0.010 0.681 0.713 1.03 ± 0.02
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.1763173531000004,
      "stddev": 0.03589663771731859,
      "median": 3.1703405231,
      "user": 1.89877692,
      "system": 2.01871494,
      "min": 3.1297558466,
      "max": 3.2374418646,
      "times": [
        3.1597126376,
        3.1934382356,
        3.1595110506,
        3.1799834896,
        3.1677993616,
        3.1297558466,
        3.1328803956,
        3.2374418646,
        3.1728816846,
        3.2297689646000003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 3.1925073894,
      "stddev": 0.046528550769399164,
      "median": 3.1965458431,
      "user": 1.92323412,
      "system": 2.02811564,
      "min": 3.1222197186000002,
      "max": 3.2675108956,
      "times": [
        3.2433207366,
        3.2101635006,
        3.2252288806,
        3.1724908026,
        3.1921428416,
        3.1222197186000002,
        3.2009488446,
        3.2675108956,
        3.1397411926000003,
        3.1513064806
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.6757216233000001,
      "stddev": 0.009418251746968078,
      "median": 0.6747241661000001,
      "user": 0.34841682,
      "system": 1.2920717399999997,
      "min": 0.6592656016,
      "max": 0.6887997426,
      "times": [
        0.6854322736,
        0.6737329706,
        0.6666111086000001,
        0.6684170796,
        0.6592656016,
        0.6887997426,
        0.6742296646,
        0.6795545096,
        0.6752186676,
        0.6859546146
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.6927545328,
      "stddev": 0.009992922370199534,
      "median": 0.6881837381,
      "user": 0.37690042,
      "system": 1.27503754,
      "min": 0.6813151406,
      "max": 0.7131799426000001,
      "times": [
        0.7131799426000001,
        0.6950710226,
        0.6835813096,
        0.6874339486000001,
        0.6813151406,
        0.6884338376,
        0.6996569046,
        0.6879336386,
        0.6874526466,
        0.7034869366000001
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 663.8 ± 7.5 652.8 676.9 5.91 ± 0.07
pacquet@main 669.2 ± 6.3 659.3 678.4 5.96 ± 0.06
pnpr@HEAD 112.7 ± 2.1 110.5 121.2 1.00 ± 0.02
pnpr@main 112.3 ± 0.5 111.3 114.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6638378356400001,
      "stddev": 0.007481134311338952,
      "median": 0.66213199434,
      "user": 0.6177722799999998,
      "system": 0.15763645999999998,
      "min": 0.65277437234,
      "max": 0.67693751634,
      "times": [
        0.65277437234,
        0.66271560034,
        0.66527290634,
        0.6600057073400001,
        0.6581644993400001,
        0.6688964243400001,
        0.6615483883400001,
        0.6737469983400001,
        0.67693751634,
        0.6583159433400001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6691866644400002,
      "stddev": 0.006345139138838323,
      "median": 0.66839052434,
      "user": 0.62452458,
      "system": 0.15706546,
      "min": 0.65931355034,
      "max": 0.67844291034,
      "times": [
        0.6621018333400001,
        0.65931355034,
        0.67844291034,
        0.67560715634,
        0.66820521034,
        0.66857583834,
        0.6656142983400001,
        0.67530103434,
        0.6736088413400001,
        0.6650959713400001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.11270734725666669,
      "stddev": 0.002050154931948526,
      "median": 0.11221040684000001,
      "user": 0.02812132166666666,
      "system": 0.021915976666666667,
      "min": 0.11049644734000001,
      "max": 0.12117060334000002,
      "times": [
        0.11136539634,
        0.11286672234,
        0.11361094234,
        0.11049644734000001,
        0.11190790434,
        0.11245442234000001,
        0.11196178434000001,
        0.11239849534000002,
        0.11214012234000001,
        0.11201966934,
        0.11217726234000001,
        0.11242802934000001,
        0.11194082734000001,
        0.11217242534,
        0.11213595234000001,
        0.11293298034,
        0.11594403234,
        0.12117060334000002,
        0.11134338934000002,
        0.11252176734000001,
        0.11224355134000001,
        0.11240221534000001,
        0.11167050834,
        0.11267088334000001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.11229376963166665,
      "stddev": 0.0005216715930386034,
      "median": 0.11230576534,
      "user": 0.027371321666666667,
      "system": 0.021973893333333328,
      "min": 0.11130790734000001,
      "max": 0.11403581134000002,
      "times": [
        0.11268452334000001,
        0.11230046534,
        0.11191378334,
        0.11227832234000001,
        0.11240385734000001,
        0.11241302134,
        0.11242621534000001,
        0.11254388534000001,
        0.11203246834000001,
        0.11403581134000002,
        0.11130790734000001,
        0.11231106534,
        0.11160585234,
        0.11193161434000001,
        0.11257616234000001,
        0.11190400934000001,
        0.11206827134000001,
        0.11269566934000001,
        0.11233037934000001,
        0.11204800134000001,
        0.11185084034000001,
        0.11276123634000002,
        0.11195677634000001,
        0.11267033234000001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 6.744 ± 0.105 6.600 6.912 1.38 ± 0.04
pacquet@main 6.830 ± 0.139 6.650 7.081 1.40 ± 0.05
pnpr@HEAD 4.887 ± 0.140 4.744 5.184 1.00
pnpr@main 4.923 ± 0.083 4.823 5.067 1.01 ± 0.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 6.744315746340002,
      "stddev": 0.10455235451426777,
      "median": 6.746865850040001,
      "user": 4.078608220000001,
      "system": 3.654186279999999,
      "min": 6.60042453354,
      "max": 6.91204809454,
      "times": [
        6.81296479554,
        6.640667859540001,
        6.771839772540001,
        6.65064136454,
        6.60042453354,
        6.91204809454,
        6.721891927540001,
        6.857700411540001,
        6.811993661540001,
        6.662985042540001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 6.829679437339999,
      "stddev": 0.13894560923603946,
      "median": 6.825826565040001,
      "user": 4.064100120000001,
      "system": 3.6960718799999994,
      "min": 6.65035673054,
      "max": 7.081263922540001,
      "times": [
        6.823445914540001,
        6.828207215540001,
        6.99857977154,
        7.081263922540001,
        6.71881639754,
        6.763642816540001,
        6.90562372954,
        6.65035673054,
        6.66715857454,
        6.859699300540001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 4.88665880004,
      "stddev": 0.13981589874099096,
      "median": 4.852935976540001,
      "user": 2.8544873199999996,
      "system": 3.12803238,
      "min": 4.743987346540001,
      "max": 5.18435871754,
      "times": [
        4.882571978540001,
        4.840398981540001,
        4.74710991554,
        4.89932901454,
        4.79562168254,
        4.83683461854,
        4.865472971540001,
        5.07090277354,
        4.743987346540001,
        5.18435871754
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 4.923228451140001,
      "stddev": 0.08343551232311357,
      "median": 4.89200565554,
      "user": 2.85479112,
      "system": 3.1068084799999998,
      "min": 4.82349252154,
      "max": 5.06726109454,
      "times": [
        4.891979532540001,
        5.0085575245400005,
        5.06726109454,
        4.885234069540001,
        4.851392819540001,
        5.023042425540001,
        4.82349252154,
        4.942234687540001,
        4.847058057540001,
        4.892031778540001
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12878
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
4,278.99 ms
(+0.24%)Baseline: 4,268.93 ms
5,122.72 ms
(83.53%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
3,176.32 ms
(+4.34%)Baseline: 3,044.19 ms
3,653.03 ms
(86.95%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
1,472.32 ms
(+7.74%)Baseline: 1,366.52 ms
1,639.82 ms
(89.79%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
663.84 ms
(+1.99%)Baseline: 650.88 ms
781.05 ms
(84.99%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
4,044.68 ms
(-1.66%)Baseline: 4,113.02 ms
4,935.63 ms
(81.95%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
6,744.32 ms
(-3.08%)Baseline: 6,958.41 ms
8,350.10 ms
(80.77%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
645.17 ms
(+0.73%)Baseline: 640.53 ms
768.63 ms
(83.94%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12878
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
2,159.19 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
675.72 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
683.36 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
112.71 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,122.66 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
4,886.66 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
722.59 ms
🐰 View full continuous benchmarking report in Bencher

Copilot AI review requested due to automatic review settings July 9, 2026 20:44

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.

@ychampion
ychampion force-pushed the fix-pack-workspace-root-gitignore branch from ebd887b to 202f1cb Compare July 10, 2026 20:34
Copilot AI review requested due to automatic review settings July 10, 2026 20:34
ychampion added a commit to ychampion/pnpm that referenced this pull request Jul 10, 2026
Use the shared subdirectory helper for workspace package containment, and add
pacquet coverage for workspace-root .npmignore precedence.

Constraint: CodeRabbit requested both follow-ups on pnpm#12878.
Rejected: keep local containment helper | duplicates repo dependency logic.
Confidence: high
Scope-risk: narrow
Directive: Keep workspace .gitignore and .npmignore cases covered.
Tested: corepack pnpm --filter fs.packlist test
Tested: cargo test -p pacquet-fs-packlist workspace_root_npmignore...
Tested: cargo test -p pacquet-fs-packlist
Tested: cargo fmt --all -- --check
Tested: git diff --check
Not-tested: full Rust workspace coverage job; unrelated rust-lld bus error.

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.

ychampion and others added 4 commits July 13, 2026 16:12
Workspace package packing should use workspace-root ignore context only when the package is actually inside that workspace. This keeps the default package-only packlist behavior unchanged while matching npm-packlist for workspace packages.

Constraint: Keep TypeScript pnpm pack and pacquet pack behavior aligned.

Rejected: Enabling parent ignore traversal generally | it would reintroduce arbitrary parent ignore leakage outside workspace context.

Confidence: high

Scope-risk: narrow

Directive: Apply workspace ignore context only for actual workspace descendants.

Tested: corepack pnpm --filter @pnpm/releasing.commands test pnpm11/releasing/commands/test/publish/pack.ts -t 'workspace root gitignore'; corepack pnpm --filter @pnpm/fs.packlist test; cargo fmt --all -- --check; cargo test -p pacquet-fs-packlist; cargo test -p pacquet-pack.

Not-tested: Full repository CI matrix.
Use the shared subdirectory helper for workspace package containment, and add
pacquet coverage for workspace-root .npmignore precedence.

Constraint: CodeRabbit requested both follow-ups on pnpm#12878.
Rejected: keep local containment helper | duplicates repo dependency logic.
Confidence: high
Scope-risk: narrow
Directive: Keep workspace .gitignore and .npmignore cases covered.
Tested: corepack pnpm --filter fs.packlist test
Tested: cargo test -p pacquet-fs-packlist workspace_root_npmignore...
Tested: cargo test -p pacquet-fs-packlist
Tested: cargo fmt --all -- --check
Tested: git diff --check
Not-tested: full Rust workspace coverage job; unrelated rust-lld bus error.
Constraint: Keep derive ordering consistent with perfectionist.

Confidence: high

Scope-risk: narrow

Tested: cargo test and cargo clippy for pacquet-fs-packlist; cargo fmt --check

Not-tested: custom Dylint locally because cargo-dylint is not installed
The rebase onto main pulled in the new required PackOptions field
before_packing_hooks; add it to the workspace-gitignore pack test so the
crate compiles. Also name the pacquet wrapper in the changeset so the
Rust side of this parity change is released alongside the TypeScript CLI.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@zkochan
zkochan force-pushed the fix-pack-workspace-root-gitignore branch from 202f1cb to df26590 Compare July 13, 2026 14:14
Copilot AI review requested due to automatic review settings July 13, 2026 14:14
@greptile-apps

greptile-apps Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge. The change is well-scoped: new opt-in options with correct guards, existing callers pass None/undefined and are unaffected, and the ignore-file walk is only activated when the package is a genuine descendant of the workspace root.

The core logic is straightforward: a subdir check gates all new behavior, existing code paths pass None/undefined and remain unchanged, and both the TypeScript and Rust sides are covered by tests that exercise the positive, unrelated-workspace, and negation-override scenarios. No data mutation, no auth boundary, no async coordination concerns.

No files require special attention beyond what the previous review threads already noted about the ignore crate's add_ignore precedence tier in pnpm/crates/fs-packlist/src/lib.rs.

Reviews (2): Last reviewed commit: "test: cover package-level ignore negatio..." | Re-trigger Greptile

Comment thread pnpm/crates/fs-packlist/src/lib.rs Resolved
Comment thread pnpm/crates/fs-packlist/src/lib.rs Resolved
@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Action required

1. Missing trailing comma in opts type ✗ Dismissed 📘 Rule violation ⚙ Maintainability
Description
The multi-line opts object type in packlist() does not use a trailing comma on its last
property, violating the required TypeScript trailing-comma style. This increases diff noise and
breaks consistency with the mandated formatting rule.
Code

pnpm11/fs/packlist/src/index.ts[R23-26]

export async function packlist (pkgDir: string, opts?: {
  manifest?: Record<string, unknown>
+  workspaceDir?: string
}): Promise<string[]> {
-  const pkg = opts?.manifest ?? readPackageJson(pkgDir)
-  const tree = buildRootTree(pkgDir, pkg)
-  const files = await npmPacklist(tree)
Evidence
PR Compliance ID 713434 requires trailing commas in multi-line TypeScript constructs. The updated
packlist() signature includes a multi-line type literal for opts whose last entry
(workspaceDir?: string) has no trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/fs/packlist/src/index.ts[23-26]

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

## Issue description
The `packlist()` function’s multi-line `opts` type literal is missing a trailing comma on the last property (`workspaceDir?: string`). The repo compliance rule requires trailing commas for multi-line TypeScript constructs.

## Issue Context
File: `pnpm11/fs/packlist/src/index.ts` — `packlist()` was modified to accept `workspaceDir`, introducing/altering a multi-line type literal.

## Fix Focus Areas
- pnpm11/fs/packlist/src/index.ts[23-26]

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



Remediation recommended

2. Workspace ignore path mismatch 🐞 Bug ⛨ Security
Description
add_workspace_ignore_files gates workspace-root ignore injection on
pkg_dir.strip_prefix(workspace_dir), which is a purely lexical comparison, so workspace ignores
are silently skipped when workspace_dir and pkg_dir use different but equivalent representations
(e.g. relative vs absolute, or paths containing ./..). This can re-include files that should
have been excluded by workspace-root .npmignore/.gitignore, especially for callers that forward
unnormalized paths (e.g. the NAPI bridge).
Code

pnpm/crates/fs-packlist/src/lib.rs[R418-424]

+    let Some(workspace_dir) = workspace_dir else { return Ok(()) };
+    let Ok(rel) = pkg_dir.strip_prefix(workspace_dir) else { return Ok(()) };
+    if rel.as_os_str().is_empty() {
+        return Ok(());
+    }
+    let Some(pkg_parent) = pkg_dir.parent() else { return Ok(()) };
+    let Ok(parent_rel) = pkg_parent.strip_prefix(workspace_dir) else { return Ok(()) };
Evidence
The new workspace behavior is controlled entirely by lexical strip_prefix checks; if those checks
fail due to mismatched path representations, no workspace-root ignore files are registered.
Higher-level callers forward paths without guaranteeing normalization (notably the NAPI bridge),
making this a practical footgun that can cause workspace ignores to be skipped.

pnpm/crates/fs-packlist/src/lib.rs[413-434]
pnpm/crates/pack/src/lib.rs[313-318]
pnpm/crates/napi/src/pack.rs[57-77]
pnpm11/fs/packlist/src/index.ts[23-35]

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

## Issue description
Workspace-root ignore files are added only when `pkg_dir.strip_prefix(workspace_dir)` succeeds. Because `strip_prefix` is lexical, equivalent paths with different representations (relative/absolute, `.`/`..`, and sometimes Windows-casing differences) can fail the check and silently disable the new workspace ignore behavior.

## Issue Context
- Rust pack forwards `opts.workspace_dir` directly into `PacklistOptions`.
- The NAPI bridge constructs `workspace_dir`/`dir` from user-provided strings without resolving/cleaning.
- TypeScript implementation resolves both paths with `path.resolve`, but Rust currently does not.

## Fix Focus Areas
- pnpm/crates/fs-packlist/src/lib.rs[413-434]
- pnpm/crates/fs-packlist/src/tests.rs[435-512]
- pnpm/crates/napi/src/pack.rs[57-77]

### Suggested fix approach
1. Normalize `pkg_dir` and `workspace_dir` to a consistent form before calling `strip_prefix` (and before constructing ignore-file paths), e.g.:
  - Prefer an *absolute + cleaned* representation (remove `.` and `..`) without requiring symlink resolution, or
  - Use `canonicalize`/`dunce::canonicalize` when the directories exist (with a safe fallback if canonicalization fails).
2. Add a regression test that passes a workspace dir in a different representation (e.g. `workspace_dir = dir.path().join(".")`) and asserts workspace-root ignores still apply.
3. (Optional hardening) Normalize in the NAPI boundary as well (resolve/absolutize `options.dir` and `options.workspace_dir`) to reduce mismatches at the source.

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


Grey Divider

Previous review results

Review updated until commit abb45b4

Results up to commit df26590


🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Missing trailing comma in opts type ✗ Dismissed 📘 Rule violation ⚙ Maintainability
Description
The multi-line opts object type in packlist() does not use a trailing comma on its last
property, violating the required TypeScript trailing-comma style. This increases diff noise and
breaks consistency with the mandated formatting rule.
Code

pnpm11/fs/packlist/src/index.ts[R23-26]

export async function packlist (pkgDir: string, opts?: {
  manifest?: Record<string, unknown>
+  workspaceDir?: string
}): Promise<string[]> {
-  const pkg = opts?.manifest ?? readPackageJson(pkgDir)
-  const tree = buildRootTree(pkgDir, pkg)
-  const files = await npmPacklist(tree)
Evidence
PR Compliance ID 713434 requires trailing commas in multi-line TypeScript constructs. The updated
packlist() signature includes a multi-line type literal for opts whose last entry
(workspaceDir?: string) has no trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/fs/packlist/src/index.ts[23-26]

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

## Issue description
The `packlist()` function’s multi-line `opts` type literal is missing a trailing comma on the last property (`workspaceDir?: string`). The repo compliance rule requires trailing commas for multi-line TypeScript constructs.

## Issue Context
File: `pnpm11/fs/packlist/src/index.ts` — `packlist()` was modified to accept `workspaceDir`, introducing/altering a multi-line type literal.

## Fix Focus Areas
- pnpm11/fs/packlist/src/index.ts[23-26]

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



Remediation recommended
2. Workspace ignore path mismatch 🐞 Bug ⛨ Security
Description
add_workspace_ignore_files gates workspace-root ignore injection on
pkg_dir.strip_prefix(workspace_dir), which is a purely lexical comparison, so workspace ignores
are silently skipped when workspace_dir and pkg_dir use different but equivalent representations
(e.g. relative vs absolute, or paths containing ./..). This can re-include files that should
have been excluded by workspace-root .npmignore/.gitignore, especially for callers that forward
unnormalized paths (e.g. the NAPI bridge).
Code

pnpm/crates/fs-packlist/src/lib.rs[R418-424]

+    let Some(workspace_dir) = workspace_dir else { return Ok(()) };
+    let Ok(rel) = pkg_dir.strip_prefix(workspace_dir) else { return Ok(()) };
+    if rel.as_os_str().is_empty() {
+        return Ok(());
+    }
+    let Some(pkg_parent) = pkg_dir.parent() else { return Ok(()) };
+    let Ok(parent_rel) = pkg_parent.strip_prefix(workspace_dir) else { return Ok(()) };
Evidence
The new workspace behavior is controlled entirely by lexical strip_prefix checks; if those checks
fail due to mismatched path representations, no workspace-root ignore files are registered.
Higher-level callers forward paths without guaranteeing normalization (notably the NAPI bridge),
making this a practical footgun that can cause workspace ignores to be skipped.

pnpm/crates/fs-packlist/src/lib.rs[413-434]
pnpm/crates/pack/src/lib.rs[313-318]
pnpm/crates/napi/src/pack.rs[57-77]
pnpm11/fs/packlist/src/index.ts[23-35]

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

## Issue description
Workspace-root ignore files are added only when `pkg_dir.strip_prefix(workspace_dir)` succeeds. Because `strip_prefix` is lexical, equivalent paths with different representations (relative/absolute, `.`/`..`, and sometimes Windows-casing differences) can fail the check and silently disable the new workspace ignore behavior.

## Issue Context
- Rust pack forwards `opts.workspace_dir` directly into `PacklistOptions`.
- The NAPI bridge constructs `workspace_dir`/`dir` from user-provided strings without resolving/cleaning.
- TypeScript implementation resolves both paths with `path.resolve`, but Rust currently does not.

## Fix Focus Areas
- pnpm/crates/fs-packlist/src/lib.rs[413-434]
- pnpm/crates/fs-packlist/src/tests.rs[435-512]
- pnpm/crates/napi/src/pack.rs[57-77]

### Suggested fix approach
1. Normalize `pkg_dir` and `workspace_dir` to a consistent form before calling `strip_prefix` (and before constructing ignore-file paths), e.g.:
  - Prefer an *absolute + cleaned* representation (remove `.` and `..`) without requiring symlink resolution, or
  - Use `canonicalize`/`dunce::canonicalize` when the directories exist (with a safe fallback if canonicalization fails).
2. Add a regression test that passes a workspace dir in a different representation (e.g. `workspace_dir = dir.path().join(".")`) and asserts workspace-root ignores still apply.
3. (Optional hardening) Normalize in the NAPI boundary as well (resolve/absolutize `options.dir` and `options.workspace_dir`) to reduce mismatches at the source.

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


Qodo Logo

Comment thread pnpm11/fs/packlist/src/index.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.

🧹 Nitpick comments (1)
pnpm/crates/fs-packlist/src/tests.rs (1)

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

Add a test for intermediate-directory ignore files.

add_workspace_ignore_files adds ignore files from every ancestor directory between the workspace root and the package parent, but the three new tests only exercise the workspace-root case. A .gitignore in packages/ (or any intermediate directory) would go untested. If someone later refactors the loop to only add the workspace root's file, these tests would still pass.

🧪 Suggested intermediate-directory test
#[test]
fn intermediate_directory_gitignore_excludes_workspace_package_files() {
    let dir = tempdir().unwrap();
    let packages = dir.path().join("packages");
    fs::create_dir_all(&packages).unwrap();
    fs::write(packages.join(".gitignore"), "dist/\n").unwrap();
    let root = packages.join("pkg");
    fs::create_dir_all(&root).unwrap();
    touch(&root, "package.json");
    touch(&root, "dist/generated.js");
    touch(&root, "src/index.js");

    let manifest = json!({ "name": "x", "version": "0.0.0" });
    let out = packlist_with_options(
        &root,
        &manifest,
        PacklistOptions { workspace_dir: Some(dir.path()) },
    )
    .unwrap();

    assert!(out.contains(&"src/index.js".to_string()), "{out:?}");
    assert!(
        !out.contains(&"dist/generated.js".to_string()),
        "intermediate-directory .gitignore must exclude `dist/`; received {out:?}",
    );
}
🤖 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/fs-packlist/src/tests.rs` around lines 435 - 511, Add a test
alongside the existing workspace ignore tests that places a .gitignore
containing dist/ in the intermediate packages directory, then creates the
package under packages/pkg with package.json, dist/generated.js, and
src/index.js. Use packlist_with_options with workspace_dir set to the workspace
root and assert src/index.js is included while dist/generated.js is excluded,
verifying intermediate-directory ignore files are applied.
🤖 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/fs-packlist/src/tests.rs`:
- Around line 435-511: Add a test alongside the existing workspace ignore tests
that places a .gitignore containing dist/ in the intermediate packages
directory, then creates the package under packages/pkg with package.json,
dist/generated.js, and src/index.js. Use packlist_with_options with
workspace_dir set to the workspace root and assert src/index.js is included
while dist/generated.js is excluded, verifying intermediate-directory ignore
files are applied.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e05bb49-5a5c-4cc6-93ac-00be7ecfc047

📥 Commits

Reviewing files that changed from the base of the PR and between 202f1cb and df26590.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (5)
  • .changeset/workspace-pack-gitignore.md
  • pnpm/crates/fs-packlist/src/lib.rs
  • pnpm/crates/fs-packlist/src/tests.rs
  • pnpm/crates/pack/src/lib.rs
  • pnpm/crates/pack/src/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/workspace-pack-gitignore.md

@qodo-code-review

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

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to abb45b4

Warning

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

CategorySuggestion                                                                                                                                    Impact
Possible issue
Canonicalize workspace containment checks

Use fs::canonicalize on paths before using strip_prefix to verify containment
and resolve ignore files.

pnpm/crates/fs-packlist/src/lib.rs [418-426]

 let Some(workspace_dir) = workspace_dir else { return Ok(()) };
-let Ok(rel) = pkg_dir.strip_prefix(workspace_dir) else { return Ok(()) };
+let Ok(workspace_dir) = fs::canonicalize(workspace_dir) else { return Ok(()) };
+let Ok(pkg_dir_canonical) = fs::canonicalize(pkg_dir) else { return Ok(()) };
+let Ok(rel) = pkg_dir_canonical.strip_prefix(&workspace_dir) else { return Ok(()) };
 if rel.as_os_str().is_empty() {
     return Ok(());
 }
-let Some(pkg_parent) = pkg_dir.parent() else { return Ok(()) };
-let Ok(parent_rel) = pkg_parent.strip_prefix(workspace_dir) else { return Ok(()) };
+let Some(pkg_parent) = pkg_dir_canonical.parent() else { return Ok(()) };
+let Ok(parent_rel) = pkg_parent.strip_prefix(&workspace_dir) else { return Ok(()) };
 
-let mut current = workspace_dir.to_path_buf();
+let mut current = workspace_dir;
  • Apply / Chat
Suggestion importance[1-10]: 3

__

Why: While using canonical paths prevents lexical containment bypasses, pnpm heavily relies on symlinks and often prefers logical paths (similar to Node's path.resolve), making canonicalization potentially disruptive to workspace setups.

Low
  • More

Previous suggestions

Suggestions up to commit df26590
CategorySuggestion                                                                                                                                    Impact
Possible issue
Preserve ancestor ignore path semantics

Build a separate workspace-rooted matcher for ancestor ignore files and use
filter_entry to apply it. This ensures workspace-relative paths in rules
correctly match package files.

pnpm/crates/fs-packlist/src/lib.rs [450-454]

-if let Some(ignore_file) = ignore_file
-    && let Some(error) = builder.add_ignore(&ignore_file)
-{
-    return Err(io_error(pkg_dir, into_io(error)));
+fn add_workspace_ignore_files(
+    builder: &mut WalkBuilder,
+    pkg_dir: &Path,
+    workspace_dir: Option<&Path>,
+) -> Result<(), PacklistError> {
+    let Some(workspace_dir) = workspace_dir else { return Ok(()) };
+    let Ok(rel) = pkg_dir.strip_prefix(workspace_dir) else { return Ok(()) };
+    if rel.as_os_str().is_empty() {
+        return Ok(());
+    }
+
+    let mut matcher = GitignoreBuilder::new(workspace_dir);
+    // Add each selected ancestor `.npmignore` or `.gitignore` to this
+    // workspace-rooted matcher, preserving its workspace-relative semantics.
+    ...
+    let matcher = matcher.build().map_err(|error| io_error(pkg_dir, into_io(error)))?;
+    builder.filter_entry(move |entry| {
+        !matcher
+            .matched_path_or_any_parents(entry.path(), entry.file_type().map(|kind| kind.is_dir()))
+            .is_ignore()
+    });
+    Ok(())
 }
Suggestion importance[1-10]: 9

__

Why: It fixes a significant logic bug where path-qualified or anchored rules in a workspace-root ignore file would incorrectly fail to match package files because WalkBuilder evaluates them relative to the package root.

High

Address review feedback on the workspace-aware packlist change:

- Add a parity test in both stacks proving a package-level `.npmignore`
  negation (`!dist/`) re-includes files the workspace-root `.gitignore`
  excluded. The Rust side adds workspace-root ignores at the lowest
  precedence tier (WalkBuilder::add_ignore), below the package's own
  discovered ignore files, so it matches npm-packlist's ancestor-first
  ordering rather than letting the workspace root win.
- Document why a non-Normal path component halts the ancestor ignore
  walk in add_workspace_ignore_files.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 13, 2026 14:29

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 merged commit b519489 into pnpm:main Jul 13, 2026
20 of 25 checks passed
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit abb45b4

@qodo-code-review qodo-code-review Bot mentioned this pull request Sep 1, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm pack does not respect gitignore at workspace root (unlike npm)

4 participants