Use prepare instead of postinstall for patch-package - #4
Open
warudin wants to merge 1 commit into
Open
Conversation
postinstall also runs in the install context of every consumer of the published package, where it can never succeed: patch-package is a devDependency (npm does not install those for consumers) and patches/ is not in the files array, so there is nothing to apply. Consumers therefore either see the hook fail or have to add patch-package to their own dependencies to make a no-op exit cleanly. prepare runs on a bare `npm install` in this repo and before publish, so the html-to-image patch is still applied for local development and for the bundled build, but it no longer runs for registry installs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
package.jsonrunspatch-packageonpostinstall. That hook also fires in the install context of everyone who installs@ybouane/liquidglassfrom npm, where it can never succeed:patch-packageis indevDependencies, and npm does not install a dependency's devDependencies — so the binary isn't there.patches/isn't in thefilesarray, so nothing is shipped to apply.For consumers the result is either a failing postinstall or adding
patch-packageto their own dependencies purely so a no-op can exit cleanly. We ended up doing the latter, and now carry a dependency our code never uses.prepareis the right hook. It runs on a barenpm installin this repo, beforenpm publish, and for git-URL installs where bothdevDependenciesandpatches/are present — so thehtml-to-imagepatch is still applied for local development and beforenpm run build, which is what matters given esbuild bundleshtml-to-imageintodist/. It does not run for registry installs of the published package.Verified in a fresh clone:
npm installprintshtml-to-image@1.11.13 ✔, exactly as before. One line, no change for maintainers.