-
-
Notifications
You must be signed in to change notification settings - Fork 297
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 creating patches with Yarn 2+ #506
base: master
Are you sure you want to change the base?
Conversation
const yarnVersionCmd = spawnSafeSync(`yarn`, ["--version"], { | ||
cwd: tmpRepoNpmRoot, | ||
logStdErrOnError: false, | ||
}) |
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.
Is there a more elegant way to interrogate the currently version of yarn?
@@ -332,7 +345,6 @@ export function makePatch({ | |||
) | |||
} | |||
process.exit(1) | |||
return |
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.
These returns are dead code, as process.exit
ends the process immediately and does not return
After using this patch in our internal CI, I believe this PR is quite unfinished, I'll create a new PR based yours. For example, "@backstage/integration@npm:^1.5.0, @backstage/integration@npm:^1.7.0, @backstage/integration@npm:^1.7.2":
version: 1.7.2
resolution: "@backstage/integration@npm:1.7.2" |
Attempting to create new patch files with
patch-package
within a yarn 2+ project currently doesn't work. This has a few small changes to fixes all of them and support modern versions of yarn. Fixes: #496 #272But first, why bother? Yarn 2 and up has its own built-in option for patching dependencies, so projects using it don't need
patch-package
anymore, right? On the contrary,patch-package
not only has a much better overall user experience, but with the addition of support multiple patch files per package in v8.0.0,patch-package
is a far more attractive solution for my needs. In particular, in one project there's a single critical dependency that I have made extensive customizations to over several years, and it's always a big effort to maintain those changes when they are combined into a single patch file. Yes, it's still technically possible to use yarn's native patch system to progressively layer patch files onto a single dependency, but it's a bit nightmarish. I would much prefer to continue usingpatch-package
than jump through those types of hoops.Now, for the issues I had to resolve to get
patch-package
with yarn 3 working:--ignore-engines
option is not supported--ignore-engines
because support for that option is removed--ignore-engines
if yarn version starts with1.
makePatch.ts
copies over any.yarnrc
file it finds, but we use a.yarnrc.yml
file.yarnrc.yml
files into the tmp directorymakePatch.ts
copies over the entire.yarn
directory which includes a very large project-specific package cache, a state file for the current project's node modules, etc.yarn
directory:.yarn/releases
which contains the currently installed version of yarn, and.yarn/plugins
which contains any additional plugins (in our case the workspace tools plugin was required)Finally, one additional "fix" that's not quite so objective is included. The error messaging produced by
patch-package
in the above failure cases was extremely hard to interpret, and doesn't include any sort of stack trace to help identify where the error is even coming from:In an attempt to at least get a useful stack trace on screen in error cases of this class, I've edited
spanSafe.ts
to create a new error object and attach it to the thrown object which provides a clear stack trace to the likely source of issues and it appears as one of the last things printed before the process exits:I haven't familiarized myself enough with the integration test setup in this project to build this PR out into something that I would consider ready to merge, but I think it should be a good starting point. And, hopefully my intro above is a convincing case for why modern yarn versions are still worth supporting in this package.