From cb3b792b50867356115830aaf2200248150af019 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 5 Jul 2019 18:11:25 +0200 Subject: [PATCH] Fixes #70205: Switch to polling based watcher that does not miss events --- build/lib/compilation.js | 26 ++------------------------ build/lib/compilation.ts | 28 ++-------------------------- 2 files changed, 4 insertions(+), 50 deletions(-) diff --git a/build/lib/compilation.js b/build/lib/compilation.js index 592a5d087ce..62aff873509 100644 --- a/build/lib/compilation.js +++ b/build/lib/compilation.js @@ -112,7 +112,6 @@ class MonacoGenerator { this._executeSoonTimer = null; this._isWatch = isWatch; this.stream = es.through(); - this._watchers = []; this._watchedFiles = {}; let onWillReadFile = (moduleId, filePath) => { if (!this._isWatch) { @@ -122,26 +121,10 @@ class MonacoGenerator { return; } this._watchedFiles[filePath] = true; - const watcher = fs.watch(filePath); - watcher.addListener('change', () => { + fs.watchFile(filePath, () => { this._declarationResolver.invalidateCache(moduleId); this._executeSoon(); }); - watcher.addListener('error', (err) => { - console.error(`Encountered error while watching ${filePath}.`); - console.log(err); - delete this._watchedFiles[filePath]; - for (let i = 0; i < this._watchers.length; i++) { - if (this._watchers[i] === watcher) { - this._watchers.splice(i, 1); - break; - } - } - watcher.close(); - this._declarationResolver.invalidateCache(moduleId); - this._executeSoon(); - }); - this._watchers.push(watcher); }; this._fsProvider = new class extends monacodts.FSProvider { readFileSync(moduleId, filePath) { @@ -151,11 +134,9 @@ class MonacoGenerator { }; this._declarationResolver = new monacodts.DeclarationResolver(this._fsProvider); if (this._isWatch) { - const recipeWatcher = fs.watch(monacodts.RECIPE_PATH); - recipeWatcher.addListener('change', () => { + fs.watchFile(monacodts.RECIPE_PATH, () => { this._executeSoon(); }); - this._watchers.push(recipeWatcher); } } _executeSoon() { @@ -168,9 +149,6 @@ class MonacoGenerator { this.execute(); }, 20); } - dispose() { - this._watchers.forEach(watcher => watcher.close()); - } _run() { let r = monacodts.run3(this._declarationResolver); if (!r && !this._isWatch) { diff --git a/build/lib/compilation.ts b/build/lib/compilation.ts index b431a134f6c..f9544af9cc5 100644 --- a/build/lib/compilation.ts +++ b/build/lib/compilation.ts @@ -137,7 +137,6 @@ class MonacoGenerator { private readonly _isWatch: boolean; public readonly stream: NodeJS.ReadWriteStream; - private readonly _watchers: fs.FSWatcher[]; private readonly _watchedFiles: { [filePath: string]: boolean; }; private readonly _fsProvider: monacodts.FSProvider; private readonly _declarationResolver: monacodts.DeclarationResolver; @@ -145,7 +144,6 @@ class MonacoGenerator { constructor(isWatch: boolean) { this._isWatch = isWatch; this.stream = es.through(); - this._watchers = []; this._watchedFiles = {}; let onWillReadFile = (moduleId: string, filePath: string) => { if (!this._isWatch) { @@ -156,26 +154,10 @@ class MonacoGenerator { } this._watchedFiles[filePath] = true; - const watcher = fs.watch(filePath); - watcher.addListener('change', () => { + fs.watchFile(filePath, () => { this._declarationResolver.invalidateCache(moduleId); this._executeSoon(); }); - watcher.addListener('error', (err) => { - console.error(`Encountered error while watching ${filePath}.`); - console.log(err); - delete this._watchedFiles[filePath]; - for (let i = 0; i < this._watchers.length; i++) { - if (this._watchers[i] === watcher) { - this._watchers.splice(i, 1); - break; - } - } - watcher.close(); - this._declarationResolver.invalidateCache(moduleId); - this._executeSoon(); - }); - this._watchers.push(watcher); }; this._fsProvider = new class extends monacodts.FSProvider { public readFileSync(moduleId: string, filePath: string): Buffer { @@ -186,11 +168,9 @@ class MonacoGenerator { this._declarationResolver = new monacodts.DeclarationResolver(this._fsProvider); if (this._isWatch) { - const recipeWatcher = fs.watch(monacodts.RECIPE_PATH); - recipeWatcher.addListener('change', () => { + fs.watchFile(monacodts.RECIPE_PATH, () => { this._executeSoon(); }); - this._watchers.push(recipeWatcher); } } @@ -206,10 +186,6 @@ class MonacoGenerator { }, 20); } - public dispose(): void { - this._watchers.forEach(watcher => watcher.close()); - } - private _run(): monacodts.IMonacoDeclarationResult | null { let r = monacodts.run3(this._declarationResolver); if (!r && !this._isWatch) {