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

Commit

Permalink
fix(watch): fixed bug where options.ignore was being ignored if it's …
Browse files Browse the repository at this point in the history
…an array
  • Loading branch information
danbucholtz committed Mar 24, 2017
1 parent 917dfc4 commit 7f1e54c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/watch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ describe('watch', () => {
expect(watcher.options.ignored).toEqual('/some/src/**/*.spec.ts');
});

it('should set replacePathVars when options.ignored is an array of strings', () => {
const watcher: watch.Watcher = { options: { ignored: ['{{SRC}}/**/*.spec.ts', '{{SRC}}/index.html'] } };
const context: BuildContext = { srcDir: '/some/src/' };
watch.prepareWatcher(context, watcher);
expect((watcher.options.ignored as string[])[0]).toEqual('/some/src/**/*.spec.ts');
expect((watcher.options.ignored as string[])[1]).toEqual('/some/src/index.html');
});

it('should set replacePathVars when paths is an array', () => {
const watcher: watch.Watcher = { paths: [
'{{SRC}}/some/path1',
Expand Down
21 changes: 14 additions & 7 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function startWatcher(name: string, watcher: Watcher, context: BuildContext) {
}
reject(new BuildError(`A watch configured to watch the following paths failed to start. It likely that a file referenced does not exist: ${filesWatchedString}`));
}, getIntPropertyValue(Constants.ENV_START_WATCH_TIMEOUT));

prepareWatcher(context, watcher);

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

if (typeof watcher.options.ignored === 'string') {
watcher.options.ignored = normalize(replacePathVars(context, watcher.options.ignored));
if (watcher.options.ignored) {
if (Array.isArray(watcher.options.ignored)) {
watcher.options.ignored = watcher.options.ignored.map(p => normalize(replacePathVars(context, p)));
} else if (typeof watcher.options.ignored === 'string') {
// it's a string, so just do it once and leave it
watcher.options.ignored = normalize(replacePathVars(context, watcher.options.ignored));
}
}

if (typeof watcher.paths === 'string') {
watcher.paths = normalize(replacePathVars(context, watcher.paths));

} else if (Array.isArray(watcher.paths)) {
watcher.paths = watcher.paths.map(p => normalize(replacePathVars(context, p)));
if (watcher.paths) {
if (Array.isArray(watcher.paths)) {
watcher.paths = watcher.paths.map(p => normalize(replacePathVars(context, p)));
} else {
watcher.paths = normalize(replacePathVars(context, watcher.paths));
}
}
}

Expand Down

0 comments on commit 7f1e54c

Please sign in to comment.