From 8d543bd1485a65d7a2cb6c96ad04ff201249cae7 Mon Sep 17 00:00:00 2001 From: Naoyuki Kanezawa Date: Sun, 1 Jan 2017 04:40:18 +0900 Subject: [PATCH] remove the monkeypatch of watchpack (#580) --- .../plugins/watch-remove-event-plugin.js | 71 +------------------ 1 file changed, 2 insertions(+), 69 deletions(-) diff --git a/server/build/plugins/watch-remove-event-plugin.js b/server/build/plugins/watch-remove-event-plugin.js index f0b30e3a..2f7a9920 100644 --- a/server/build/plugins/watch-remove-event-plugin.js +++ b/server/build/plugins/watch-remove-event-plugin.js @@ -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 */