Comparing version 0.9.0 to 0.10.0
{ | ||
"name": "npm-watch", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "run scripts from package.json when files change", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,2 +5,5 @@ # npm-watch | ||
## Common Issues | ||
- `monorepo setups`: In a monorepo setup, `npm-watch` may fail with `ENOENT`. The solution is to have nodemon globally installed. [See here for more context](https://github.com/M-Zuber/npm-watch/issues/83) | ||
## Synopsis | ||
@@ -129,2 +132,13 @@ | ||
### Global Config | ||
#### `setMaxListeners` | ||
If too many listeners are added to an event emitter, [`node.js` will send a warning (rightfully so) about potential memory leaks](https://nodejs.org/docs/latest/api/events.html#events_emitter_setmaxlisteners_n). | ||
The default maximum is 10. If you need more than that, you can add a top level global config to your package.json | ||
```json | ||
"watchGlobalConfig": { | ||
"setMaxListeners": true | ||
} | ||
``` | ||
And max listeners will be set on the relevant processes to the minimum needed to avoid the warning. | ||
### Options | ||
@@ -131,0 +145,0 @@ |
@@ -64,3 +64,8 @@ 'use strict'; | ||
} else { | ||
// We only look for the global watch config here, since it is otherwise not relevant | ||
var setMaxListeners = null; | ||
if (typeof pkg.watchGlobalConfig === 'object') { | ||
setMaxListeners = pkg.watchGlobalConfig.setMaxListeners | ||
} | ||
var scriptsCount = Object.keys(pkg.watch).length; | ||
Object.keys(pkg.watch).forEach(function (script) { | ||
@@ -70,3 +75,3 @@ if (!pkg.scripts[script]) { | ||
} | ||
startScript(script, pkg, processes); | ||
startScript(script, pkg, processes, setMaxListeners, scriptsCount + 1); | ||
}) | ||
@@ -99,3 +104,3 @@ } | ||
function startScript(script, pkg, processes) { | ||
function startScript(script, pkg, processes, setMaxListeners, scriptsCount) { | ||
var exec = [npm, 'run', '-s', script].join(' ') | ||
@@ -154,3 +159,8 @@ var patterns = null | ||
if (silent) { args = args.concat(['-q']) } | ||
if (runOnChangeOnly) { args = args.concat(['--on-change-only']) } | ||
if (runOnChangeOnly) { args = args.concat(['--on-change-only']) } | ||
if (setMaxListeners){ | ||
process.setMaxListeners(scriptsCount) | ||
stdin.stdout.setMaxListeners(scriptsCount) | ||
stdin.stderr.setMaxListeners(scriptsCount) | ||
} | ||
args = args.concat(['--exec', exec]) | ||
@@ -157,0 +167,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14554
177
247