zkat / npx

execute npm package binaries (moved)

Home Page:https://github.com/npm/npx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow executing project scripts defined in package.json via `npx run {SCRIPT_NAME}` similar to `yarn run`

k0pernikus opened this issue · comments

Given a package.json containing project scripts like:

  "scripts": {
    "build": "rm ./dist/* -rf && tsc",
    "task": "node dist/src/bin/taskRunner.js",
    "goldenMaster:test": "mocha dist/tests/acceptance/TaskTests.js",
    "goldenMaster:update": "cp ./out/data.csv ./tests/acceptance/goldenMaster.csv"
  },

I would like npx to have the feature to invoke these scripts through npx run {SCRIPT NAME}, e.g.:

npx run build
npx run goldenMaster:test

The npx run {SCRIPT NAME} execution should print the actual command being executed and its result.

For example, npx run build should print:

npx run build
$ rm ./dist/* -rf && tsc
Done in 2.57s.

If npx run was invoked without a script name, it could give a list of all the possible scripts and installed binaries which it could run.

  • So if a project ony has the dependencies typescript and tslint, it should print this for yarn run:

     Commands available from binary scripts: esparse, esvalidate, js-yaml, semver, tsc, tslint, tsserver
    
  • if a project only had said dependencies and the mentioned scripts defintions, npx run should print:

    info Commands available from binary scripts: esparse, esvalidate, js-yaml, semver, tsc, tslint, tsserver
    info Project commands
       - build
          rm ./dist/* -rf && tsc
       - goldenMaster:test
          mocha dist/tests/acceptance/TaskTests.js
       - goldenMaster:update
          cp ./out/data.csv ./tests/acceptance/goldenMaster.csv
       - task
          node dist/src/bin/taskRunner.js
    

This feature request is identical to the actual current behavior of yarn run and the example output provided here is also a direct copy of yarn run behavior.

I just realized that it would already suffice if npx run could just pass through to npm run.

The actual use case is allowing to call both scripts and binaries through one interface, and it should be npx.

As #107 says -- I'm not interested in doing this kind of overloading, and the apparent convenience is superficial at best. Just use npm run. I don't consider run-scripts to be binaries or subcommands. I think conflating those is bound to cause more pain than anything.