Skip to content
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

[Question] patch on published module #198

Closed
gigaga opened this issue Jan 28, 2020 · 3 comments
Closed

[Question] patch on published module #198

gigaga opened this issue Jan 28, 2020 · 3 comments

Comments

@gigaga
Copy link

gigaga commented Jan 28, 2020

Hello,

currently I have a module project (named great-module) where the code is organized like that:

/node_modules/sub-module
/patches
package.json

From this repo, the postinstall script is correctly executed and the patch is applied to sub-module module.

After publishing my module (npm publish) I want to use it from another project (npm install geat-module).
But after install process, I have the following error message : Error: Patch file found for package sub-module which is not present at node_modules/sub-module

Indeed, after this installation, the code of this project is organized like that:

/node_modules/great-module/patches
/node_modules/sub-module
package.json

patch-package tries to use sub-module from /node_modules/great-module/node_modules/sub-module and not from /node_modules/sub-module.

What is the way to apply patches in published module?

Thanks a lot :)

@ds300
Copy link
Owner

ds300 commented Jan 28, 2020

Sorry, patch-package doesn't support publishing libraries. This has been asked before a number of times but it's not safe and therefore not something i want to encourage. If you really want to do this for some reason I'm gonna leave it up to you to figure out how to write a postinstall script that would work ;)

@ds300 ds300 closed this as completed Jan 28, 2020
@gunzip
Copy link

gunzip commented Apr 6, 2020

may you please elaborate more on "patch-package doesn't support publishing libraries" what do you mean exactly ? is this exposed by the readme / docs ?

I'm wondering if using prepare hook instead of postinstall would solve the issue. Do you see any drawback in using prepare ?

gwn added a commit to ixofoundation/ixo-client-sdk that referenced this issue Feb 16, 2021
We found out that we may not rely on patch-package in a library,
as it is intended to work exclusively in top level projects and
not recommended to be used in a library. References:

- ds300/patch-package#198
- ds300/patch-package#26

For that reason we had to create a new repository containing the
patched version of the Launchpad package's latest build. We
patched the build instead of forking the whole package and
patching the source for practical reasons, please see the package
README if you're curious about those reasons.
@0es
Copy link

0es commented Jul 5, 2021

A simple solution

"postinstall": "cd $INIT_CWD && $(npm bin)/patch-package --patch-dir YOUR_PATCH_PATH"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants