From 34902dd65f1c4a777bfb0fc2ecd404fd4f95e294 Mon Sep 17 00:00:00 2001 From: Dan Freeman Date: Thu, 10 May 2018 23:09:46 -0400 Subject: [PATCH] Anchor watcher ignore patterns at the project root --- lib/utilities/compile.js | 11 ++++++++--- package.json | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/utilities/compile.js b/lib/utilities/compile.js index 6b94abb97..2030e4733 100644 --- a/lib/utilities/compile.js +++ b/lib/utilities/compile.js @@ -3,6 +3,7 @@ const chokidar = require('chokidar'); const fs = require('fs-extra'); +const escapeRegex = require('escape-string-regexp'); const debug = require('debug')('ember-cli-typescript:tsc:trace'); module.exports = function compile(project, tsOptions, callbacks) { @@ -23,7 +24,7 @@ module.exports = function compile(project, tsOptions, callbacks) { let host = ts.createWatchCompilerHost( configPath, fullOptions, - buildWatchHooks(ts.sys, callbacks), + buildWatchHooks(project, ts.sys, callbacks), createProgram, diagnosticCallback(callbacks.reportDiagnostic), diagnosticCallback(callbacks.reportWatchStatus) @@ -47,13 +48,17 @@ function diagnosticCallback(callback) { } } -function buildWatchHooks(sys, callbacks) { +function buildWatchHooks(project, sys, callbacks) { + let root = escapeRegex(project.root); + let sep = `[/\\\\]`; + let patterns = ['\\..*?', 'dist', 'node_modules', 'tmp']; + let ignored = new RegExp(`^${root}${sep}(${patterns.join('|')})${sep}`); + return Object.assign({}, sys, { watchFile: null, watchDirectory(dir, callback) { if (!fs.existsSync(dir)) return; - let ignored = /\/(\..*?|dist|node_modules|tmp)\//; let watcher = chokidar.watch(dir, { ignored, ignoreInitial: true }); watcher.on('all', (type, path) => { diff --git a/package.json b/package.json index f28735865..9ea1fcf3e 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "ember-cli-valid-component-name": "^1.0.0", "ember-cli-version-checker": "^2.1.0", "ember-router-generator": "^1.2.3", + "escape-string-regexp": "^1.0.5", "execa": "^0.9.0", "exists-sync": "^0.0.4", "fs-extra": "^5.0.0",