Skip to content

[rush] Fix "rush-pnpm patch-commit" writing absolute paths into pnpm-config.json#5875

Merged
iclanton merged 1 commit into
microsoft:mainfrom
ATKasem:fix/rush-pnpm-patch-absolute-paths
Jul 18, 2026
Merged

[rush] Fix "rush-pnpm patch-commit" writing absolute paths into pnpm-config.json#5875
iclanton merged 1 commit into
microsoft:mainfrom
ATKasem:fix/rush-pnpm-patch-absolute-paths

Conversation

@ATKasem

@ATKasem ATKasem commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #5348

When a repo already has entries in globalPatchedDependencies and another patch is added with rush-pnpm patch-commit, the pre-existing entries get rewritten in pnpm-config.json as absolute paths (e.g. /home/user/repo/common/temp/patches/foo@1.0.0.patch), leaking the local checkout location into a committed config file.

The cause is on the pnpm side: pnpm >= 9 rewrites the pre-existing patchedDependencies entries in the workspace package.json using absolute paths when running patch-commit / patch-remove (reproduced in isolation with pnpm 10.7.1 — the new entry is written relative, the old ones become absolute). rush-pnpm then copied that map verbatim from common/temp/<subspace>/package.json into pnpm-config.json.

Details

RushPnpmCommandLineParser now normalizes the map read back from the temp package.json before persisting: any value that is an absolute path under the subspace temp folder is converted back to a temp-relative POSIX path (patches/example@1.0.0.patch). Relative values and absolute paths outside the temp folder are left unchanged. The normalization happens before the deep-equal comparison, so entries that only differ by pnpm's absolutization no longer register as changes.

How it was tested

  • Unit tests added to RushPnpmCommandLineParser.test.ts (absolute-under-temp conversion, relative passthrough, absolute-outside-temp passthrough, undefined passthrough); heft test passes 7/7 for the suite.
  • rush build --to @microsoft/rush-lib (tsc + lint) passes.
  • Full rush-lib test run: 684 passing; the 7 failures in RushPluginCommandLineParameters.test.ts reproduce identically on an unmodified main checkout in this environment, so they are unrelated to this change.

Comment thread libraries/rush-lib/src/cli/RushPnpmCommandLineParser.ts Outdated
@ATKasem
ATKasem force-pushed the fix/rush-pnpm-patch-absolute-paths branch 2 times, most recently from 705af95 to 3a8b6d1 Compare July 17, 2026 19:37
…config.json

When running "pnpm patch-commit"/"patch-remove" with pnpm 9+, pnpm
rewrites pre-existing patchedDependencies entries using absolute paths
into common/temp. Rush then copied those into pnpm-config.json, leaking
the local checkout location.

Normalize absolute paths under the common/temp folder back to relative
paths at the point they are recorded, inside
PnpmOptionsConfiguration.updateGlobalPatchedDependencies. This is the
single sink for both the pnpm 11+ (pnpm-workspace.yaml) and older
(package.json) sources, so both are covered.
@ATKasem
ATKasem force-pushed the fix/rush-pnpm-patch-absolute-paths branch from 3a8b6d1 to 1193824 Compare July 17, 2026 19:43
Comment thread libraries/rush-lib/src/logic/pnpm/PnpmOptionsConfiguration.ts
@iclanton
iclanton merged commit ab92302 into microsoft:main Jul 18, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Needs triage to Closed in Bug Triage Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

[rush] rush-pnpm patch puts absolute paths into pnpm-config.json

2 participants