1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

remove the monkeypatch of watchpack (#580)

This commit is contained in:
Naoyuki Kanezawa 2017-01-01 04:40:18 +09:00 committed by Guillermo Rauch
parent 629051db2c
commit 8d543bd148

View file

@ -23,77 +23,10 @@ export default class WatchRemoveEventPlugin {
}, callbackUndelayed)
const watchpack = watchFileSystem.watcher
watchpack.fileWatchers.forEach((w) => {
w.on('remove', this.onRemove.bind(this, watchpack, w.path))
watchpack.on('remove', (file) => {
this.removedFiles.push(file)
})
return result
}
}
onRemove (watchpack, file) {
this.removedFiles.push(file)
watchpack.emit('remove', file)
watchpack._onChange(file)
}
}
// monkeypatching watchpack module to fix
// https://github.com/webpack/watchpack/pull/33
let DirectoryWatcher
try {
DirectoryWatcher = require('webpack/node_modules/watchpack/lib/DirectoryWatcher')
} catch (err) {
DirectoryWatcher = require('watchpack/lib/DirectoryWatcher')
}
/* eslint-disable */
var FS_ACCURENCY = 10000;
function withoutCase(str) {
return str.toLowerCase();
}
DirectoryWatcher.prototype.setFileTime = function setFileTime(filePath, mtime, initial, type) {
var now = Date.now();
var old = this.files[filePath];
this.files[filePath] = [initial ? Math.min(now, mtime) : now, mtime];
// we add the fs accurency to reach the maximum possible mtime
if(mtime)
mtime = mtime + FS_ACCURENCY;
if(!old) {
if(mtime) {
if(this.watchers[withoutCase(filePath)]) {
this.watchers[withoutCase(filePath)].forEach(function(w) {
if(!initial || w.checkStartTime(mtime, initial)) {
w.emit("change", mtime);
}
});
}
}
} else if(!initial && mtime && type !== "add") {
if(this.watchers[withoutCase(filePath)]) {
this.watchers[withoutCase(filePath)].forEach(function(w) {
w.emit("change", mtime);
});
}
} else if(!initial && !mtime) {
delete this.files[filePath];
if(this.watchers[withoutCase(filePath)]) {
this.watchers[withoutCase(filePath)].forEach(function(w) {
w.emit("remove");
});
}
}
if(this.watchers[withoutCase(this.path)]) {
this.watchers[withoutCase(this.path)].forEach(function(w) {
if(!initial || w.checkStartTime(mtime, initial)) {
w.emit("change", filePath, mtime);
}
});
}
};
/* eslint-enable */