Skip to content

Filter patchedDependencies in isolated pnpm-workspace.yaml#180

Merged
0x80 merged 4 commits intomainfrom
thijs/0429-fix-patched-deps-handling
Apr 30, 2026
Merged

Filter patchedDependencies in isolated pnpm-workspace.yaml#180
0x80 merged 4 commits intomainfrom
thijs/0429-fix-patched-deps-handling

Conversation

@0x80
Copy link
Copy Markdown
Owner

@0x80 0x80 commented Apr 30, 2026

Fixes #178.

When a pnpm workspace declares patchedDependencies for packages that aren't reachable from the target, copyPatches correctly skips those patch files but the workspace config was still copied verbatim. The resulting isolate referenced patch files that didn't exist on disk, so pnpm install (e.g. during a Firebase Functions deploy) failed.

pnpm-workspace.yaml is now parsed when written into the isolate, and its patchedDependencies field is rewritten to only contain the entries that were actually copied. The field is removed entirely when no patches apply. If the file has no patchedDependencies field or fails to parse, it falls back to a verbatim copy as before. The lockfile and target manifest were already filtered, so this brings the workspace config in line.

Scope: cli (patches)
Visibility: user-facing

When pnpm-workspace.yaml was copied verbatim into the isolate, its
patchedDependencies field still referenced every workspace patch even
when copyPatches had only copied the subset relevant to the target
package. pnpm install then failed on missing patch files. The yaml is
now read, the patchedDependencies field is rewritten to only contain
entries actually copied (and removed entirely if none remain), and
written back. Falls back to a verbatim copy when the yaml has no
patchedDependencies or cannot be parsed.
Copilot AI review requested due to automatic review settings April 30, 2026 06:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates PNPM isolate output to avoid broken patchedDependencies references in pnpm-workspace.yaml when patch files are excluded from the isolate (fixing #178), keeping workspace config consistent with already-filtered lockfile/manifest behavior.

Changes:

  • Add writeIsolatePnpmWorkspace to copy pnpm-workspace.yaml while rewriting/removing patchedDependencies to match the patches actually copied.
  • Replace the direct pnpm-workspace.yaml copy in src/isolate.ts with the new filtered writer.
  • Add Vitest coverage for the new workspace writer behavior and fallback paths.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/lib/patches/write-isolate-pnpm-workspace.ts Implements filtered writing of pnpm-workspace.yaml based on copiedPatches, with fallback to verbatim copy.
src/lib/patches/write-isolate-pnpm-workspace.test.ts Adds unit tests validating filtering, field removal, and verbatim-copy fallback behavior.
src/isolate.ts Switches PNPM workspace config handling to use the new filtered writer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib/patches/write-isolate-pnpm-workspace.ts Outdated
When every patchedDependencies entry in the source pnpm-workspace.yaml
is also present in copiedPatches, copy the file verbatim instead of
parsing and rewriting it. This preserves comments, key ordering, and
trailing whitespace for the common case where all workspace patches
apply to the target. The read-modify-write path still runs whenever any
patch is excluded.
Copilot AI review requested due to automatic review settings April 30, 2026 07:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib/patches/write-isolate-pnpm-workspace.ts Outdated
@ChromeQ
Copy link
Copy Markdown

ChromeQ commented Apr 30, 2026

If the file has no patchedDependencies field or fails to parse, it falls back to a verbatim copy as before

Do you think it is worth the "fallback to verbatim copy" if all the patches are included?

This is my thought matrix: (Claude can confirm if these cases are met):

  1. There are no patchedDeps - verbatim copy
  2. There are patchedDeps and all are copied - verbatim copy
  3. There are patchedDeps and some are copied - rewrite file
  4. There are patchedDeps and none are copied - rewrite file without section
  5. Failed to parse - verbatim copy (you have bigger problems)

@0x80
Copy link
Copy Markdown
Owner Author

0x80 commented Apr 30, 2026

Yes, all five cases are covered exactly as you describe — confirmed against src/lib/patches/write-isolate-pnpm-workspace.ts:

  1. No patchedDeps — verbatim copy via fs.copyFileSync (the !settings.patchedDependencies branch).
  2. All patches copied — verbatim copy. Computed as hasExclusions = sourceSpecs.some((spec) => !copiedSpecs.has(spec)); when false, fs.copyFileSync is used so comments/order are preserved.
  3. Some patches copied — rewrites patchedDependencies to only the copied entries via writeTypedYamlSync.
  4. No patches copied (but section existed)delete settings.patchedDependencies then writeTypedYamlSync, so the field is dropped from the rewritten yaml.
  5. Failed to read/parse — caught by the try/catch around readTypedYamlSync, logged at warn level, falls back to fs.copyFileSync.

Each path also has a dedicated unit test in write-isolate-pnpm-workspace.test.ts.

@ChromeQ
Copy link
Copy Markdown

ChromeQ commented Apr 30, 2026

Yep all good then, ship it 🚀

@0x80 0x80 merged commit f2075b3 into main Apr 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm patchedDependencies bug with excluded patch files

3 participants