Giter Club home page Giter Club logo

npm-run's Introduction

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

npm-run's People

Contributors

aretecode avatar doug-wade avatar gyran avatar htanjo avatar millermedeiros avatar scottyeck avatar timoxley avatar wesleytodd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

npm-run's Issues

Cannot find module 'cross-spawn'

npm-run breaks due to "cross-spawn" not being installed. This dependency got removed in the last commit.

npm-run app-config build -e staging-f ./src/config.default.js
module.js:545
    throw err;
    ^
Error: Cannot find module 'cross-spawn'
    at Function.Module._resolveFilename (module.js:543:15)
    at Function.Module._load (module.js:470:25)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm-run/index.js:5:13)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)

bug: options is not optional

When running npmRun.exec(cmd, callback) I got a TypeError: Cannot read property 'env' of undefined (at augmentOptionsSync - index.js:73:34).

Run from a sub-directory

Is it possible to run a package from a sub-directory or a folder different from the root of the project? Now I get:

not found: PACKAGE_NAME

Thanks,
Marco.

Local eslint doesn't work

This happens because eslint doesnt get installed in node_modules/bin, but rather in node_modules/eslint/bin. (but if I add a script in package.json, npm will find it).

Is this in the scope of the project? Would you accept a PR?

Remove spawn-sync dep

Is it possible to remove that dep in favor of using the built in one?

I understand backwards compat issues, BUT let me tell you my story:

I am using the linter happiness (a fork of standard). I added it to the package.json's of my company modules, about 100 of them. We are also using linklocal for development and a recursive link via bulk. Turns out that the npm install in all these directories takes like an hour. Here is the dependency tree that is leading here:

node_modules/happiness/node_modules/happiness-format/node_modules/esformatter/node_modules/npm-run/node_modules/spawn-sync

spawn-sync is a c extension, so gets compiled for every npm install that is run. I didnt spend the time to figure out how many times it is run, but I started it at like 9am and now it is 12 and it is still running :)

I had some time, so figured I would open an issue here.....

ENOENT error on Windows

D:\Dev\webextension-test>npm-run --version
5.0.1

D:\Dev\webextension-test>npm-run web-ext --version
Error: spawn web-ext ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:201:19)
    at onErrorNT (internal/child_process.js:379:16)
    at process._tickCallback (internal/process/next_tick.js:114:19)
    at Function.Module.runMain (module.js:705:11)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:660:3

D:\Dev\webextension-test>npm-run where web-ext
D:\Dev\webextension-test\node_modules\.bin\web-ext
D:\Dev\webextension-test\node_modules\.bin\web-ext.cmd
C:\Users\Owner\AppData\Roaming\npm\web-ext
C:\Users\Owner\AppData\Roaming\npm\web-ext.cmd

It works fine with v4.x.

Dashed parameters are not passed

When I install bower locally and try to get it's version with npm-run bower --version I get the version of npm-run, not of bower. Same with grunt. I suspect that the --params are not passed to the binary correctly.

Doesn't work on Windows 10 ?

Hi, it seems npm-run doesn't work on my windows. Basically it will return a not found: module-xyz for every module I tried. But on bash on ubuntu for windows, same machine, it works (and in both cases, nothing is globally installed). Is it as intended ? Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.