Support creating patches with Yarn 2+ #506
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.