Skip to content

Commit 8776cc6

Browse files
authored
Merge pull request #208 from typed-ember/fix-ignore-pattern
Anchor watcher ignore patterns at the project root
2 parents 2bc9fd1 + 70fa640 commit 8776cc6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/utilities/compile.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const chokidar = require('chokidar');
55
const fs = require('fs-extra');
6+
const escapeRegex = require('escape-string-regexp');
67
const debug = require('debug')('ember-cli-typescript:tsc:trace');
78

89
module.exports = function compile(project, tsOptions, callbacks) {
@@ -23,7 +24,7 @@ module.exports = function compile(project, tsOptions, callbacks) {
2324
let host = ts.createWatchCompilerHost(
2425
configPath,
2526
fullOptions,
26-
buildWatchHooks(ts.sys, callbacks),
27+
buildWatchHooks(project, ts.sys, callbacks),
2728
createProgram,
2829
diagnosticCallback(callbacks.reportDiagnostic),
2930
diagnosticCallback(callbacks.reportWatchStatus)
@@ -47,13 +48,17 @@ function diagnosticCallback(callback) {
4748
}
4849
}
4950

50-
function buildWatchHooks(sys, callbacks) {
51+
function buildWatchHooks(project, sys, callbacks) {
52+
let root = escapeRegex(project.root);
53+
let sep = `[/\\\\]`;
54+
let patterns = ['\\..*?', 'dist', 'node_modules', 'tmp'];
55+
let ignored = new RegExp(`^${root}${sep}(${patterns.join('|')})${sep}`);
56+
5157
return Object.assign({}, sys, {
5258
watchFile: null,
5359
watchDirectory(dir, callback) {
5460
if (!fs.existsSync(dir)) return;
5561

56-
let ignored = /\/(\..*?|dist|node_modules|tmp)\//;
5762
let watcher = chokidar.watch(dir, { ignored, ignoreInitial: true });
5863

5964
watcher.on('all', (type, path) => {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"ember-cli-valid-component-name": "^1.0.0",
4949
"ember-cli-version-checker": "^2.1.0",
5050
"ember-router-generator": "^1.2.3",
51+
"escape-string-regexp": "^1.0.5",
5152
"execa": "^0.9.0",
5253
"exists-sync": "^0.0.4",
5354
"fs-extra": "^5.0.0",

0 commit comments

Comments
 (0)