Skip to content

Commit

Permalink
fix(processPattern): add glob directory context to `contextDependen…
Browse files Browse the repository at this point in the history
…cies` (#290)
  • Loading branch information
alan-agius4 authored and michael-ciniawsky committed Sep 28, 2018
1 parent 5474889 commit 5fa69db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/processPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import writeFile from './writeFile';
import isObject from './utils/isObject';

export default function processPattern(globalRef, pattern) {
const {info, debug, output, concurrency} = globalRef;
const {info, debug, output, concurrency, contextDependencies} = globalRef;
const globArgs = Object.assign({
cwd: pattern.context
}, pattern.fromArgs || {});
Expand All @@ -30,6 +30,13 @@ export default function processPattern(globalRef, pattern) {
file.relativeFrom = path.basename(file.relativeFrom);
}

// This is so webpack is able to watch the directory and when
// a new file is added it triggeres a rebuild
const contextPath = path.dirname(path.resolve(from));
if (contextDependencies.indexOf(contextPath) === -1) {
contextDependencies.push(contextPath);
}

debug(`found ${from}`);

// Check the ignore list
Expand Down
22 changes: 19 additions & 3 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,22 @@ describe('apply function', () => {
.then(done)
.catch(done);
});

it('adds the directory to the watch list when using glob', (done) => {
run({
patterns: [{
from: 'directory/**/*'
}]
})
.then((compilation) => {
const absFrom = path.resolve(HELPER_DIR, 'directory');
const absFromNested = path.resolve(HELPER_DIR, 'directory', 'nested');
expect(compilation.contextDependencies).to.have.members([absFrom, absFromNested]);
})
.then(done)
.catch(done);
});

});

describe('with file in from', () => {
Expand Down Expand Up @@ -1196,9 +1212,9 @@ describe('apply function', () => {
}]
})
.then((compilation) => {
const absFrom = path.join(HELPER_DIR, 'directory');

expect(compilation.contextDependencies).to.have.members([absFrom]);
const absFrom = path.resolve(HELPER_DIR, 'directory');
const absFromNested = path.resolve(HELPER_DIR, 'directory', 'nested');
expect(compilation.contextDependencies).to.have.members([absFrom, absFromNested]);
})
.then(done)
.catch(done);
Expand Down

0 comments on commit 5fa69db

Please sign in to comment.