Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

npm-run

timoxley199.2kMIT5.0.1TypeScript support: definitely-typed

Run executables for locally-installed packages without using ./node_modules/.bin

npm, path, executable, .bin, run

readme

npm-run

NPM NPM

Build Status

Run executables in node_modules from the command-line

Use npm-run to ensure you're using the same version of a package on the command-line and in package.json scripts.

Any executable available to an npm lifecycle script is available to npm-run.

Usage

> npm install mocha # mocha installed in ./node_modules
> npm-run mocha test/* # uses locally installed mocha executable 
> npm-run --help
Usage: npm-run command [...args]
Options:
  --version  Display version & exit.
  --help     Display this help & exit.

Hint: to print augmented path use:
npm-run node -p process.env.PATH

Installation

> npm install -g npm-run

Programmatic API

The API of npm-run basically wraps core child_process methods (exec, spawn, etc) such that locally install package executables will be on the PATH when the command runs.

npmRun(command[, options], callback)

Alias of npmRun.exec.

npmRun.exec(command[, options], callback)

Takes same arguments as node's exec.

npmRun.exec('mocha --debug-brk --sort', {cwd: __dirname + '/tests'}, function (err, stdout, stderr) {
  // err Error or null if there was no error
  // stdout Buffer|String
  // stderr Buffer|String
})

npmRun.sync(command[, options])

Alias of npmRun.execSync

npmRun.execSync(command[, options])

Takes same arguments as node's execSync.

var stdout = npmRun.execSync(
  'mocha --debug-brk --sort',
  {cwd: __dirname + '/tests'}
)
stdout // command output as Buffer|String

npmRun.spawnSync(command[, args][, options])

Takes same arguments as node's spawnSync.

var child = npmRun.spawnSync(
  'mocha',
  '--debug-brk --sort'.split(' '),
  {cwd: __dirname + '/tests'}
)
child.stdout // stdout Buffer|String
child.stderr // stderr Buffer|String
child.status // exit code

npmRun.spawn(command[, args][, options])

Takes same arguments as node's spawn.

var child = npmRun.spawn(
  'mocha',
  '--debug-brk --sort'.split(' '),
  {cwd: __dirname + '/tests'}
)
child.stdout // stdout Stream
child.stderr // stderr Stream
child.on('exit', function (code) {
  code // exit code
})

Why

Due to npm's install algorithm node_modules/.bin is not guaranteed to contain your executable. npm-run uses the same mechanism npm uses to locate the correct executable.

See Also

License

MIT

changelog

5.0.1 / 2018-04-12

  • Fix broken package reference.

5.0.0 / 2018-04-10

  • Update dependencies.
  • Remove spawn-sync polyfill.
  • Test on node 8.

4.1.2 / 2017-03-17

  • Options is optional (@Gyran)

4.1.1 / 2016-07-22

  • Update dependencies.
  • Documentation fixes.
  • Lint code.

4.1.0 / 2016-07-22

  • Update dependencies.
  • Support Windows with cross-spawn. (@htanjo)

4.0.1 / 2016-07-22

  • Update dependencies.

4.0.0 / 2016-07-22

  • Update dependencies.
  • Older versions of node no longer supported.

3.0.0 / 2016-02-25

  • Removed spawn-sync. (@wesleytodd)

2.0.1 / 2016-01-29

  • Update to exec-sync with new licence. (@gtanner)

2.0.0 / 2015-03-22

  • Alter API to be simple wrapper around child_process methods.

1.1.1 / 2015-03-06

  • Fix sync exec in 0.12/io.js. Polyfill with sync-exec over runsync.
  • Add Travis CI.

1.1.0 / 2015-03-06

  • Update dependencies.
  • Correctly forward dashed parameters. (Reported by @michalkleiner)
  • Improve error reporting for non-existent commands.
  • Polyfill execSync for legacy node.
  • Add npmRun.sync method (SEMVER.MINOR) (@millermedeiros)

1.0.2 / 2014-06-28

  • Add missing npm-which dependency.

1.0.1 / 2014-06-23

  • Add meta info to package.json.

1.0.0 / 2014-04-21

  • Birth