From 49a28f07ea7fb235098a472e813ef2f96de4930e Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Mon, 18 Feb 2019 17:45:55 +0300 Subject: [PATCH] fix: handles new files when you in watch mode (#333) --- src/preProcessPattern.js | 4 ++++ src/processPattern.js | 11 +---------- test/CopyPlugin.test.js | 12 ++++-------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/preProcessPattern.js b/src/preProcessPattern.js index b0a9364b..234249e1 100644 --- a/src/preProcessPattern.js +++ b/src/preProcessPattern.js @@ -90,6 +90,10 @@ export default function preProcessPattern(globalRef, pattern) { if (isGlob(pattern.from) || pattern.from.indexOf('*') !== -1) { pattern.fromType = 'glob'; pattern.glob = escape(pattern.context, pattern.from); + + // We need to add context directory as dependencies to avoid problems when new files added in directories + // when we already in watch mode and this directories are not in context dependencies + contextDependencies.add(pattern.context); } else { const msg = `unable to locate '${pattern.from}' at '${ pattern.absoluteFrom diff --git a/src/processPattern.js b/src/processPattern.js index e7370ae1..289f0ee2 100644 --- a/src/processPattern.js +++ b/src/processPattern.js @@ -2,13 +2,12 @@ import path from 'path'; import globby from 'globby'; import pLimit from 'p-limit'; -import isGlob from 'is-glob'; import minimatch from 'minimatch'; import isObject from './utils/isObject'; export default function processPattern(globalRef, pattern) { - const { info, debug, output, concurrency, contextDependencies } = globalRef; + const { info, debug, output, concurrency } = globalRef; const globOptions = Object.assign( { cwd: pattern.context, @@ -41,14 +40,6 @@ 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 (isGlob(pattern.glob)) { - contextDependencies.add(contextPath); - } - debug(`found ${from}`); // Check the ignore list diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index 81415da4..a332750f 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -623,7 +623,7 @@ describe('apply function', () => { .catch(done); }); - it('adds the directory to the watch list when using glob', (done) => { + it('adds the context directory to the watch list when using glob', (done) => { run({ patterns: [ { @@ -632,11 +632,8 @@ describe('apply function', () => { ], }) .then((compilation) => { - const absFrom = path.resolve(HELPER_DIR, 'directory'); - const absFromNested = path.resolve(HELPER_DIR, 'directory', 'nested'); - expect(Array.from(compilation.contextDependencies).sort()).toEqual( - [absFrom, absFromNested].sort() + [HELPER_DIR].sort() ); }) .then(done) @@ -1540,7 +1537,7 @@ describe('apply function', () => { .catch(done); }); - it('adds the directory to the watch list', (done) => { + it('adds the context directory to the watch list', (done) => { run({ patterns: [ { @@ -1550,9 +1547,8 @@ describe('apply function', () => { }) .then((compilation) => { const absFrom = path.resolve(HELPER_DIR, 'directory'); - const absFromNested = path.resolve(HELPER_DIR, 'directory', 'nested'); expect(Array.from(compilation.contextDependencies).sort()).toEqual( - [absFrom, absFromNested].sort() + [absFrom].sort() ); }) .then(done)