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 npm alpha release of 2.0.0 has already appeared , which includes this feature.

    For starters, why is this good?
    Historically, some kind of node packages (build tools, test runners) used two types of packages: one installed globally, which usually had the postfix-cli (karma-cli, grunt-cli), which ran a 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 any of them. This, at one time, was an excellent solution for grunt (version 0.4.0 applied this approach, which helped to avoid many problems with backward incompatibility of packages).
    Also, there is the fact that when you run the npm script, node_modules / .bin is added to the path of executable files, which, in principle, contains the very 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 running locally installed grunt is easy npm run grunt. The problem to this day was the case when you needed to pass arguments to your npm script - this was not possible.
    Now it will be possible by adding package.json to your
    scripts: {
     grunt: "grunt"

    use commands of the form npm run grunt - buildor 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 launch the build is simple gr build.

    Also popular now: