-
Notifications
You must be signed in to change notification settings - Fork 19
copy patches with pnpm #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add @esbuild-plugins/tsconfig-paths to handle ~/lib/* imports - Use createRequire to import CommonJS plugin in ESM context - Resolves build failures in CI environments where baseUrl context differs
| clean: true, | ||
| esbuildPlugins: [tsconfigPathsPlugin({})], | ||
| // shims: true, // replaces use of import.meta | ||
| /** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Building inside a pnpm install that has a newer version of esbuild. Esbuild struggles with the paths without the plugin to hoist in the paths from tsconfig.
|
I wish this feature would be released soon! |
There was a problem hiding this 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 adds support for copying pnpm patches to the isolated package folder when includePatchedDependencies is enabled. The implementation filters patches based on whether the target package has dependencies on the patched packages, respecting both production and dev dependency types.
Key changes:
- Introduces patch file copying logic that filters patches based on target package dependencies
- Updates lockfile generation to filter
patchedDependenciesin the same manner - Extends the
PackageManifesttype to include pnpm-specific fields
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tsup.config.ts | Adds esbuild plugin for TypeScript path resolution |
| src/lib/types.ts | Extends PackageManifest type to include pnpm.patchedDependencies field |
| src/lib/patches/copy-patches.ts | New module implementing patch file copying with dependency-based filtering |
| src/lib/lockfile/helpers/generate-pnpm-lockfile.ts | Adds filtering logic for patchedDependencies in lockfiles and PNPM 10+ support |
| src/isolate.ts | Integrates patch copying into the isolation workflow |
| package.json | Adds @esbuild-plugins/tsconfig-paths dev dependency |
| pnpm-lock.yaml | Updates lockfile with new dependency and consolidated debug version |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const getPackageName = (packageSpec: string): string => { | ||
| // Handle scoped packages: @scope/package@version -> @scope/package | ||
| if (packageSpec.startsWith("@")) { | ||
| const parts = packageSpec.split("@"); | ||
| return `@${parts[1]}`; | ||
| } | ||
| // Handle regular packages: package@version -> package | ||
| return packageSpec.split("@")[0]; | ||
| }; |
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getPackageName function is duplicated in src/lib/lockfile/helpers/generate-pnpm-lockfile.ts (lines 35-43). Extract this utility function to a shared location (e.g., src/lib/utils/get-package-name.ts) to avoid code duplication and ensure consistent behavior across both modules.
| import { pnpmMapImporter } from "./pnpm-map-importer"; | ||
|
|
||
| function filterPatchedDependencies( | ||
| originalPatchedDependencies: any, |
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The any type should be replaced with a more specific type. Consider using Record<string, string> or defining a proper type for patchedDependencies based on the pnpm specification.
| targetPackageManifest: PackageManifest, | ||
| includeDevDependencies: boolean, | ||
| log: Logger | ||
| ): any { |
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type any should be replaced with a more specific type such as Record<string, string> | undefined to improve type safety.
| return packageSpec.split("@")[0]; | ||
| }; | ||
|
|
||
| const filteredPatches: any = {}; |
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace any type with Record<string, string> or the appropriate type for patchedDependencies to improve type safety.
| export async function copyPatches({ | ||
| workspaceRootDir, | ||
| targetPackageManifest, | ||
| isolateDir, | ||
| includePatchedDependencies, | ||
| includeDevDependencies, | ||
| }: { | ||
| workspaceRootDir: string; | ||
| targetPackageManifest: PackageManifest; | ||
| isolateDir: string; | ||
| includePatchedDependencies: boolean; | ||
| includeDevDependencies: boolean; | ||
| }): Promise<Record<string, string>> { |
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new copyPatches function lacks test coverage. Consider adding tests to verify: (1) correct filtering of patches based on dependency types, (2) handling of scoped vs non-scoped packages, (3) behavior when includePatchedDependencies is false, (4) error handling when workspace root package.json cannot be read, and (5) proper file copying to the isolate directory.
| function filterPatchedDependencies( | ||
| originalPatchedDependencies: any, | ||
| targetPackageManifest: PackageManifest, | ||
| includeDevDependencies: boolean, | ||
| log: Logger | ||
| ): any { |
Copilot
AI
Nov 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new filterPatchedDependencies function lacks test coverage. Consider adding tests to verify the filtering logic for production dependencies, dev dependencies, and packages not found in target dependencies.
|
@kevpie @jieey1140 I have upgraded to more modern tooling and moved away from tsup, and there were a few things in here that I didn't want to merge as-is, so I found it easier to let Opus create a new PR based on this. Please review #145 and see if I missed anything. I don't have projects where I need this, and I don't have proper tests for this, so please try out the prerelease 1.27.0-0 under tag "next" and let me know if it works for you. Also, I wonder about the setting needed to enable this behavior. Don't you think we can assume that if you define patched dependencies in your manifest file, that you'd always want to copy them? |
|
Closed in favor of #145 |
|
Thank you @0x80! I'll try out the new PR soon using |
|
@kevpie @jieey1140 Cursor and Copilot came with a lot of seemingly good suggestions and I adopted them, but it was a bit of a snowball effect, and I don't have time to go over things carefully. I've created a new version 1.27.0-1 with all the changes that are listed in the PR description under subsequent changes. I hope it still works with all of that 🤞 |
|
Ok it seems AI was a bit silly flattening the copied patches and then attempting to avoid the naming collisions that could be caused by that. I will revert that and preserve the original folder structure of the patches. So 1.27.0-2 coming up... |
Copies the relevant patches to the isolate folder along with package.json section.
Probably a better way to do this.
For now I force firebase-tools-with-isolate to provide the right config using a patch like this.