Skip to content
Browse files

Merge branch 'master' of github.com:remy/nodemon

  • Loading branch information...
2 parents ee4ef25 + a452fb5 commit 06f4f53ab0e7d6fb4bda16295824fee7bc973d23 @remy committed
Showing with 55 additions and 42 deletions.
  1. +8 −0 README.md
  2. +47 −42 nodemon.js
View
8 README.md
@@ -115,6 +115,14 @@ To test this, you can kill the server.js process and forever will restart it. If
Note that I *would not* recommend using nodemon in a production environment - but that's because I wouldn't want it restart without my explicit instruction.
+# Help! My changes aren't being detected!
+
+nodemon has three potential methods it uses to look for file changes. First, it polls using the find command to search for files modified within the last second. This method works on systems with a BSD based find (Mac, for example).
+
+Next it tries using node's fs.watch. fs.watch will not always work however, and nodemon will try and detect if this is the case by writing a file to the tmp directory and seeing if fs.watch is triggered when it's removed. If nodemon finds that fs.watch was not triggered, it will then fall back to the third method (called legacy watch), which works by statting each file in your working directory looking for changes to the last modified time. This is the most cpu intensive method, but it may be the only option on some systems.
+
+In certain cases, like when where you are working on a different drive than your tmp directory is on, fs.watch may give you a false positive. You can force nodemon to start using the most compatible legacy method by passing the -L switch, e.g. `nodemon -L /my/odd/file.js`.
+
# License
MIT [http://rem.mit-license.org](http://rem.mit-license.org)
View
89 nodemon.js
@@ -36,7 +36,8 @@ var fs = require('fs'),
// Flag to distinguish an app crash from intentional killing (used on Windows only for now)
killedAfterChange = false,
// Make this the last call so it can use the variables defined above (specifically isWindows)
- program = getNodemonArgs();
+ program = getNodemonArgs(),
+ watched = [];
// test to see if the version of find being run supports searching by seconds (-mtime -1s -print)
if (noWatch) {
@@ -239,19 +240,27 @@ function startMonitor() {
fs.readdir(dir, function (err, files) {
if (!err) {
+ files = files.
+ map(function (file ) { return path.join(dir, file); }).
+ filter(ignoredFilter);
files.forEach(function (file) {
- var filename = path.join(dir, file);
- fs.stat(filename, function (err, stat) {
- if (!err && stat) {
- if (stat.isDirectory()) {
- fs.realpath(filename, watch);
+ if (-1 === watched.indexOf(file)) {
+ watched.push(file);
+ fs.stat(file, function (err, stat) {
+ if (!err && stat) {
+ if (stat.isDirectory()) {
+ fs.realpath(file, watch);
+ }
}
- }
- });
+ });
+ }
});
}
});
} catch (e) {
+ if ('EMFILE' === e.code) {
+ console.error('EMFILE: Watching too many files.');
+ }
// ignoring this directory, likely it's "My Music"
// or some such windows fangled stuff
}
@@ -267,45 +276,41 @@ function startMonitor() {
changeFunction = function() { util.error("Nodemon error: changeFunction called when it shouldn't be.") }
}
+ // filter ignored files
+ var ignoredFilter = function (file) {
+ // If we are in a Windows machine
+ if (isWindows) {
+ // Break up the file by slashes
+ var fileParts = file.split(/\\/g);
+
+ // Remove the first piece (C:)
+ fileParts.shift();
+
+ // Join the parts together with Unix slashes
+ file = '/' + fileParts.join('/');
+ }
+ return !reIgnoreFiles.test(file);
+ };
+
var isWindows = process.platform === 'win32';
if ((noWatch || watchWorks) && !program.options.forceLegacyWatch) {
changeFunction(lastStarted, function (files) {
if (files.length) {
- // filter ignored files
- if (ignoreFiles.length) {
- files = files.filter(function(file) {
- // If we are in a Windows machine
- if (isWindows) {
- // Break up the file by slashes
- var fileParts = file.split(/\\/g);
-
- // Remove the first piece (C:)
- fileParts.shift();
-
- // Join the parts together with Unix slashes
- file = '/' + fileParts.join('/');
- }
- return !reIgnoreFiles.test(file);
+ if (restartTimer !== null) clearTimeout(restartTimer);
+ restartTimer = setTimeout(function () {
+ if (program.options.verbose) util.log('[nodemon] restarting due to changes...');
+ files.forEach(function (file) {
+ if (program.options.verbose) util.log('[nodemon] ' + file);
});
- }
-
- if (files.length) {
- if (restartTimer !== null) clearTimeout(restartTimer);
- restartTimer = setTimeout(function () {
- if (program.options.verbose) util.log('[nodemon] restarting due to changes...');
- files.forEach(function (file) {
- if (program.options.verbose) util.log('[nodemon] ' + file);
- });
- if (program.options.verbose) util.print('\n\n');
-
- if (child !== null) {
- child.kill(isWindows ? '' : 'SIGUSR2');
- } else {
- startNode();
- }
- }, restartDelay);
- return;
- }
+ if (program.options.verbose) util.print('\n\n');
+
+ if (child !== null) {
+ child.kill(isWindows ? '' : 'SIGUSR2');
+ } else {
+ startNode();
+ }
+ }, restartDelay);
+ return;
}
if (noWatch) setTimeout(startMonitor, timeout);

0 comments on commit 06f4f53

Please sign in to comment.
Something went wrong with that request. Please try again.