Skip to content

Commit b0d9240

Browse files
author
Daniel Gasienica
committed
Add support for ignoring paths
Uses `ignore` configuration key with an array of ignored paths or files. Fixes #88
1 parent 18192c0 commit b0d9240

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ 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)
@@ -146,3 +166,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
146166
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
147167
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
148168
THE SOFTWARE.
169+
170+
171+
[react]: http://facebook.github.io/react/
172+
[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
@@ -61,7 +61,9 @@ module.exports = function(args) {
6161

6262
// Listen for `required` messages and watch the required file.
6363
ipc.on(child, 'required', function(m) {
64-
if (cfg.deps == -1 || getLevel(m.required) <= cfg.deps) {
64+
var isIgnored = cfg.ignore.some(isPrefixOf(m.required))
65+
66+
if (!isIgnored && (cfg.deps == -1 || getLevel(m.required) <= cfg.deps)) {
6567
watcher.add(m.required)
6668
}
6769
})
@@ -107,3 +109,9 @@ function getPrefix(mod) {
107109
var i = mod.lastIndexOf(n)
108110
return ~i ? mod.slice(0, i+n.length) : ''
109111
}
112+
113+
function isPrefixOf(value) {
114+
return function (prefix) {
115+
return value.indexOf(prefix) === 0
116+
}
117+
}

0 commit comments

Comments
 (0)