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.
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.
- Are you asking how to do when when (a) Your module is installed (b) Any module is installed when npm install is run in the same directory as your package.json or (c) Any module is installed system wide on your puter? – Quentin Commented Oct 13, 2017 at 8:23
-
(b) any module is installed when
npm install <module>
is run in the same directory as package.json . just to make myself clear -> for installing an package / module you run the mandnpm install name_of_module
. I want a script to be run every time i try to install any package / module from npm . – yawningphantom Commented Oct 13, 2017 at 11:54 -
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>
? – RobC Commented Oct 13, 2017 at 13:26 - yeah it can be done by using npm view and shell scripting but I was hoping to get a better solution so that my team can follow the same convention anyway I create a shell script and added the script node . now it asks for the name of the module , show dependencies and version and then ask whether I would like to install the package. – yawningphantom Commented Oct 13, 2017 at 16:22
- In which case you’ve almost answered your question here over here – RobC Commented Oct 13, 2017 at 16:52
1 Answer
Reset to default 10Add "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]"