Skip to content

Commit fd18d05

Browse files
committed
Merge pull request #99 from FiftyThree/ignore-paths
Add support for ignoring paths
2 parents 432d7f2 + 8b2596b commit fd18d05

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,32 @@ If your app is not listening for these signals `process.exit(0)` will be called
123123
immediately. If a listener is registered, node-dev assumes that your app will
124124
exit on its own once it is ready.
125125

126+
### Ignore paths
127+
128+
If you’d like to ignore certain paths or files from triggering a restart simply
129+
list them in the `.node-dev.json` configuration under `"ignore"`, e.g.
130+
131+
```json
132+
{
133+
"ignore": [
134+
"client/scripts",
135+
"shared/module.js"
136+
]
137+
}
138+
139+
```
140+
141+
This might be useful when you are running a [universal][universal-javascript]
142+
(isomorphic) web app that shares modules across the server and client, e.g.
143+
[React.js](react) components for server-side rendering, which you don’t want to trigger a
144+
server restart when changed, since it introduces an unnecessary delay.
145+
126146
## License
127147

128148
### The MIT License (MIT)
129149

130-
Copyright (c) 2014 Felix Gnass
150+
Copyright (c) 2014–2015 Felix Gnass
151+
Copyright (c) 2015 Daniel Gasienica
131152

132153
Permission is hereby granted, free of charge, to any person obtaining a copy
133154
of this software and associated documentation files (the "Software"), to deal
@@ -146,3 +167,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
146167
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
147168
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
148169
THE SOFTWARE.
170+
171+
172+
[react]: http://facebook.github.io/react/
173+
[universal-javascript]: https://medium.com/@mjackson/universal-javascript-4761051b7ae9

lib/cfg.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ function read(dir) {
66
return fs.existsSync(f) ? JSON.parse(fs.readFileSync(f)) : {}
77
}
88

9+
function resolvePath(unresolvedPath) {
10+
return path.resolve(process.cwd(), unresolvedPath)
11+
}
12+
913
module.exports = function(main, opts) {
1014
var dir = main ? path.dirname(main) : '.'
1115
var c = read(dir)
@@ -22,6 +26,8 @@ module.exports = function(main, opts) {
2226
if (opts.dedupe) c.dedupe = true
2327
}
2428

29+
var ignore = (c.ignore || []).map(resolvePath)
30+
2531
return {
2632
vm : c.vm !== false,
2733
fork : c.fork !== false,
@@ -30,6 +36,7 @@ module.exports = function(main, opts) {
3036
timestamp : c.timestamp || (c.timestamp !== false && 'HH:MM:ss'),
3137
clear : !!c.clear,
3238
dedupe : !!c.dedupe,
39+
ignore : ignore,
3340
extensions : c.extensions || {
3441
coffee: "coffee-script/register",
3542
ls: "LiveScript"

lib/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ module.exports = function(wrapper, script, scriptArgs, opts) {
6969

7070
// Listen for `required` messages and watch the required file.
7171
ipc.on(child, 'required', function(m) {
72-
if (cfg.deps == -1 || getLevel(m.required) <= cfg.deps) {
72+
var isIgnored = cfg.ignore.some(isPrefixOf(m.required))
73+
74+
if (!isIgnored && (cfg.deps == -1 || getLevel(m.required) <= cfg.deps)) {
7375
watcher.add(m.required)
7476
}
7577
})
@@ -115,3 +117,9 @@ function getPrefix(mod) {
115117
var i = mod.lastIndexOf(n)
116118
return ~i ? mod.slice(0, i+n.length) : ''
117119
}
120+
121+
function isPrefixOf(value) {
122+
return function (prefix) {
123+
return value.indexOf(prefix) === 0
124+
}
125+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"watch"
1111
],
1212
"author": "Felix Gnass",
13+
"contributors": [
14+
"Daniel Gasienica <daniel@gasienica.ch> (https://github.com/gasi/)"
15+
],
1316
"repository": {
1417
"type": "git",
1518
"url": "http://github.com/fgnass/node-dev.git"

0 commit comments

Comments
 (0)