diff options
author | Tim Krins <timkrins@gmail.com> | 2015-10-20 20:53:29 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2016-01-21 04:08:38 +0300 |
commit | 310930395c9bf1577cf085b9742210bfc71bb019 (patch) | |
tree | f129af40bb3733f7ead5fdae5bf266097d860e6d | |
parent | e9f1ad88ce58ecd111811e11afa52ac19fc8696e (diff) |
run-script: Warn if using script without install
It might be helpful to remind people that they're trying to run
a script before they actually run `npm install` on the package.
PR-URL: https://github.com/npm/npm/pull/10043
Credit: @timkrins
-rw-r--r-- | doc/cli/npm-run-script.md | 3 | ||||
-rw-r--r-- | lib/utils/lifecycle.js | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/doc/cli/npm-run-script.md b/doc/cli/npm-run-script.md index 1e956adcc..b8da1f09f 100644 --- a/doc/cli/npm-run-script.md +++ b/doc/cli/npm-run-script.md @@ -40,6 +40,9 @@ you should write: instead of `"scripts": {"test": "node_modules/.bin/tap test/\*.js"}` to run your tests. +If you try to run a script without having a `node_modules` directory and it fails, +you will be given a warning to run `npm install`, just in case you've forgotten. + ## SEE ALSO * npm-scripts(7) diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index e2ec37c24..7c93cdfad 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -243,6 +243,11 @@ function runCmd_ (cmd, pkg, env, wd, stage, unsafe, uid, gid, cb_) { if (er.code !== 'EPERM') { er.code = 'ELIFECYCLE' } + fs.stat(npm.dir, function (statError, d) { + if (statError && statError.code === 'ENOENT' && npm.dir.split(path.sep).slice(-1)[0] === 'node_modules') { + log.warn('', 'Local package.json exists, but node_modules missing, did you mean to install?') + } + }) er.pkgid = pkg._id er.stage = stage er.script = cmd |