Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handles new files when you in watch mode #333

Merged
merged 1 commit into from Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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