Skip to content

Conversation

@0x80
Copy link
Owner

@0x80 0x80 commented Nov 27, 2025

When includePatchedDependencies is enabled, copy relevant patch files from the workspace root to the isolated directory and update the isolated package.json with patch references.

Patches are filtered based on the target package's dependencies:

  • Production dependency patches are always included
  • Dev dependency patches are included only when includeDevDependencies is true
  • Patches for packages not in the target's dependencies are excluded

The lockfile generator also filters patchedDependencies to match only relevant packages.

Based on #142 but adapted for the updated tooling (tsdown instead of tsup).


Subsequent improvements

After the initial implementation, several refinements were made to improve code quality, fix bugs, and ensure correctness:

Code organization

  • Extracted shared utilities - The getPackageName function (which parses package specs like @firebase/[email protected] into package names) was duplicated between copy-patches.ts and filter-patched-dependencies.ts. Extracted to src/lib/utils/get-package-name.ts.

  • Extracted filtering logic - The patch filtering logic was also duplicated. Extracted to src/lib/utils/filter-patched-dependencies.ts as a generic utility that works with any value type via TypeScript generics.

  • Preserved folder structure - Patch files are copied preserving their original directory structure rather than flattening to a single patches/ directory.

Bug fixes

  • Manifest consistency - The filtering was using the original targetPackageManifest instead of the adapted outputManifest. This could cause issues since the output manifest may have different dependency references. Fixed to use outputManifest for filtering.

  • Lockfile patch paths - The lockfile was being generated before patches were copied, causing a mismatch between the paths in the lockfile and the actual copied files. Fixed by:

    1. Reordering operations so copyPatches runs before processLockfile
    2. Having copyPatches return the full PatchFile format (with path and hash)
    3. Reading hashes from the original lockfile so they're preserved after copying
    4. Passing pre-computed patched dependencies to the lockfile generator

Test coverage

Added comprehensive unit tests for the new utilities:

  • get-package-name.test.ts - 14 tests covering scoped packages, edge cases, and malformed input
  • filter-patched-dependencies.test.ts - 11 tests for filtering logic with various dependency configurations
  • copy-patches.test.ts - 10 tests for the patch copying functionality

Type safety

  • Defined a local PatchFile interface ({ path: string; hash: string }) matching the pnpm lockfile format, since the installed @pnpm/types version doesn't export this type
  • Used TypeScript generics in filterPatchedDependencies<T> to preserve the value type through filtering operations

When includePatchedDependencies is enabled, copy relevant patch files
from the workspace root to the isolated directory and update the
isolated package.json with patch references.

Patches are filtered based on the target package's dependencies,
respecting the includeDevDependencies configuration option.
Copilot AI review requested due to automatic review settings November 27, 2025 20:11
Copilot finished reviewing on behalf of 0x80 November 27, 2025 20:16
Copy link

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

This PR implements support for copying PNPM patch files to isolated package directories when the includePatchedDependencies configuration option is enabled. The implementation filters patches based on the target package's dependencies, ensuring only relevant patches are copied and referenced in both the isolated package.json and lockfile.

Key Changes

  • Added patchedDependencies field to the PackageManifest type definition to support PNPM patch configuration
  • Implemented patch file copying with dependency-based filtering that respects production and dev dependency boundaries
  • Updated lockfile generation to filter patchedDependencies entries to match only packages present in the isolated environment

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/lib/types.ts Extended PackageManifest type with optional pnpm.patchedDependencies field
src/lib/patches/copy-patches.ts New module implementing patch file copying with filtering logic based on target dependencies
src/lib/lockfile/helpers/generate-pnpm-lockfile.ts Added patch filtering for lockfile generation, replacing previous comment about incomplete implementation
src/isolate.ts Integrated patch copying into isolation workflow and updated isolated manifest with patch references

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

@0x80 0x80 mentioned this pull request Nov 27, 2025
Copilot AI review requested due to automatic review settings November 27, 2025 20:45
Copilot finished reviewing on behalf of 0x80 November 27, 2025 20:49
Copy link

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 9 out of 9 changed files in this pull request and generated 4 comments.


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

Copilot AI review requested due to automatic review settings November 27, 2025 20:53
Copilot finished reviewing on behalf of 0x80 November 27, 2025 20:56
Copy link

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 13 out of 13 changed files in this pull request and generated 1 comment.


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

0x80 added 3 commits November 27, 2025 22:02
- Use getIsolateRelativeLogPath for patches directory logging
- Add getIsolateRelativeLogPath to test mocks
- Format CLAUDE.md code style section
The lockfile was being generated before patches were copied, causing
paths in the lockfile to not match the actual copied files.

Changes:
- Reorder operations so copyPatches runs before processLockfile
- Update copyPatches to return PatchFile format with path and hash
- Read hashes from original lockfile to preserve them after copying
- Pass pre-computed patched dependencies to lockfile generator
- Add PatchFile interface to types.ts
- Update tests to expect PatchFile format
Copilot AI review requested due to automatic review settings November 27, 2025 21:21
Copilot finished reviewing on behalf of 0x80 November 27, 2025 21:25
Copy link

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 14 out of 14 changed files in this pull request and generated 2 comments.


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

Copilot AI review requested due to automatic review settings November 27, 2025 21:28
Copilot finished reviewing on behalf of 0x80 November 27, 2025 21:31
Copy link

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 14 out of 14 changed files in this pull request and generated 1 comment.


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

0x80 added 2 commits November 27, 2025 22:39
Patches are now automatically copied if they exist in the workspace.
There's no need for an explicit opt-in setting.
Copilot AI review requested due to automatic review settings November 27, 2025 21:44
Copilot finished reviewing on behalf of 0x80 November 27, 2025 21:46
Copy link

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 15 out of 15 changed files in this pull request and generated no new comments.


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

0x80 added 2 commits November 27, 2025 22:50
Instead of flattening all patches to patches/ with collision avoidance,
preserve the original directory structure when copying patch files.

This eliminates unnecessary complexity:
- Remove collision detection and filename renaming logic
- Paths in patchedDependencies remain unchanged from workspace root
- Simpler code, no edge cases for naming conflicts
Patched dependencies are a pnpm-specific feature. Skip copying patches
when forceNpm is enabled or when the detected package manager is not pnpm.
Copilot AI review requested due to automatic review settings November 27, 2025 21:56
Copilot finished reviewing on behalf of 0x80 November 27, 2025 21:59
Copy link

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 16 out of 16 changed files in this pull request and generated 1 comment.


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

Copilot AI review requested due to automatic review settings November 28, 2025 10:12
Copilot finished reviewing on behalf of 0x80 November 28, 2025 10:15
Copy link

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 16 out of 16 changed files in this pull request and generated no new comments.


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

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.

2 participants