-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
support patching dependencies, similar to pnpm patch
/patch-package
#2336
Comments
Hello @josefaidt - Can you have some time to make this issue progress? Thank 😆 |
Alternatively, if it's easier to add support for using patch-package, that would go a long way too. |
Attempting to create a patch using Copy code
**ERROR** No package-lock.json, npm-shrinkwrap.json, or yarn.lock file.
You must use either npm@>=5, yarn, or npm-shrinkwrap to manage this project's
dependencies. However, if you have pre-existing patches in the As a temporary workaround to generate a
I found a new workaround:
|
It would be nice to see this to facilitate angular/angular#46719 |
Any plans to implement this? @Jarred-Sumner |
this works with one minor tweak: |
+1 pnpm patch is no nice to have and definetely a blocking feature before adopting bun in some of my repos |
This wont work though for platforms like vercel that determines the package manager by which lockfile you have in the repo, so if you have a |
I'm very certain you only need the |
I got bun install --yarn You can now use bunx patch-package moti |
It works, my production repos are using it. Moreover, vercel already supports bun for building. |
Instead of adding a
This command can be used
|
we probably will do we've looked into adding it but are unhappy with the performance of various diff/patch libraries |
seem |
please don't worry about performance for the first version (of course unless it is unreasonably slow). a good enough is better than not having this feature at all |
+1 for having some kind of solution even if its performance is not on par with rest of the project. |
I followed your steps but I'm getting the following error. bunx patch-package drizzle-kit
patch-package 8.0.0
• Creating temporary folder
• Installing [email protected] with yarn
21 | function spawnSync(command, args, options) {
22 | // Parse the arguments
23 | const parsed = parse(command, args, options);
24 |
25 | // Spawn the child process
26 | const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
^
TypeError: Executable not found in $PATH: "yarn"
code: "ERR_INVALID_ARG_TYPE"
at node:child_process:173:47
at spawnSync (/private/tmp/patch-package@latest--bunx/node_modules/cross-spawn/index.js:26:20)
at spawnSafeSync (/private/tmp/patch-package@latest--bunx/node_modules/patch-package/dist/spawnSafe.js:11:20)
at makePatch (/private/tmp/patch-package@latest--bunx/node_modules/patch-package/dist/makePatch.js:131:17)
at /private/tmp/patch-package@latest--bunx/node_modules/patch-package/dist/index.js:72:13
at forEach (:1:21)
at /private/tmp/patch-package@latest--bunx/node_modules/patch-package/dist/index.js:71:9
at /private/tmp/patch-package@latest--bunx/node_modules/patch-package/index.js:3:1
21 | function spawnSync(command, args, options) {
22 | // Parse the arguments
23 | const parsed = parse(command, args, options);
24 |
25 | // Spawn the child process
26 | const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
^
TypeError: Executable not found in $PATH: "yarn"
code: "ERR_INVALID_ARG_TYPE"
at node:child_process:173:47
at spawnSync (/private/tmp/patch-package@latest--bunx/node_modules/cross-spawn/index.js:26:20)
at spawnSafeSync (/private/tmp/patch-package@latest--bunx/node_modules/patch-package/dist/spawnSafe.js:11:20)
at makePatch (/private/tmp/patch-package@latest--bunx/node_modules/patch-package/dist/makePatch.js:131:17)
at /private/tmp/patch-package@latest--bunx/node_modules/patch-package/dist/index.js:72:13
at forEach (:1:21)
at /private/tmp/patch-package@latest--bunx/node_modules/patch-package/dist/index.js:71:9
at /private/tmp/patch-package@latest--bunx/node_modules/patch-package/index.js:3:1 Is installing |
In the meantime, I just slapped together some naive implementation of a patcher (just copies packages by name from https://github.com/corysimmons/patcheer It seems to work well for my needs and should be as fast as |
Why can't we just edit the code in |
@resthedev I can't speak for |
I see. Do you mean you put |
Yes, it should recognize it based on there only being a |
I was migrating to Bun and realized I wouldn't be able to use |
@gustavopch I provide a workaround a couple of comments above yours.
This should work locally and in any hosting env that supports Bun (i.e. it's working on Vercel for me). Ping me if something doesn't work.
|
@corysimmons |
@Jarred-Sumner some workaround in the meantime? |
@AngeloCloudAcademy you can try this with |
i'm doing this in the meantime
this works, also adding |
After numerous amount of experiments, I found that patching StepsConfigure bun to generate yarn lockfileSpecify a [install.lockfile]
print = "yarn" # Whether to generate a non-Bun lockfile alongside bun.lockb Warning I personally recommend the later one since you need to generate the yarn v1 lockfile every time you update dependencies. Install
|
I would also like to add that it would be awesome to support something like Yarn does with resolutions:
{
"resolutions": {
"some-library:1.2.3": "patch:patch-file",
"other-library:1.0.0": "http://alternate-source/file.tgz",
"final-library:100.0.0": "./dir/final-library-fork"
}
} This support pretty much every use case:
|
To make it work with Private registriesI followed the steps by @ReoHakase and it worked for public packages. But to make it work with our private registry I had to do the following changes: diff --git a/node_modules/patch-package/dist/makePatch.js b/node_modules/patch-package/dist/makePatch.js
index d8d0925..7c488cd 100644
--- a/node_modules/patch-package/dist/makePatch.js
+++ b/node_modules/patch-package/dist/makePatch.js
@@ -109,18 +109,18 @@ function makePatch({ packagePathSpecifier, appPath, packageManager, includePaths
resolutions: resolveRelativeFileDependencies_1.resolveRelativeFileDependencies(appPath, appPackageJson.resolutions || {}),
}));
const packageVersion = getPackageVersion_1.getPackageVersion(path_1.join(path_1.resolve(packageDetails.path), "package.json"));
- [".npmrc", ".yarnrc", ".yarn"].forEach((rcFile) => {
+ [".npmrc", ".yarnrc", ".yarn", "bunfig.toml", ".env"].forEach((rcFile) => {
const rcPath = path_1.join(appPath, rcFile);
if (fs_extra_1.existsSync(rcPath)) {
fs_extra_1.copySync(rcPath, path_1.join(tmpRepo.name, rcFile), { dereference: true });
}
});
if (packageManager === "yarn") {
- console_1.default.info(chalk_1.default.grey("•"), `Installing ${packageDetails.name}@${packageVersion} with yarn`);
+ console_1.default.info(chalk_1.default.grey("•"), `Installing ${packageDetails.name}@${packageVersion} with bun`);
try {
// try first without ignoring scripts in case they are required
// this works in 99.99% of cases
- spawnSafe_1.spawnSafeSync(`yarn`, ["install", "--ignore-engines"], {
+ spawnSafe_1.spawnSafeSync(`bun`, ["install"], {
cwd: tmpRepoNpmRoot,
logStdErrOnError: false,
});
@@ -128,7 +128,7 @@ function makePatch({ packagePathSpecifier, appPath, packageManager, includePaths
catch (e) {
// try again while ignoring scripts in case the script depends on
// an implicit context which we haven't reproduced
- spawnSafe_1.spawnSafeSync(`yarn`, ["install", "--ignore-engines", "--ignore-scripts"], {
+ spawnSafe_1.spawnSafeSync(`bun`, ["install", "--ignore-scripts"], {
cwd: tmpRepoNpmRoot,
});
} I had to specify To Summarize:
[install.lockfile]
print = "yarn" # Whether to generate a non-Bun lockfile alongside bun.lockb
bun add -D patch-package
bun patch-package patch-package
{
"name": "reoiam-dev",
"version": "0.0.0",
"workspaces": [
"apps/*",
"packages/*"
],
"scripts": {
"postinstall": "patch-package",
}
bun install --force
|
For those tracking this issue, I am currently working on this. Patching a package will behave similarly to pnpm, through the Yarn's patch protocol will also be supported. My work-in-progress PR for this feature is here. |
The merged implementation of |
Fixed by @zackradisic in #11858 |
@Scalahansolo |
Still doesn't work in our monorepo on 1.1.16 cc @zackradisic |
@Scalahansolo can you file an issue and @zackradisic will fix it? |
Is there a way to prepare multiple packages for patching at once? |
What is the problem this feature would solve?
I am currently working with a few dependencies that will cause errors at runtime due to their imports, and I'd also like to apply general changes without suggesting changes to the projects.
Today I'm using
pnpm
to manage dependencies andbun
to run the project, which is fine for the most part. Unfortunatelypatch-package
will not work as it is looking for npm & yarn lockfiles.What is the feature you are proposing to solve the problem?
bun patch
pnpm patch
bun patch <dependency-name>
allows the developer to modify dependenciesbun patch --apply <dependency-name>
applies the patch/private/var/folders
and requires the developer to pass the full directory path when applying a patch withpnpm patch-commit <directory-path>
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: