I've installed a custom package called @company/cdk-library.
It has package.json scripts:
"scripts": {
"test": "jest",
"build": "tsc",
"prepublishOnly": "npx tsc --skipLibCheck",
"installLambdas": "(cd constructs/account/mylambda/code/ && npm i)",
"postinstall": "npm run installLambdas"
},
When I install this package into my project using: npm i @mycompany/[email protected] --foreground-script
I don't get any indication that it's ran the postinstall
script. If I check the directory, there's no dependencies there either.
Output from install:
➜ cdk git:(cdk-update) ✗ npm i @mycompany/[email protected] --foreground-scripts
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
added 504 packages, and audited 523 packages in 16s
25 packages are looking for funding
run `npm fund` for details
1 critical severity vulnerability
To address all issues, run:
npm audit fix
Run `npm audit` for details.
However, if I do it manually by running cd node_modules/@mycompany/cdk-library && npm run postinstall
It runs it fine, output:
cdk-library git:(cdk-update) ✗ npm run postinstall
> @mycompany/[email protected] postinstall
> npm run installLambdas
npm WARN deprecated [email protected]: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
added 82 packages, and audited 83 packages in 1s
...
Does anyone know why my postinstall isn't running when I install the package?
I know this has been here for a while, but I just ran into it myself and what I finally worked out, is that "postinstall" will only be callled with you actually using "npm install ..."
If you happen to use the shortcut "npm i ..." it won't be called. You would need to add a script entry for "posti" in order to have it also work with the shortcut.
Hope this helps others.