Skip to content

Commit 49a28f0

Browse files
authoredFeb 18, 2019
fix: handles new files when you in watch mode (#333)
1 parent 11c9aef commit 49a28f0

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed
 

‎src/preProcessPattern.js

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export default function preProcessPattern(globalRef, pattern) {
9090
if (isGlob(pattern.from) || pattern.from.indexOf('*') !== -1) {
9191
pattern.fromType = 'glob';
9292
pattern.glob = escape(pattern.context, pattern.from);
93+
94+
// We need to add context directory as dependencies to avoid problems when new files added in directories
95+
// when we already in watch mode and this directories are not in context dependencies
96+
contextDependencies.add(pattern.context);
9397
} else {
9498
const msg = `unable to locate '${pattern.from}' at '${
9599
pattern.absoluteFrom

‎src/processPattern.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import path from 'path';
22

33
import globby from 'globby';
44
import pLimit from 'p-limit';
5-
import isGlob from 'is-glob';
65
import minimatch from 'minimatch';
76

87
import isObject from './utils/isObject';
98

109
export default function processPattern(globalRef, pattern) {
11-
const { info, debug, output, concurrency, contextDependencies } = globalRef;
10+
const { info, debug, output, concurrency } = globalRef;
1211
const globOptions = Object.assign(
1312
{
1413
cwd: pattern.context,
@@ -41,14 +40,6 @@ export default function processPattern(globalRef, pattern) {
4140
file.relativeFrom = path.basename(file.relativeFrom);
4241
}
4342

44-
// This is so webpack is able to watch the directory and when
45-
// a new file is added it triggeres a rebuild
46-
const contextPath = path.dirname(path.resolve(from));
47-
48-
if (isGlob(pattern.glob)) {
49-
contextDependencies.add(contextPath);
50-
}
51-
5243
debug(`found ${from}`);
5344

5445
// Check the ignore list

‎test/CopyPlugin.test.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ describe('apply function', () => {
623623
.catch(done);
624624
});
625625

626-
it('adds the directory to the watch list when using glob', (done) => {
626+
it('adds the context directory to the watch list when using glob', (done) => {
627627
run({
628628
patterns: [
629629
{
@@ -632,11 +632,8 @@ describe('apply function', () => {
632632
],
633633
})
634634
.then((compilation) => {
635-
const absFrom = path.resolve(HELPER_DIR, 'directory');
636-
const absFromNested = path.resolve(HELPER_DIR, 'directory', 'nested');
637-
638635
expect(Array.from(compilation.contextDependencies).sort()).toEqual(
639-
[absFrom, absFromNested].sort()
636+
[HELPER_DIR].sort()
640637
);
641638
})
642639
.then(done)
@@ -1540,7 +1537,7 @@ describe('apply function', () => {
15401537
.catch(done);
15411538
});
15421539

1543-
it('adds the directory to the watch list', (done) => {
1540+
it('adds the context directory to the watch list', (done) => {
15441541
run({
15451542
patterns: [
15461543
{
@@ -1550,9 +1547,8 @@ describe('apply function', () => {
15501547
})
15511548
.then((compilation) => {
15521549
const absFrom = path.resolve(HELPER_DIR, 'directory');
1553-
const absFromNested = path.resolve(HELPER_DIR, 'directory', 'nested');
15541550
expect(Array.from(compilation.contextDependencies).sort()).toEqual(
1555-
[absFrom, absFromNested].sort()
1551+
[absFrom].sort()
15561552
);
15571553
})
15581554
.then(done)

0 commit comments

Comments
 (0)
Please sign in to comment.