make-github-pseudonymous-again / rejuvenate

:baby: Keep your package up to date
GNU Affero General Public License v3.0
0 stars 1 forks source link

`postinstall` hook should only be run when installing the package dependencies directly #395

Open make-github-pseudonymous-again opened 2 months ago

make-github-pseudonymous-again commented 2 months ago

And not when installing the package itself. Currently, npm install package will fail because it tries to run the husky installation, but husky is a dev dependency.

make-github-pseudonymous-again commented 2 months ago

Would it work to only run husky if we detect that it has been installed? Or do we have to disable this for npm entirely?

make-github-pseudonymous-again commented 2 months ago

Would it work to only run husky if we detect that it has been installed? Or do we have to disable this for npm entirely?

We have to disable this for npm entirely, see for instance:

npm ERR! code 1
npm ERR! path ./node_modules/@async-abstraction/tape
npm ERR! command failed
npm ERR! command sh -c npm run install-hooks
npm ERR! > @async-abstraction/tape@10.0.0 install-hooks
npm ERR! > husky install
npm ERR! husky - .git can't be found (see https://typicode.github.io/husky/#/?id=custom-directory)
make-github-pseudonymous-again commented 2 months ago

According to husky's own docs, not running the postinstall script on npm install can be achieved with

{
  "scripts": {
    // Yarn doesn't support prepare script
    "postinstall": "husky",
    // Include this if publishing to npmjs.com
    "prepack": "pinst --disable",
    "postpack": "pinst --enable"
  }
}

This requires pinst as a dev dependency:

yarn add --dev husky
# Add pinst ONLY if your package is not private
yarn add --dev pinst