An automatic call of "node-gyp rebuild" on "npm install" and "yarn install"

Viewed 350

I am creating a package with some native code, which will be installed globally, and now I see the following behavior:

  1. node-gyp rebuild runs automatically on local npm install and when the package is installed itself.
  2. When I add a custom preinstall script to the package.json, it isn't invoked anymore on npm install nor when the package is installed globally, so it's not compiled at all.
  3. However, in case of yarn install node-gyp rebuild still runs even with a preinstall hook.
  4. Moreover, if I add "preinstall": "node-gyp rebuild", yarn runs my script and then invokes node-gyp rebuild again, so it is compiled twice.

I wonder is there any documentation describing this behavior? Cause I found nothing. I even didn't find an explicit mention that node-gyp rebuild runs automatically on npm install.
And how can I use the preinstall hook so that my module is compiled only once both for npm and yarn?

npm 6.14.6
yarn 1.22.4

0 Answers
Related