I am trying to make a test for npm packages for my project such that every time I try to install a module i.e run npm install <module>
a script must be run before that module is installed. The preinstall script only works with npm install
and not with npm install <module>
.
eg :- If run npm install request
. It should run a script which shows me all the dependencies of the request module before installing the module. Thanks in advance.
You could run $ npm view <package_name> dependencies , (to list the dependencies), before running $ npm install <package_name> as mentioned in the docs. Or must $ npm view <package_name> dependencies be automatically invoked every time you run $ npm view <package_name> ?
To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command. Some predefined aliases convert to npm run, like npm test or npm start, you can use them interchangeably. Maintaining commands you run regularly as an npm script is common, like starting your application, linting, building production apps, etc.
npm run install only runs the package. json scripts. install , it will not install dependencies.
An npm script is a convenient way to bundle common shell commands for your project. They are typically commands, or a string of commands, which would normally be entered at the command line in order to do something with your application. Scripts are stored in a project's package.
Add "install": "[Your Command]"
in the script part of your package.json
Example:
{
"name": "test",
"version": "1.0.0",
"description": "A sample test",
"main": "index.js",
"scripts": {
"install": "echo Test"
}
}
You can also use a pre hook with "preinstall": "[Your Command]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With