Skip to content

Commit

Permalink
fix: handles new files when you in watch mode (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Feb 18, 2019
1 parent 11c9aef commit 49a28f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/preProcessPattern.js
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions src/processPattern.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions test/CopyPlugin.test.js
Expand Up @@ -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: [
{
Expand All @@ -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)
Expand Down Expand Up @@ -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: [
{
Expand All @@ -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)
Expand Down

0 comments on commit 49a28f0

Please sign in to comment.