Skip to content

Commit 74e6d06

Browse files
test(deps): cover a barrel dependency that spells isLazy as a flag
The walk called every dependency carrying the name, so a foreign type holding a plain flag under it ended the build with a TypeError. The case hands a barrel one and fails on the previous guard.
1 parent bb87a7c commit 74e6d06

7 files changed

Lines changed: 100 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+
Skip a foreign dependency whose `isLazy` is a flag when walking a lazy barrel.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { missing, value } from "./lib";
2+
3+
it("should walk a barrel carrying a foreign dependency that spells isLazy as a flag", () => {
4+
expect(value).toBe(1);
5+
expect(missing).toBe(undefined);
6+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { value } from "./value.js";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "flagged-lib",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"sideEffects": false
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
3+
module.exports = [[/export 'missing'/]];
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"use strict";
2+
3+
const webpack = require("../../../../");
4+
const makeSerializable = require("../../../../lib/util/makeSerializable");
5+
6+
/**
7+
* @import {
8+
* ObjectDeserializerContext,
9+
* ObjectSerializerContext
10+
* } from "../../../../lib/serialization/ObjectMiddleware"
11+
*/
12+
13+
const { NullDependency } = webpack.dependencies;
14+
15+
// A dependency type of webpack's own spells `isLazy` as a method; a foreign one may
16+
// spell the same name as a plain flag, which the lazy-barrel walk must not call.
17+
class LazyFlagDependency extends NullDependency {
18+
constructor() {
19+
super();
20+
/** @type {{ isLazy: boolean }} */ (/** @type {unknown} */ (this)).isLazy =
21+
true;
22+
}
23+
24+
/**
25+
* Serializes this instance into the provided serializer context.
26+
* @param {ObjectSerializerContext} context context
27+
*/
28+
serialize(context) {
29+
context.write(this.isLazy);
30+
super.serialize(context);
31+
}
32+
33+
/**
34+
* Restores this instance from the provided deserializer context.
35+
* @param {ObjectDeserializerContext} context context
36+
*/
37+
deserialize(context) {
38+
/** @type {{ isLazy: boolean }} */ (/** @type {unknown} */ (this)).isLazy =
39+
/** @type {boolean} */ (context.read());
40+
super.deserialize(context);
41+
}
42+
}
43+
44+
makeSerializable(
45+
LazyFlagDependency,
46+
"test/configCases/lazy-barrel/custom-dependency-lazy-flag/webpack.config.js",
47+
"LazyFlagDependency"
48+
);
49+
50+
/** @type {import("../../../../").Configuration} */
51+
module.exports = {
52+
mode: "production",
53+
target: "web",
54+
devtool: false,
55+
optimization: {
56+
sideEffects: true,
57+
providedExports: true,
58+
usedExports: true,
59+
moduleIds: "named",
60+
minimize: false,
61+
concatenateModules: false
62+
},
63+
plugins: [
64+
(compiler) => {
65+
compiler.hooks.compilation.tap("Test", (compilation) => {
66+
compilation.dependencyTemplates.set(
67+
LazyFlagDependency,
68+
new NullDependency.Template()
69+
);
70+
compilation.hooks.succeedModule.tap("Test", (module) => {
71+
if (/lib[/\\]index\.js$/.test(module.identifier())) {
72+
module.addDependency(new LazyFlagDependency());
73+
}
74+
});
75+
});
76+
}
77+
]
78+
};

0 commit comments

Comments
 (0)