Skip to content

Commit 5fa69db

Browse files
alan-agius4michael-ciniawsky
authored andcommitted
fix(processPattern): add glob directory context to contextDependencies (#290)
1 parent 5474889 commit 5fa69db

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/processPattern.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import writeFile from './writeFile';
66
import isObject from './utils/isObject';
77

88
export default function processPattern(globalRef, pattern) {
9-
const {info, debug, output, concurrency} = globalRef;
9+
const {info, debug, output, concurrency, contextDependencies} = globalRef;
1010
const globArgs = Object.assign({
1111
cwd: pattern.context
1212
}, pattern.fromArgs || {});
@@ -30,6 +30,13 @@ export default function processPattern(globalRef, pattern) {
3030
file.relativeFrom = path.basename(file.relativeFrom);
3131
}
3232

33+
// This is so webpack is able to watch the directory and when
34+
// a new file is added it triggeres a rebuild
35+
const contextPath = path.dirname(path.resolve(from));
36+
if (contextDependencies.indexOf(contextPath) === -1) {
37+
contextDependencies.push(contextPath);
38+
}
39+
3340
debug(`found ${from}`);
3441

3542
// Check the ignore list

tests/index.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,22 @@ describe('apply function', () => {
472472
.then(done)
473473
.catch(done);
474474
});
475+
476+
it('adds the directory to the watch list when using glob', (done) => {
477+
run({
478+
patterns: [{
479+
from: 'directory/**/*'
480+
}]
481+
})
482+
.then((compilation) => {
483+
const absFrom = path.resolve(HELPER_DIR, 'directory');
484+
const absFromNested = path.resolve(HELPER_DIR, 'directory', 'nested');
485+
expect(compilation.contextDependencies).to.have.members([absFrom, absFromNested]);
486+
})
487+
.then(done)
488+
.catch(done);
489+
});
490+
475491
});
476492

477493
describe('with file in from', () => {
@@ -1196,9 +1212,9 @@ describe('apply function', () => {
11961212
}]
11971213
})
11981214
.then((compilation) => {
1199-
const absFrom = path.join(HELPER_DIR, 'directory');
1200-
1201-
expect(compilation.contextDependencies).to.have.members([absFrom]);
1215+
const absFrom = path.resolve(HELPER_DIR, 'directory');
1216+
const absFromNested = path.resolve(HELPER_DIR, 'directory', 'nested');
1217+
expect(compilation.contextDependencies).to.have.members([absFrom, absFromNested]);
12021218
})
12031219
.then(done)
12041220
.catch(done);

0 commit comments

Comments
 (0)