From 56709263bf210388191db4ee4f4def54aa0d661e Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 18 Oct 2018 23:53:08 +0200 Subject: [PATCH] fix(processPattern): don't add `'glob'` as directory when it is a file (`contextDependencies`) (#296) --- src/processPattern.js | 3 ++- tests/index.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/processPattern.js b/src/processPattern.js index 09592092..e6fb3d41 100644 --- a/src/processPattern.js +++ b/src/processPattern.js @@ -1,5 +1,6 @@ import globby from 'globby'; import pLimit from 'p-limit'; +import isGlob from 'is-glob'; import path from 'path'; import minimatch from 'minimatch'; import writeFile from './writeFile'; @@ -33,7 +34,7 @@ export default function processPattern(globalRef, pattern) { // 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) { + if (contextDependencies.indexOf(contextPath) === -1 && isGlob(pattern.glob)) { contextDependencies.push(contextPath); } diff --git a/tests/index.js b/tests/index.js index c65e21ec..071ead0f 100644 --- a/tests/index.js +++ b/tests/index.js @@ -488,6 +488,21 @@ describe('apply function', () => { .catch(done); }); + it('does not add the directory to the watch list when glob is a file', (done) => { + run({ + patterns: [{ + from: { + glob: 'directory/directoryfile.txt' + } + }] + }) + .then((compilation) => { + const absFrom = path.resolve(HELPER_DIR, 'directory'); + expect(compilation.contextDependencies).to.not.have.members([absFrom]); + }) + .then(done) + .catch(done); + }); }); describe('with file in from', () => {