Repository: webpack-contrib/copy-webpack-plugin (js)

Issue:
Not copy new file in watch mode
I use 
```
new CopyWebpackPlugin([
    'res/**/*.*'
])
```
and
```
webpack -w --mode=development
```

When watching, if I create a new file (like `res/test.txt`), it would not copy to the output path.
I must restart webpack.

Pull request:
fix: handles new files when you in watch mode
<!--
  HOLY CRAP a Pull Request. We ❤️ those!

  If you remove or skip this template, you'll make the 🐼 sad and the mighty god
  of Github will appear and pile-drive the close button from a great height
  while making animal noises.

  Please place an x (no spaces!) in all [ ] that apply
-->

This PR contains a:

- [x] **bugfix**
- [ ] new **feature**
- [ ] **code refactor**
- [x] **test update** <!-- if bug or feature is checked, this should be too -->
- [ ] **typo fix**
- [ ] **metadata update**

### Motivation / Use-Case

fixes #252

### Breaking Changes

No

### Additional Info

No

Patch:
diff --git a/src/preProcessPattern.js b/src/preProcessPattern.js
index b0a9364..234249e 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 e7370ae..289f0ee 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


Test patch:
diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js
index 81415da..a332750 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)