Repository: webpack-contrib/copy-webpack-plugin
Pull request #558 (2020-11-19 16:06:21)

fix: watching directories
<!--
  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

adding files to file dependencies for dir type too

### Breaking Changes

No

### Additional Info

No

codecov[bot]: # [Codecov](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558?src=pr&el=h1) Report
> Merging [#558](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558?src=pr&el=desc) (fcc3c69) into [master](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/commit/521572190800ece87756a4a6cf17f43753092408?el=desc) (5215721) will **decrease** coverage by `15.87%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558/graphs/tree.svg?width=650&height=150&src=pr&token=fEoU9iBFGL)](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           master     #558       +/-   ##
===========================================
- Coverage   91.11%   75.23%   -15.88%     
===========================================
  Files           3        3               
  Lines         315      315               
  Branches       96       96               
===========================================
- Hits          287      237       -50     
- Misses         28       70       +42     
- Partials        0        8        +8     
```


| [Impacted Files](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/index.js](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558/diff?src=pr&el=tree#diff-c3JjL2luZGV4Lmpz) | `74.41% <100.00%> (-16.62%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558?src=pr&el=footer). Last update [5215721...fcc3c69](https://codecov.io/gh/webpack-contrib/copy-webpack-plugin/pull/558?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/index.js b/src/index.js
index 488d53c..1b9bc43 100644
--- a/src/index.js
+++ b/src/index.js
@@ -351,8 +351,8 @@ class CopyPlugin {
             force: pattern.force,
           };
 
-          // If this came from a glob, add it to the file dependencies
-          if (pattern.fromType === "glob") {
+          // If this came from a glob or dir, add it to the file dependencies
+          if (pattern.fromType === "dir" || pattern.fromType === "glob") {
             compilation.fileDependencies.add(absoluteFilename);
 
             logger.debug(`added '${absoluteFilename}' as a file dependency`);


Test patch:
diff --git a/test/__snapshots__/CopyPlugin.test.js.snap b/test/__snapshots__/CopyPlugin.test.js.snap
index b37e63f..6f28f0a 100644
--- a/test/__snapshots__/CopyPlugin.test.js.snap
+++ b/test/__snapshots__/CopyPlugin.test.js.snap
@@ -176,6 +176,10 @@ exports[`CopyPlugin logging should logging when "from" is a directory: logs 1`]
 Object {
   "logs": Array [
     "added './fixtures/directory' as a context dependency",
+    "added './fixtures/directory/.dottedfile' as a file dependency",
+    "added './fixtures/directory/directoryfile.txt' as a file dependency",
+    "added './fixtures/directory/nested/deep-nested/deepnested.txt' as a file dependency",
+    "added './fixtures/directory/nested/nestedfile.txt' as a file dependency",
     "begin globbing './fixtures/directory/**/*'...",
     "determined './fixtures/directory' is a directory",
     "determined that './fixtures/directory/.dottedfile' should write to '.dottedfile'",