Skip to content

Use prepare instead of postinstall for patch-package - #4

Open
warudin wants to merge 1 commit into
ybouane:mainfrom
warudin:fix/patch-package-prepare-hook
Open

Use prepare instead of postinstall for patch-package#4
warudin wants to merge 1 commit into
ybouane:mainfrom
warudin:fix/patch-package-prepare-hook

Conversation

@warudin

@warudin warudin commented Aug 6, 2026

Copy link
Copy Markdown

package.json runs patch-package on postinstall. That hook also fires in the install context of everyone who installs @ybouane/liquidglass from npm, where it can never succeed:

  • patch-package is in devDependencies, and npm does not install a dependency's devDependencies — so the binary isn't there.
  • patches/ isn't in the files array, so nothing is shipped to apply.

For consumers the result is either a failing postinstall or adding patch-package to 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.

prepare is the right hook. It runs on a bare npm install in this repo, before npm publish, and for git-URL installs where both devDependencies and patches/ are present — so the html-to-image patch is still applied for local development and before npm run build, which is what matters given esbuild bundles html-to-image into dist/. It does not run for registry installs of the published package.

Verified in a fresh clone: npm install prints html-to-image@1.11.13 ✔, exactly as before. One line, no change for maintainers.

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.
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

Successfully merging this pull request may close these issues.

2 participants