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 6ab12a8f6..6fca04cd6 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",