Skip to content

Commit befeee9

Browse files
authored
Merge pull request #14777 from webpack/bugfix/double-compilation-managed-path
fix double compilation with managed paths
2 parents eee5ffc + 200ab0e commit befeee9

File tree

14 files changed

+104
-2
lines changed

14 files changed

+104
-2
lines changed

lib/FileSystemInfo.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,9 @@ class FileSystemInfo {
22562256
for (const path of managedItems) {
22572257
const cache = this._managedItems.get(path);
22582258
if (cache !== undefined) {
2259-
managedFiles.add(join(this.fs, path, "package.json"));
2259+
if (cache !== "missing") {
2260+
managedFiles.add(join(this.fs, path, "package.json"));
2261+
}
22602262
managedItemInfo.set(path, cache);
22612263
} else {
22622264
jobs++;
@@ -2269,7 +2271,9 @@ class FileSystemInfo {
22692271
}
22702272
jobError();
22712273
} else if (entry) {
2272-
managedFiles.add(join(this.fs, path, "package.json"));
2274+
if (entry !== "missing") {
2275+
managedFiles.add(join(this.fs, path, "package.json"));
2276+
}
22732277
managedItemInfo.set(path, entry);
22742278
jobDone();
22752279
} else {

test/Watch.test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"use strict";
2+
3+
require("./helpers/warmup-webpack");
4+
5+
const path = require("path");
6+
const webpack = require("..");
7+
const { createFsFromVolume, Volume } = require("memfs");
8+
9+
describe("Watch", () => {
10+
jest.setTimeout(10000);
11+
12+
it("should only compile a single time", done => {
13+
let counterBeforeCompile = 0;
14+
let counterDone = 0;
15+
let counterHandler = 0;
16+
const compiler = webpack(
17+
{
18+
context: path.resolve(__dirname, "fixtures/watch"),
19+
watch: true,
20+
mode: "development",
21+
snapshot: {
22+
managedPaths: [/^(.+?[\\/]node_modules[\\/])/]
23+
},
24+
experiments: {
25+
futureDefaults: true
26+
},
27+
module: {
28+
// unsafeCache: false,
29+
rules: [
30+
{
31+
test: /\.js$/,
32+
use: "some-loader"
33+
}
34+
]
35+
},
36+
plugins: [
37+
c => {
38+
c.hooks.beforeCompile.tap("test", () => {
39+
counterBeforeCompile++;
40+
});
41+
c.hooks.done.tap("test", () => {
42+
counterDone++;
43+
});
44+
}
45+
]
46+
},
47+
(err, stats) => {
48+
if (err) return done(err);
49+
if (stats.hasErrors()) return done(new Error(stats.toString()));
50+
counterHandler++;
51+
}
52+
);
53+
compiler.outputFileSystem = createFsFromVolume(new Volume());
54+
setTimeout(() => {
55+
expect(counterBeforeCompile).toBe(1);
56+
expect(counterDone).toBe(1);
57+
expect(counterHandler).toBe(1);
58+
compiler.close(done);
59+
}, 5000);
60+
});
61+
});

test/fixtures/watch/node_modules/inline-loader/index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/watch/node_modules/inline-loader/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/watch/node_modules/nested-package1/index.js

Whitespace-only changes.

test/fixtures/watch/node_modules/nested-package1/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/watch/node_modules/package/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/watch/node_modules/package/node_modules/nested-package2/index.js

Whitespace-only changes.

test/fixtures/watch/node_modules/package/node_modules/nested-package2/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/watch/node_modules/package/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy