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

patch-package should support patching itself in postinstall script #203

Open
pdcastro opened this issue Feb 10, 2020 · 5 comments
Open

patch-package should support patching itself in postinstall script #203

pdcastro opened this issue Feb 10, 2020 · 5 comments

Comments

@pdcastro
Copy link

patch-package is great, so much so that I recently found myself attempting to use it to patch patch-package itself as I came across issue #201. It didn't work, at least in my setup, using "postinstall": "patch-package" in the package.json file. What I think was happening is that by the time patch-package had patched itself, it was too late -- the old unpatched code was already being used to patch other packages.

Perhaps the solution might be for patch-package to detect if one of the patch files is for patch-package itself, and if so, apply that patch first, then re-exec itself before continuing with other patches. (When re-exec'ing, perhaps add a command-line option like --no-self-patch to prevent patching itself in a loop.) :-)

@mikehardy
Copy link
Contributor

I am about to do similar (attempt to patch patch-package) and I think this is achievable as-is by modifying your postinstall

Specifically,

  1. make a new patch directory called patch-package-patches
  2. in package.json::postinstall don't just call patch-package, call patch-package --patch-dir patch-package-patches && patch-package

That way your patch-package patches should go in, and should go first, then it will do it's normal run.

Should work?

@pdcastro
Copy link
Author

@mikehardy, great suggestion! I wasn't aware of the --patch-dir option: it is not documented by npx patch-package --help, but indeed it is in the source code. I've successfully "solved" issue #201 in my project thanks to your tip. 👍

@mikehardy
Copy link
Contributor

@pdcastro quick! Propose a PR for the help doc and claim the internet points 🏆 before someone else does 😄 https://github.com/ds300/patch-package/blob/master/src/index.ts#L104

@pdcastro
Copy link
Author

Propose a PR for the help doc and claim the internet points 🏆

@mikehardy, I think you have a rightful claim for those points, 😄 and I am already collecting lots elsewhere at the moment! 💰

@mikehardy
Copy link
Contributor

Mine all mine, precious internet points #225
Cheers :-)

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

2 participants