📜 ⬆️ ⬇️

NPM 2.0.0 & passing arguments to run-script

On July 22, a small but significant event happened: a pull request was accepted, which added support for passing arbitrary arguments to your npm scripts. The alpha release of npm version 2.0.0 has already appeared, which includes this feature.

For a start, why is this good?
Historically, some kind of node-packages (build tools, test runners) used two types of package set: one installed globally, which usually had a post -fli-kli (karma-cli, grunt-cli) that ran the locally installed package in node_modules. This made it possible to use different versions of test runners, without having to break all the tests in all other projects, if necessary, update the package in one of them. This, in its time, was an excellent solution for grunt (version 0.4.0 applied this approach, which helped avoid many problems with inverse package incompatibility).
Also, there is the fact that when running npm script, node_modules / .bin are added to the path of executable files, in which, in principle, are the same runners / builders that are launched by the global cli package. This allows you to add in your package.json:
scripts: { grunt: "grunt build" } 

and run the locally installed grunt with a simple npm run grunt . The problem to this day was the case when you had to pass arguments to your npm script — that was impossible.
Now it will be possible by adding in your package.json
 scripts: { grunt: "grunt" } 

use commands like npm run grunt - build or npm run grunt - build --verbose . In one of the comments to the original pull request, it is proposed to simply create an alias of the form alias gr='npm run grunt --' and run the build with a simple gr build .

')

Source: https://habr.com/ru/post/230831/


All Articles