webpack 5.77.0 → 5.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/bin/webpack.js +0 -0
- package/lib/APIPlugin.js +25 -18
- package/lib/CompatibilityPlugin.js +53 -52
- package/lib/ConstPlugin.js +22 -15
- package/lib/ContextModule.js +3 -2
- package/lib/DefinePlugin.js +44 -36
- package/lib/DelegatedModule.js +2 -1
- package/lib/DllModule.js +2 -1
- package/lib/ErrorHelpers.js +61 -22
- package/lib/ExportsInfoApiPlugin.js +16 -9
- package/lib/ExternalModule.js +2 -1
- package/lib/FlagAllModulesAsUsedPlugin.js +22 -27
- package/lib/FlagDependencyExportsPlugin.js +336 -348
- package/lib/FlagDependencyUsagePlugin.js +6 -8
- package/lib/FlagEntryExportAsUsedPlugin.js +22 -23
- package/lib/HotModuleReplacementPlugin.js +50 -45
- package/lib/JavascriptMetaInfoPlugin.js +16 -9
- package/lib/ModuleTypeConstants.js +50 -0
- package/lib/NodeStuffPlugin.js +35 -31
- package/lib/NormalModule.js +2 -1
- package/lib/NormalModuleFactory.js +7 -1
- package/lib/ProvidePlugin.js +17 -10
- package/lib/RawModule.js +2 -1
- package/lib/RequireJsStuffPlugin.js +15 -15
- package/lib/UseStrictPlugin.js +15 -8
- package/lib/WebpackIsIncludedPlugin.js +16 -9
- package/lib/config/defaults.js +16 -8
- package/lib/config/normalization.js +4 -0
- package/lib/container/ContainerEntryModule.js +2 -1
- package/lib/css/CssParser.js +22 -2
- package/lib/debug/ProfilingPlugin.js +20 -12
- package/lib/dependencies/AMDPlugin.js +26 -20
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -4
- package/lib/dependencies/CommonJsPlugin.js +29 -25
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyModulesPlugin.js +11 -5
- package/lib/dependencies/ImportMetaContextPlugin.js +11 -5
- package/lib/dependencies/ImportMetaPlugin.js +26 -20
- package/lib/dependencies/ImportPlugin.js +14 -7
- package/lib/dependencies/RequireContextPlugin.js +12 -6
- package/lib/dependencies/RequireEnsurePlugin.js +13 -7
- package/lib/dependencies/RequireIncludePlugin.js +11 -5
- package/lib/dependencies/SystemPlugin.js +21 -15
- package/lib/dependencies/URLPlugin.js +15 -9
- package/lib/dependencies/WorkerPlugin.js +14 -8
- package/lib/javascript/JavascriptModulesPlugin.js +157 -164
- package/lib/json/JsonModulesPlugin.js +13 -5
- package/lib/library/AmdLibraryPlugin.js +22 -6
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
- package/lib/optimize/ConcatenatedModule.js +2 -1
- package/lib/optimize/InnerGraphPlugin.js +47 -46
- package/lib/optimize/SideEffectsFlagPlugin.js +43 -43
- package/lib/sharing/ConsumeSharedPlugin.js +4 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +9 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +42 -43
- package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +40 -40
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +18 -0
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +8 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
- package/types.d.ts +10 -0
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { JSON_MODULE_TYPE } = require("../ModuleTypeConstants");
|
8
9
|
const createSchemaValidation = require("../util/create-schema-validation");
|
9
10
|
const JsonGenerator = require("./JsonGenerator");
|
10
11
|
const JsonParser = require("./JsonParser");
|
@@ -20,26 +21,33 @@ const validate = createSchemaValidation(
|
|
20
21
|
}
|
21
22
|
);
|
22
23
|
|
24
|
+
const PLUGIN_NAME = "JsonModulesPlugin";
|
25
|
+
|
26
|
+
/**
|
27
|
+
* The JsonModulesPlugin is the entrypoint plugin for the json modules feature.
|
28
|
+
* It adds the json module type to the compiler and registers the json parser and generator.
|
29
|
+
*/
|
23
30
|
class JsonModulesPlugin {
|
24
31
|
/**
|
25
32
|
* Apply the plugin
|
26
33
|
* @param {Compiler} compiler the compiler instance
|
27
34
|
* @returns {void}
|
35
|
+
*
|
28
36
|
*/
|
29
37
|
apply(compiler) {
|
30
38
|
compiler.hooks.compilation.tap(
|
31
|
-
|
39
|
+
PLUGIN_NAME,
|
32
40
|
(compilation, { normalModuleFactory }) => {
|
33
41
|
normalModuleFactory.hooks.createParser
|
34
|
-
.for(
|
35
|
-
.tap(
|
42
|
+
.for(JSON_MODULE_TYPE)
|
43
|
+
.tap(PLUGIN_NAME, parserOptions => {
|
36
44
|
validate(parserOptions);
|
37
45
|
|
38
46
|
return new JsonParser(parserOptions);
|
39
47
|
});
|
40
48
|
normalModuleFactory.hooks.createGenerator
|
41
|
-
.for(
|
42
|
-
.tap(
|
49
|
+
.for(JSON_MODULE_TYPE)
|
50
|
+
.tap(PLUGIN_NAME, () => {
|
43
51
|
return new JsonGenerator();
|
44
52
|
});
|
45
53
|
}
|
@@ -29,6 +29,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
29
29
|
/**
|
30
30
|
* @typedef {Object} AmdLibraryPluginParsed
|
31
31
|
* @property {string} name
|
32
|
+
* @property {string} amdContainer
|
32
33
|
*/
|
33
34
|
|
34
35
|
/**
|
@@ -52,7 +53,7 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
52
53
|
* @returns {T | false} preprocess as needed by overriding
|
53
54
|
*/
|
54
55
|
parseOptions(library) {
|
55
|
-
const { name } = library;
|
56
|
+
const { name, amdContainer } = library;
|
56
57
|
if (this.requireAsWrapper) {
|
57
58
|
if (name) {
|
58
59
|
throw new Error(
|
@@ -67,7 +68,8 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
67
68
|
}
|
68
69
|
}
|
69
70
|
return {
|
70
|
-
name: /** @type {string=} */ (name)
|
71
|
+
name: /** @type {string=} */ (name),
|
72
|
+
amdContainer: /** @type {string=} */ (amdContainer)
|
71
73
|
};
|
72
74
|
}
|
73
75
|
|
@@ -111,9 +113,14 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
111
113
|
(iife || !chunk.hasRuntime() ? " return " : "\n");
|
112
114
|
const fnEnd = iife ? ";\n}" : "\n}";
|
113
115
|
|
116
|
+
let amdContainerPrefix = "";
|
117
|
+
if (options.amdContainer) {
|
118
|
+
amdContainerPrefix = `${options.amdContainer}.`;
|
119
|
+
}
|
120
|
+
|
114
121
|
if (this.requireAsWrapper) {
|
115
122
|
return new ConcatSource(
|
116
|
-
|
123
|
+
`${amdContainerPrefix}require(${externalsDepsArray}, ${fnStart}`,
|
117
124
|
source,
|
118
125
|
`${fnEnd});`
|
119
126
|
);
|
@@ -123,18 +130,24 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
123
130
|
});
|
124
131
|
|
125
132
|
return new ConcatSource(
|
126
|
-
|
133
|
+
`${amdContainerPrefix}define(${JSON.stringify(
|
134
|
+
name
|
135
|
+
)}, ${externalsDepsArray}, ${fnStart}`,
|
127
136
|
source,
|
128
137
|
`${fnEnd});`
|
129
138
|
);
|
130
139
|
} else if (externalsArguments) {
|
131
140
|
return new ConcatSource(
|
132
|
-
|
141
|
+
`${amdContainerPrefix}define(${externalsDepsArray}, ${fnStart}`,
|
133
142
|
source,
|
134
143
|
`${fnEnd});`
|
135
144
|
);
|
136
145
|
} else {
|
137
|
-
return new ConcatSource(
|
146
|
+
return new ConcatSource(
|
147
|
+
`${amdContainerPrefix}define(${fnStart}`,
|
148
|
+
source,
|
149
|
+
`${fnEnd});`
|
150
|
+
);
|
138
151
|
}
|
139
152
|
}
|
140
153
|
|
@@ -155,6 +168,9 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
155
168
|
chunk
|
156
169
|
});
|
157
170
|
hash.update(name);
|
171
|
+
} else if (options.amdContainer) {
|
172
|
+
hash.update("amdContainer");
|
173
|
+
hash.update(options.amdContainer);
|
158
174
|
}
|
159
175
|
}
|
160
176
|
}
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants");
|
8
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
10
|
const Template = require("../Template");
|
10
11
|
const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
|
@@ -85,7 +86,7 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
85
86
|
if (
|
86
87
|
!chunkGraph.hasModuleInGraph(
|
87
88
|
chunk,
|
88
|
-
m => m.type ===
|
89
|
+
m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
|
89
90
|
)
|
90
91
|
) {
|
91
92
|
return;
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { WEBASSEMBLY_MODULE_TYPE_SYNC } = require("../ModuleTypeConstants");
|
8
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
10
|
const Template = require("../Template");
|
10
11
|
const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRuntimeModule");
|
@@ -69,7 +70,7 @@ class ReadFileCompileWasmPlugin {
|
|
69
70
|
if (
|
70
71
|
!chunkGraph.hasModuleInGraph(
|
71
72
|
chunk,
|
72
|
-
m => m.type ===
|
73
|
+
m => m.type === WEBASSEMBLY_MODULE_TYPE_SYNC
|
73
74
|
)
|
74
75
|
) {
|
75
76
|
return;
|
@@ -15,6 +15,7 @@ const {
|
|
15
15
|
const ConcatenationScope = require("../ConcatenationScope");
|
16
16
|
const { UsageState } = require("../ExportsInfo");
|
17
17
|
const Module = require("../Module");
|
18
|
+
const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
|
18
19
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
19
20
|
const Template = require("../Template");
|
20
21
|
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
|
@@ -683,7 +684,7 @@ class ConcatenatedModule extends Module {
|
|
683
684
|
* @param {Set<Module>=} options.modules all concatenated modules
|
684
685
|
*/
|
685
686
|
constructor({ identifier, rootModule, modules, runtime }) {
|
686
|
-
super(
|
687
|
+
super(JAVASCRIPT_MODULE_TYPE_ESM, null, rootModule && rootModule.layer);
|
687
688
|
|
688
689
|
// Info from Factory
|
689
690
|
/** @type {string} */
|
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
11
|
+
} = require("../ModuleTypeConstants");
|
8
12
|
const PureExpressionDependency = require("../dependencies/PureExpressionDependency");
|
9
13
|
const InnerGraph = require("./InnerGraph");
|
10
14
|
|
@@ -21,6 +25,8 @@ const InnerGraph = require("./InnerGraph");
|
|
21
25
|
|
22
26
|
const { topLevelSymbolTag } = InnerGraph;
|
23
27
|
|
28
|
+
const PLUGIN_NAME = "InnerGraphPlugin";
|
29
|
+
|
24
30
|
class InnerGraphPlugin {
|
25
31
|
/**
|
26
32
|
* Apply the plugin
|
@@ -29,7 +35,7 @@ class InnerGraphPlugin {
|
|
29
35
|
*/
|
30
36
|
apply(compiler) {
|
31
37
|
compiler.hooks.compilation.tap(
|
32
|
-
|
38
|
+
PLUGIN_NAME,
|
33
39
|
(compilation, { normalModuleFactory }) => {
|
34
40
|
const logger = compilation.getLogger("webpack.InnerGraphPlugin");
|
35
41
|
|
@@ -61,11 +67,11 @@ class InnerGraphPlugin {
|
|
61
67
|
});
|
62
68
|
};
|
63
69
|
|
64
|
-
parser.hooks.program.tap(
|
70
|
+
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
65
71
|
InnerGraph.enable(parser.state);
|
66
72
|
});
|
67
73
|
|
68
|
-
parser.hooks.finish.tap(
|
74
|
+
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
69
75
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
70
76
|
|
71
77
|
logger.time("infer dependency usage");
|
@@ -97,7 +103,7 @@ class InnerGraphPlugin {
|
|
97
103
|
|
98
104
|
// The following hooks are used during prewalking:
|
99
105
|
|
100
|
-
parser.hooks.preStatement.tap(
|
106
|
+
parser.hooks.preStatement.tap(PLUGIN_NAME, statement => {
|
101
107
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
102
108
|
|
103
109
|
if (parser.scope.topLevelScope === true) {
|
@@ -110,7 +116,7 @@ class InnerGraphPlugin {
|
|
110
116
|
}
|
111
117
|
});
|
112
118
|
|
113
|
-
parser.hooks.blockPreStatement.tap(
|
119
|
+
parser.hooks.blockPreStatement.tap(PLUGIN_NAME, statement => {
|
114
120
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
115
121
|
|
116
122
|
if (parser.scope.topLevelScope === true) {
|
@@ -143,33 +149,30 @@ class InnerGraphPlugin {
|
|
143
149
|
}
|
144
150
|
});
|
145
151
|
|
146
|
-
parser.hooks.preDeclarator.tap(
|
147
|
-
|
148
|
-
(
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
) {
|
155
|
-
const
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
) {
|
166
|
-
pureDeclarators.add(decl);
|
167
|
-
}
|
168
|
-
return true;
|
152
|
+
parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl, statement) => {
|
153
|
+
if (!InnerGraph.isEnabled(parser.state)) return;
|
154
|
+
if (
|
155
|
+
parser.scope.topLevelScope === true &&
|
156
|
+
decl.init &&
|
157
|
+
decl.id.type === "Identifier"
|
158
|
+
) {
|
159
|
+
const name = decl.id.name;
|
160
|
+
if (decl.init.type === "ClassExpression") {
|
161
|
+
const fn = InnerGraph.tagTopLevelSymbol(parser, name);
|
162
|
+
classWithTopLevelSymbol.set(decl.init, fn);
|
163
|
+
} else if (parser.isPure(decl.init, decl.id.range[1])) {
|
164
|
+
const fn = InnerGraph.tagTopLevelSymbol(parser, name);
|
165
|
+
declWithTopLevelSymbol.set(decl, fn);
|
166
|
+
if (
|
167
|
+
!decl.init.type.endsWith("FunctionExpression") &&
|
168
|
+
decl.init.type !== "Literal"
|
169
|
+
) {
|
170
|
+
pureDeclarators.add(decl);
|
169
171
|
}
|
172
|
+
return true;
|
170
173
|
}
|
171
174
|
}
|
172
|
-
);
|
175
|
+
});
|
173
176
|
|
174
177
|
// During real walking we set the TopLevelSymbol state to the assigned
|
175
178
|
// TopLevelSymbol by using the fill datastructures.
|
@@ -187,7 +190,7 @@ class InnerGraphPlugin {
|
|
187
190
|
|
188
191
|
// The following hooks are called during walking:
|
189
192
|
|
190
|
-
parser.hooks.statement.tap(
|
193
|
+
parser.hooks.statement.tap(PLUGIN_NAME, statement => {
|
191
194
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
192
195
|
if (parser.scope.topLevelScope === true) {
|
193
196
|
InnerGraph.setTopLevelSymbol(parser.state, undefined);
|
@@ -219,7 +222,7 @@ class InnerGraphPlugin {
|
|
219
222
|
});
|
220
223
|
|
221
224
|
parser.hooks.classExtendsExpression.tap(
|
222
|
-
|
225
|
+
PLUGIN_NAME,
|
223
226
|
(expr, statement) => {
|
224
227
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
225
228
|
if (parser.scope.topLevelScope === true) {
|
@@ -239,7 +242,7 @@ class InnerGraphPlugin {
|
|
239
242
|
);
|
240
243
|
|
241
244
|
parser.hooks.classBodyElement.tap(
|
242
|
-
|
245
|
+
PLUGIN_NAME,
|
243
246
|
(element, classDefinition) => {
|
244
247
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
245
248
|
if (parser.scope.topLevelScope === true) {
|
@@ -252,7 +255,7 @@ class InnerGraphPlugin {
|
|
252
255
|
);
|
253
256
|
|
254
257
|
parser.hooks.classBodyValue.tap(
|
255
|
-
|
258
|
+
PLUGIN_NAME,
|
256
259
|
(expression, element, classDefinition) => {
|
257
260
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
258
261
|
if (parser.scope.topLevelScope === true) {
|
@@ -292,7 +295,7 @@ class InnerGraphPlugin {
|
|
292
295
|
}
|
293
296
|
);
|
294
297
|
|
295
|
-
parser.hooks.declarator.tap(
|
298
|
+
parser.hooks.declarator.tap(PLUGIN_NAME, (decl, statement) => {
|
296
299
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
297
300
|
const fn = declWithTopLevelSymbol.get(decl);
|
298
301
|
|
@@ -330,7 +333,7 @@ class InnerGraphPlugin {
|
|
330
333
|
|
331
334
|
parser.hooks.expression
|
332
335
|
.for(topLevelSymbolTag)
|
333
|
-
.tap(
|
336
|
+
.tap(PLUGIN_NAME, () => {
|
334
337
|
const topLevelSymbol = /** @type {TopLevelSymbol} */ (
|
335
338
|
parser.currentTagData
|
336
339
|
);
|
@@ -343,21 +346,19 @@ class InnerGraphPlugin {
|
|
343
346
|
currentTopLevelSymbol || true
|
344
347
|
);
|
345
348
|
});
|
346
|
-
parser.hooks.assign
|
347
|
-
.
|
348
|
-
.
|
349
|
-
|
350
|
-
if (expr.operator === "=") return true;
|
351
|
-
});
|
349
|
+
parser.hooks.assign.for(topLevelSymbolTag).tap(PLUGIN_NAME, expr => {
|
350
|
+
if (!InnerGraph.isEnabled(parser.state)) return;
|
351
|
+
if (expr.operator === "=") return true;
|
352
|
+
});
|
352
353
|
};
|
353
354
|
normalModuleFactory.hooks.parser
|
354
|
-
.for(
|
355
|
-
.tap(
|
355
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
356
|
+
.tap(PLUGIN_NAME, handler);
|
356
357
|
normalModuleFactory.hooks.parser
|
357
|
-
.for(
|
358
|
-
.tap(
|
358
|
+
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
359
|
+
.tap(PLUGIN_NAME, handler);
|
359
360
|
|
360
|
-
compilation.hooks.finishModules.tap(
|
361
|
+
compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
|
361
362
|
logger.timeAggregateEnd("infer dependency usage");
|
362
363
|
});
|
363
364
|
}
|
@@ -6,6 +6,11 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const glob2regexp = require("glob-to-regexp");
|
9
|
+
const {
|
10
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
11
|
+
JAVASCRIPT_MODULE_TYPE_ESM,
|
12
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
13
|
+
} = require("../ModuleTypeConstants");
|
9
14
|
const { STAGE_DEFAULT } = require("../OptimizationStages");
|
10
15
|
const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
|
11
16
|
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
|
@@ -50,6 +55,8 @@ const globToRegexp = (glob, cache) => {
|
|
50
55
|
return regexp;
|
51
56
|
};
|
52
57
|
|
58
|
+
const PLUGIN_NAME = "SideEffectsFlagPlugin";
|
59
|
+
|
53
60
|
class SideEffectsFlagPlugin {
|
54
61
|
/**
|
55
62
|
* @param {boolean} analyseSource analyse source code for side effects
|
@@ -69,48 +76,41 @@ class SideEffectsFlagPlugin {
|
|
69
76
|
globToRegexpCache.set(compiler.root, cache);
|
70
77
|
}
|
71
78
|
compiler.hooks.compilation.tap(
|
72
|
-
|
79
|
+
PLUGIN_NAME,
|
73
80
|
(compilation, { normalModuleFactory }) => {
|
74
81
|
const moduleGraph = compilation.moduleGraph;
|
75
|
-
normalModuleFactory.hooks.module.tap(
|
76
|
-
|
77
|
-
(
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
) {
|
84
|
-
const sideEffects = resolveData.descriptionFileData.sideEffects;
|
85
|
-
if (sideEffects !== undefined) {
|
86
|
-
if (module.factoryMeta === undefined) {
|
87
|
-
module.factoryMeta = {};
|
88
|
-
}
|
89
|
-
const hasSideEffects =
|
90
|
-
SideEffectsFlagPlugin.moduleHasSideEffects(
|
91
|
-
resolveData.relativePath,
|
92
|
-
sideEffects,
|
93
|
-
cache
|
94
|
-
);
|
95
|
-
module.factoryMeta.sideEffectFree = !hasSideEffects;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
return module;
|
100
|
-
}
|
101
|
-
);
|
102
|
-
normalModuleFactory.hooks.module.tap(
|
103
|
-
"SideEffectsFlagPlugin",
|
104
|
-
(module, data) => {
|
105
|
-
if (typeof data.settings.sideEffects === "boolean") {
|
82
|
+
normalModuleFactory.hooks.module.tap(PLUGIN_NAME, (module, data) => {
|
83
|
+
const resolveData = data.resourceResolveData;
|
84
|
+
if (
|
85
|
+
resolveData &&
|
86
|
+
resolveData.descriptionFileData &&
|
87
|
+
resolveData.relativePath
|
88
|
+
) {
|
89
|
+
const sideEffects = resolveData.descriptionFileData.sideEffects;
|
90
|
+
if (sideEffects !== undefined) {
|
106
91
|
if (module.factoryMeta === undefined) {
|
107
92
|
module.factoryMeta = {};
|
108
93
|
}
|
109
|
-
|
94
|
+
const hasSideEffects = SideEffectsFlagPlugin.moduleHasSideEffects(
|
95
|
+
resolveData.relativePath,
|
96
|
+
sideEffects,
|
97
|
+
cache
|
98
|
+
);
|
99
|
+
module.factoryMeta.sideEffectFree = !hasSideEffects;
|
110
100
|
}
|
111
|
-
return module;
|
112
101
|
}
|
113
|
-
|
102
|
+
|
103
|
+
return module;
|
104
|
+
});
|
105
|
+
normalModuleFactory.hooks.module.tap(PLUGIN_NAME, (module, data) => {
|
106
|
+
if (typeof data.settings.sideEffects === "boolean") {
|
107
|
+
if (module.factoryMeta === undefined) {
|
108
|
+
module.factoryMeta = {};
|
109
|
+
}
|
110
|
+
module.factoryMeta.sideEffectFree = !data.settings.sideEffects;
|
111
|
+
}
|
112
|
+
return module;
|
113
|
+
});
|
114
114
|
if (this._analyseSource) {
|
115
115
|
/**
|
116
116
|
* @param {JavascriptParser} parser the parser
|
@@ -118,11 +118,11 @@ class SideEffectsFlagPlugin {
|
|
118
118
|
*/
|
119
119
|
const parserHandler = parser => {
|
120
120
|
let sideEffectsStatement;
|
121
|
-
parser.hooks.program.tap(
|
121
|
+
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
122
122
|
sideEffectsStatement = undefined;
|
123
123
|
});
|
124
124
|
parser.hooks.statement.tap(
|
125
|
-
{ name:
|
125
|
+
{ name: PLUGIN_NAME, stage: -100 },
|
126
126
|
statement => {
|
127
127
|
if (sideEffectsStatement) return;
|
128
128
|
if (parser.scope.topLevelScope !== true) return;
|
@@ -203,7 +203,7 @@ class SideEffectsFlagPlugin {
|
|
203
203
|
}
|
204
204
|
}
|
205
205
|
);
|
206
|
-
parser.hooks.finish.tap(
|
206
|
+
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
207
207
|
if (sideEffectsStatement === undefined) {
|
208
208
|
parser.state.module.buildMeta.sideEffectFree = true;
|
209
209
|
} else {
|
@@ -220,18 +220,18 @@ class SideEffectsFlagPlugin {
|
|
220
220
|
});
|
221
221
|
};
|
222
222
|
for (const key of [
|
223
|
-
|
224
|
-
|
225
|
-
|
223
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
224
|
+
JAVASCRIPT_MODULE_TYPE_ESM,
|
225
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
226
226
|
]) {
|
227
227
|
normalModuleFactory.hooks.parser
|
228
228
|
.for(key)
|
229
|
-
.tap(
|
229
|
+
.tap(PLUGIN_NAME, parserHandler);
|
230
230
|
}
|
231
231
|
}
|
232
232
|
compilation.hooks.optimizeDependencies.tap(
|
233
233
|
{
|
234
|
-
name:
|
234
|
+
name: PLUGIN_NAME,
|
235
235
|
stage: STAGE_DEFAULT
|
236
236
|
},
|
237
237
|
modules => {
|
@@ -224,6 +224,10 @@ class ConsumeSharedPlugin {
|
|
224
224
|
);
|
225
225
|
return resolve();
|
226
226
|
}
|
227
|
+
if (data.name === packageName) {
|
228
|
+
// Package self-referencing
|
229
|
+
return resolve();
|
230
|
+
}
|
227
231
|
const requiredVersion = getRequiredVersionFromDescriptionFile(
|
228
232
|
data,
|
229
233
|
packageName
|
@@ -9,6 +9,7 @@ const { SyncWaterfallHook } = require("tapable");
|
|
9
9
|
const Compilation = require("../Compilation");
|
10
10
|
const Generator = require("../Generator");
|
11
11
|
const { tryRunOrWebpackError } = require("../HookWebpackError");
|
12
|
+
const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants");
|
12
13
|
const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
|
13
14
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
14
15
|
const memoize = require("../util/memoize");
|
@@ -53,6 +54,8 @@ const getAsyncWebAssemblyParser = memoize(() =>
|
|
53
54
|
/** @type {WeakMap<Compilation, CompilationHooks>} */
|
54
55
|
const compilationHooksMap = new WeakMap();
|
55
56
|
|
57
|
+
const PLUGIN_NAME = "AsyncWebAssemblyModulesPlugin";
|
58
|
+
|
56
59
|
class AsyncWebAssemblyModulesPlugin {
|
57
60
|
/**
|
58
61
|
* @param {Compilation} compilation the compilation
|
@@ -89,7 +92,7 @@ class AsyncWebAssemblyModulesPlugin {
|
|
89
92
|
*/
|
90
93
|
apply(compiler) {
|
91
94
|
compiler.hooks.compilation.tap(
|
92
|
-
|
95
|
+
PLUGIN_NAME,
|
93
96
|
(compilation, { normalModuleFactory }) => {
|
94
97
|
const hooks =
|
95
98
|
AsyncWebAssemblyModulesPlugin.getCompilationHooks(compilation);
|
@@ -99,15 +102,15 @@ class AsyncWebAssemblyModulesPlugin {
|
|
99
102
|
);
|
100
103
|
|
101
104
|
normalModuleFactory.hooks.createParser
|
102
|
-
.for(
|
103
|
-
.tap(
|
105
|
+
.for(WEBASSEMBLY_MODULE_TYPE_ASYNC)
|
106
|
+
.tap(PLUGIN_NAME, () => {
|
104
107
|
const AsyncWebAssemblyParser = getAsyncWebAssemblyParser();
|
105
108
|
|
106
109
|
return new AsyncWebAssemblyParser();
|
107
110
|
});
|
108
111
|
normalModuleFactory.hooks.createGenerator
|
109
|
-
.for(
|
110
|
-
.tap(
|
112
|
+
.for(WEBASSEMBLY_MODULE_TYPE_ASYNC)
|
113
|
+
.tap(PLUGIN_NAME, () => {
|
111
114
|
const AsyncWebAssemblyJavascriptGenerator =
|
112
115
|
getAsyncWebAssemblyJavascriptGenerator();
|
113
116
|
const AsyncWebAssemblyGenerator = getAsyncWebAssemblyGenerator();
|
@@ -135,7 +138,7 @@ class AsyncWebAssemblyModulesPlugin {
|
|
135
138
|
chunk,
|
136
139
|
compareModulesByIdentifier
|
137
140
|
)) {
|
138
|
-
if (module.type ===
|
141
|
+
if (module.type === WEBASSEMBLY_MODULE_TYPE_ASYNC) {
|
139
142
|
const filenameTemplate =
|
140
143
|
outputOptions.webassemblyModuleFilename;
|
141
144
|
|