Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 7f1e54c

Browse files
committed
fix(watch): fixed bug where options.ignore was being ignored if it's an array
1 parent 917dfc4 commit 7f1e54c

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/watch.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ describe('watch', () => {
200200
expect(watcher.options.ignored).toEqual('/some/src/**/*.spec.ts');
201201
});
202202

203+
it('should set replacePathVars when options.ignored is an array of strings', () => {
204+
const watcher: watch.Watcher = { options: { ignored: ['{{SRC}}/**/*.spec.ts', '{{SRC}}/index.html'] } };
205+
const context: BuildContext = { srcDir: '/some/src/' };
206+
watch.prepareWatcher(context, watcher);
207+
expect((watcher.options.ignored as string[])[0]).toEqual('/some/src/**/*.spec.ts');
208+
expect((watcher.options.ignored as string[])[1]).toEqual('/some/src/index.html');
209+
});
210+
203211
it('should set replacePathVars when paths is an array', () => {
204212
const watcher: watch.Watcher = { paths: [
205213
'{{SRC}}/some/path1',

src/watch.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function startWatcher(name: string, watcher: Watcher, context: BuildContext) {
8282
}
8383
reject(new BuildError(`A watch configured to watch the following paths failed to start. It likely that a file referenced does not exist: ${filesWatchedString}`));
8484
}, getIntPropertyValue(Constants.ENV_START_WATCH_TIMEOUT));
85+
8586
prepareWatcher(context, watcher);
8687

8788
if (!watcher.paths) {
@@ -157,15 +158,21 @@ export function prepareWatcher(context: BuildContext, watcher: Watcher) {
157158
watcher.options.ignoreInitial = true;
158159
}
159160

160-
if (typeof watcher.options.ignored === 'string') {
161-
watcher.options.ignored = normalize(replacePathVars(context, watcher.options.ignored));
161+
if (watcher.options.ignored) {
162+
if (Array.isArray(watcher.options.ignored)) {
163+
watcher.options.ignored = watcher.options.ignored.map(p => normalize(replacePathVars(context, p)));
164+
} else if (typeof watcher.options.ignored === 'string') {
165+
// it's a string, so just do it once and leave it
166+
watcher.options.ignored = normalize(replacePathVars(context, watcher.options.ignored));
167+
}
162168
}
163169

164-
if (typeof watcher.paths === 'string') {
165-
watcher.paths = normalize(replacePathVars(context, watcher.paths));
166-
167-
} else if (Array.isArray(watcher.paths)) {
168-
watcher.paths = watcher.paths.map(p => normalize(replacePathVars(context, p)));
170+
if (watcher.paths) {
171+
if (Array.isArray(watcher.paths)) {
172+
watcher.paths = watcher.paths.map(p => normalize(replacePathVars(context, p)));
173+
} else {
174+
watcher.paths = normalize(replacePathVars(context, watcher.paths));
175+
}
169176
}
170177
}
171178

0 commit comments

Comments
 (0)