-
-
Notifications
You must be signed in to change notification settings - Fork 299
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 for Yarn workspaces/monorepos #42
Comments
Hi! Sorry it took me so long to respond to this.
Not that I know of.
The alternative, however, would be prone to conflicts. imagine if you had sub-projects A and B, then A decides to patch I think in order for this to work in a way that allows independent patches for the same package version, yarn would need to either be aware of the patch files, or make module resolution (or, specifically, the conflict detection part of module resolution) pluggable. Then it could install separate versions in sub-projects' own node_modules directory. Otherwise, patch-package should be able to include support for workspaces where this kind of conflict is prohibited. I'm happy to provide guidance for anyone who is willing to work on it. I probably won't get around to it myself any time soon, although I certainly recognise the need for the feature. Thanks for binging this up! |
Ok, that makes sense, thanks for getting back on it! I appreciate the amount of effort it would take to solve (if at all possible), and that's not really needed because the workaround is more reliable and simple to set up at the moment (I have now been using it for a week without issues). The one case this might be simple is when each sub-project depends on its own version of a package, in which case they'd be both installed in the sub-project directories instead of the root one (but then again, this likely works already, I just haven't tested it). Feel free to keep this issue open for others to weigh in, or close it if you prefer. Thanks again! |
@ds300 would it be an option if we add the version of the npm package to the patch file so if multiple versions are found it can still find the the correct package but only if there are multiple packages found. If patch-package can not resolve to a correct version it just throws an error? Could this be a good approach? |
I am having trouble to create patches when using yarn workspaces. From the "parent" folder I execute for instance
If I manually generate the patch and put it in the patches folder, it correctly applies later on Is it working for you guys? Thanks! |
@vieira it cannot be applied from the parent folder if its |
I'm getting a similar issue running from parent folder.
It's not recognizing that |
it doesn't support it yet. |
@ds300 would you provide some pointers on how someone might be able to work on a patch for this particular issue? |
Sure! There are two workflows that need to be changed: Creating patches (makePatch.ts), and applying patches (applyPatches.ts).
If you need any more detail on code specifics, let me know. I'd recommend branching off of #45 for now. I'm probably going to merge that into master soon and make smaller PRs for the bits that remain to get to a 6.0 release. Might take a few weeks, and would be super happy to help get this feature in too. |
ooh, another thing is that patches should always be kept at the same level as the node_modules folder which contains the code that they'll be patching. So for a monorepo it might be like this:
I might even consider changing |
Currently, the only way to make patching work with Yarn seems to be to keep all patches under the root On top of that, I can only create patches with Finally, I install With these workarounds, everything else works nicely on |
@ds300 I'll take a stab at this. I can test this on a few repos |
I was also having trouble generating the patch on a yarn workspace, getting the error Here's my current workaround:
This way the patch will be successfully created. I didn't face issues applying the patch. |
FYI: you don't really need to do |
I'm having issues due to the package not being hoisted (using |
Btw, for those still having issues it may help to:
I was consistently having trouble with (4) until I did (1). |
As of version 6.1.0 patch-package now works with yarn workspaces 🎉 The setup instructions are exactly the same, but you might need to set it up for sub packages in addition to the repo root package if you want to patch node_modules which were not hoisted. |
Hey, I have a yarn workspaces where I have set Here is the console error:
|
First of all, thanks for the awesome work on this package!
I've started exploring the new "workspaces"/"monorepos" feature of Yarn (https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/), which enables "hoisting" of all
node_modules
from any sub-projects to a single parent repository (so that if you have sub-folders with individualpackage.json
s, each one would install its deps in the "parent"node_modules
and link them, unless there are version conflicts).However,
patch-package
no longer automatically applies patches to sub-project packages in its default configuration (i.e. when I runyarn
in the parent folder, it only appliespatches/
from the "parent" folder). I had to move all patches from sub-projects into the "parent"patches/
to make it work, however that sort of "pollutes" the "global" patch space with patches from sub-projects.Are you familiar with this feature, and are there any other (better) solutions to enable automatic patching of sub-projects (I know it's a lot to ask, was just hoping to hear your thoughts)?
Thanks again!
The text was updated successfully, but these errors were encountered: