Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing '.' for watch directory. Fix file/stat references #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can also use forever from inside your own node.js code.
var child = new (forever.Monitor)('your-filename.js', {
max: 3,
silent: true,
args: []
args: ['--color']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help others figure out how to enable color support. See here for details

});

child.on('exit', function () {
Expand Down Expand Up @@ -66,9 +66,9 @@ There are several options that you should be aware of when using forever. Most o
// Options for restarting on watched files.
//
'watch': true, // Value indicating if we should watch files.
'watchIgnoreDotFiles': null, // Whether to ignore file starting with a '.'
'watchIgnoreDotFiles': true, // Whether to ignore file starting with a '.'
'watchIgnorePatterns': null, // Ignore patterns to use when watching files.
'watchDirectory': null, // Top-level directory to watch from.
'watchDirectory': '.', // Top-level directory to watch from.

//
// All or nothing options passed along to `child_process.spawn`.
Expand Down
7 changes: 4 additions & 3 deletions lib/forever-monitor/plugins/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ exports.name = 'watch';
//
function watchFilter(fileName) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on removing this function altogether and just passing the watchIgnorePatterns to chokidar? chokidar seems to handle the patterns much better than watch did. We could do something like:

  if (this.watchIgnoreDotFiles) {
    this.watchIgnorePatterns.push(/^\/?\..+/)
  }

  var opts = {
    ignoreInitial: true,
    ignored: this.watchIgnorePatterns
  };

var relFileName = path.relative(this.watchDirectory, fileName),
baseFileName = path.basename(fileName),
length = this.watchIgnorePatterns.length,
testName,
i;

if (this.watchIgnoreDotFiles && path.basename(fileName)[0] === '.') {
if (this.watchIgnoreDotFiles && baseFileName[0] === '.' && baseFileName !== '.') {
return false;
}

Expand Down Expand Up @@ -72,8 +73,8 @@ exports.attach = function () {
// Or, ignore: function(fileName) { return !watchFilter(fileName) }
chokidar
.watch(this.watchDirectory, opts)
.on('all', function(f, stat) {
monitor.emit('watch:restart', { file: f, stat: stat });
.on('all', function(event, path) {
monitor.emit('watch:restart', { file: path, stat: event });
monitor.restart();
});
};