Skip to content

cli: implement `node --run <script-in-package-json>`

This is a more up to date implementation of @joyeecheung's original pull-request.

Co-authored-by: Daniel Lemire

The purpose of this pull-request to offer a fast alternative to npm run xxx. With this pull-request, node supports node run test which executes test command inside package.json scripts.

Locally the overhead that node run <cmd> adds to running cmd is ~200ms less than npm run <cmd>

TODO

  • Add documentation
  • Add tests
  • Add node_modules/.bin to PATH.
  • Pass additional arguments to execSync

Benchmark

❯ hyperfine './out/Release/node run test' 'npm run test' -i
Benchmark 1: ./out/Release/node run test
  Time (mean ± σ):      29.3 ms ±   1.1 ms    [User: 23.2 ms, System: 3.1 ms]
  Range (min … max):    27.6 ms …  33.2 ms    97 runs

  Warning: Ignoring non-zero exit code.

Benchmark 2: npm run test
  Time (mean ± σ):     185.7 ms ±   9.2 ms    [User: 136.7 ms, System: 30.3 ms]
  Range (min … max):   174.7 ms … 212.9 ms    15 runs

  Warning: Ignoring non-zero exit code.

Summary
  ./out/Release/node run test ran
    6.34 ± 0.40 times faster than npm run test

Merge request reports

Loading