From b913eb4cd6bb7bcbad0e837eb3a8c551d3b45214 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 10 Oct 2018 12:58:46 +0200 Subject: [PATCH] fix: don't add directiory to conext dependencies when `glob` is a file In some cases we might have someone like this which in that cause we wouldn't want to add the parent directory as a webpack context dependencies ``` { ignore: [ '.gitkeep', '**/.DS_Store', '**/Thumbs.db' ], from: { glob: 'favicon.ico', dot: true }, toType: 'dir', fromType: 'glob' } ``` --- 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', () => {