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

Replace fireworm with sane #1482

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
12 changes: 0 additions & 12 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const EventEmitter = require('events').EventEmitter;
const Bluebird = require('bluebird');
const Path = require('path');
const log = require('npmlog');
const StyledString = require('styled_string');
const find = require('lodash.find');

const Server = require('./server');
Expand Down Expand Up @@ -321,17 +320,6 @@ module.exports = class App extends EventEmitter {
});
}
});
this.fileWatcher.on('EMFILE', () => {
let view = this.view;
let text = [
'The file watcher received a EMFILE system error, which means that ',
'it has hit the maximum number of files that can be open at a time. ',
'Luckily, you can increase this limit as a workaround. See the directions below \n \n',
'Linux: http://stackoverflow.com/a/34645/5304\n',
'Mac OS: http://serverfault.com/a/15575/47234'
].join('');
view.setErrorPopupMessage(new StyledString(text + '\n ').foreground('megenta'));
});

return Bluebird.resolve().asCallback(cb);
}
Expand Down
64 changes: 36 additions & 28 deletions lib/file_watcher.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
'use strict';

const fireworm = require('fireworm');
const sane = require('sane');
const EventEmitter = require('events').EventEmitter;

module.exports = class FileWatcher extends EventEmitter {
constructor(config) {
super();

this.fileWatcher = fireworm('./', {
ignoreInitial: true,
skipDirEntryPatterns: []
});
let onFileChanged = this.onFileChanged.bind(this);
this.fileWatcher.on('change', onFileChanged);
this.fileWatcher.on('add', onFileChanged);
this.fileWatcher.on('remove', onFileChanged);
this.fileWatcher.on('emfile', this.onEMFILE.bind(this));
let globPatterns = [];

let watchFiles = config.get('watch_files');
this.fileWatcher.clear();
let confFile = config.get('file');
if (confFile) {
this.fileWatcher.add(confFile);
}
addPatternToGlobList(globPatterns, confFile);

if (config.isCwdMode()) {
this.fileWatcher.add('*.js');
}
if (watchFiles) {
this.fileWatcher.add(watchFiles);
addPatternToGlobList(globPatterns, '*.js');
}

let watchFiles = config.get('watch_files');
addPatternToGlobList(globPatterns, watchFiles);

let srcFiles = config.get('src_files') || '*.js';
this.fileWatcher.add(srcFiles);
addPatternToGlobList(globPatterns, srcFiles);

let ignoreFiles = config.get('src_files_ignore');
if (ignoreFiles) {
this.fileWatcher.ignore(ignoreFiles);
}

let cwd = config.cwd();

this.fileWatcher = sane(cwd, {
glob: globPatterns,
ignored: ignoreFiles
});

let onFileChanged = this.onFileChanged.bind(this);
this.fileWatcher.on('change', onFileChanged);
this.fileWatcher.on('add', onFileChanged);
this.fileWatcher.on('delete', onFileChanged);
}

onFileChanged(filePath) {
this.emit('fileChanged', filePath);
}

onEMFILE() {
this.emit('EMFILE');
}

add(file) {
this.fileWatcher.add(file);
this.fileWatcher.register(file);
}
};

function addPatternToGlobList(list, globPattern) {
if (!globPattern) {
return;
}

if (Array.isArray(globPattern)) {
globPattern.forEach((globPattern) => list.push(globPattern));
} else {
list.push(globPattern);
}
}
Loading