Skip to content

Commit 99a3100

Browse files
committed
fix(loaders): preserve resolution dependencies across rebuilds
1 parent 63f2330 commit 99a3100

13 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Preserve loader resolution dependencies across cached rebuilds.

‎lib/Compilation.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,30 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
24642464
context
24652465
},
24662466
(err, factoryResult) => {
2467+
// Loader-created modules have no origin connection to resolve again.
2468+
// Preserve their resolution dependencies in the caller's build snapshot.
2469+
if (
2470+
factoryResult &&
2471+
!connectOrigin &&
2472+
originModule &&
2473+
originModule.buildInfo &&
2474+
this.buildQueue.isProcessing(originModule)
2475+
) {
2476+
for (const key of /** @type {const} */ ([
2477+
"fileDependencies",
2478+
"contextDependencies",
2479+
"missingDependencies"
2480+
])) {
2481+
const dependencies = factoryResult[key];
2482+
if (dependencies) {
2483+
let target = originModule.buildInfo[key];
2484+
if (target === undefined) {
2485+
originModule.buildInfo[key] = target = new LazySet();
2486+
}
2487+
target.addAll(dependencies);
2488+
}
2489+
}
2490+
}
24672491
const applyFactoryResultDependencies = () => {
24682492
const { fileDependencies, contextDependencies, missingDependencies } =
24692493
/** @type {ModuleFactoryResult} */ (factoryResult);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "directory";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const value = require("./value.generated");
2+
const step = require("./step");
3+
4+
it("should invalidate loader imports when resolution changes", () => {
5+
expect(step).toBe(+WATCH_STEP);
6+
expect(value).toBe(step < 2 ? "directory" : "file");
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import("../../../../..").LoaderDefinition} */
2+
module.exports = function () {
3+
const callback = this.async();
4+
this.loadModule("./choice", (error, source) => {
5+
callback(error, source);
6+
});
7+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import("../../../../..").LoaderDefinitionFunction} */
2+
module.exports = async function () {
3+
const result = await this.importModule("./choice");
4+
return `module.exports = ${JSON.stringify(result)};`;
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 0;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generated
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "file";

0 commit comments

Comments
 (0)