Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(processPattern): add glob directory context to contextDependencies #290

Merged
merged 1 commit into from Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/processPattern.js
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
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