I have a Node.js server I am developing and I'm using nodemon to have the server restarted when the source code changes.
This server has a dependency on another module, which I am also developing, so it would be nice if changes to that module also restarted the server.
Best attempt yet (Thanks, bitstrider!)
I made a repo to reproduce this problem with minimal code if anyone wants to check it out: https://github.com/shawninder/nodemon-troubles
The highlights are in nodemon.json
:
{
"ignoreRoot": [
".git",
".nyc_output",
".sass-cache",
"bower-components",
"coverage"
],
"ignore": [
"node_modules/!(is-node)",
"node_modules/is-node/node_modules"
]
}
ignoreRoot
is the same as the defaults, but withoutnode_modules
.ignore
is where I'm trying to tell it to ignore node_modules, but notis-node
.
This almost works (editing is-node restarts the server) but it's watching all the node modules, not only is-node.
How can I tell nodemon to ignore all node modules except for one?
Details
- I'm using the latest version of nodemon, 1.11.0
- I also tried with https://github.com/remy/nodemon/pull/922
Explaining the problem
Nodemon takes the ignores and combines them into one big regular expression before passing this along to chokidar. It's a custom parsing algorithm based on regular expressions and supports neither glob negation nor regular expression syntax. For example, the example above produces the following regular expression:
/\.git|\.nyc_output|\.sass\-cache|bower\-components|coverage|node_modules\/!\(is\-node\)\/.*.*\/.*|node_modules\/is\-node\/node_modules\/.*.*\/.*/
Notice the negation character !
end up as a literal !
in the resulting regular expression. Using negative look-ahead syntax also doesn't work because the control characters are transformed into literal characters.
{"ignoreRoot: [".git", ".nyc_output", ".sass-cache", "bower-components", "coverage"], "ignore": ["node_modules/!(my-watched-module)", "node_modules/my-watched-module/node_modules"]}
It's correctly watching my-watched-module and not watching my-watched-module's node_modules, but it's still watching other node modules... – Indistinguishable