webpack 5.37.0 → 5.37.1
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/README.md +5 -8
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +2 -3
- package/lib/Compilation.js +43 -55
- package/lib/Compiler.js +4 -4
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ContextModule.js +3 -3
- package/lib/ContextReplacementPlugin.js +4 -3
- package/lib/DefinePlugin.js +16 -12
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/FileSystemInfo.js +24 -30
- package/lib/FlagDependencyExportsPlugin.js +8 -7
- package/lib/FlagDependencyUsagePlugin.js +2 -4
- package/lib/HotModuleReplacementPlugin.js +20 -30
- package/lib/JavascriptMetaInfoPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -3
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraphConnection.js +6 -2
- package/lib/ModuleInfoHeaderPlugin.js +2 -3
- package/lib/MultiCompiler.js +31 -27
- package/lib/NormalModule.js +22 -5
- package/lib/RecordIdsPlugin.js +5 -4
- package/lib/ResolverFactory.js +10 -7
- package/lib/SourceMapDevToolPlugin.js +13 -14
- package/lib/Template.js +4 -2
- package/lib/Watching.js +83 -46
- package/lib/asset/AssetGenerator.js +19 -23
- package/lib/buildChunkGraph.js +21 -21
- package/lib/cache/PackFileCacheStrategy.js +12 -9
- package/lib/config/defaults.js +12 -9
- package/lib/config/normalization.js +7 -7
- package/lib/debug/ProfilingPlugin.js +4 -3
- package/lib/dependencies/AMDRequireDependency.js +3 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
- package/lib/dependencies/CommonJsPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +10 -8
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
- package/lib/dependencies/ImportDependency.js +3 -3
- package/lib/dependencies/ImportParserPlugin.js +2 -4
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
- package/lib/dependencies/RequireEnsureDependency.js +3 -3
- package/lib/dependencies/WorkerDependency.js +6 -6
- package/lib/dependencies/WorkerPlugin.js +18 -19
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/ids/HashedModuleIdsPlugin.js +3 -3
- package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
- package/lib/index.js +5 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
- package/lib/javascript/JavascriptGenerator.js +3 -1
- package/lib/javascript/JavascriptModulesPlugin.js +15 -23
- package/lib/javascript/JavascriptParser.js +10 -8
- package/lib/library/AssignLibraryPlugin.js +4 -2
- package/lib/node/NodeWatchFileSystem.js +19 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
- package/lib/optimize/ConcatenatedModule.js +22 -27
- package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
- package/lib/optimize/InnerGraph.js +9 -11
- package/lib/optimize/InnerGraphPlugin.js +3 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
- package/lib/optimize/RealContentHashPlugin.js +14 -16
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
- package/lib/optimize/SplitChunksPlugin.js +13 -15
- package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -3
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
- package/lib/serialization/BinaryMiddleware.js +2 -3
- package/lib/serialization/FileMiddleware.js +3 -1
- package/lib/serialization/ObjectMiddleware.js +11 -7
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -3
- package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
- package/lib/stats/StatsFactory.js +2 -1
- package/lib/stats/StatsPrinter.js +3 -3
- package/lib/util/LazyBucketSortedSet.js +3 -3
- package/lib/util/cleverMerge.js +3 -1
- package/lib/util/comparators.js +13 -13
- package/lib/util/identifier.js +2 -1
- package/lib/validateSchema.js +5 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +6 -5
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
- package/lib/webpack.js +11 -7
- package/package.json +6 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +68 -60
- package/types.d.ts +89 -257
@@ -21,49 +21,50 @@ class OnChunksLoadedRuntimeModule extends RuntimeModule {
|
|
21
21
|
const { runtimeTemplate } = compilation;
|
22
22
|
return Template.asString([
|
23
23
|
"var deferred = [];",
|
24
|
-
`${
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Template.indent([
|
29
|
-
"priority = priority || 0;",
|
30
|
-
"for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];",
|
31
|
-
"deferred[i] = [chunkIds, fn, priority];",
|
32
|
-
"return;"
|
33
|
-
]),
|
34
|
-
"}",
|
35
|
-
"var notFulfilled = Infinity;",
|
36
|
-
"for (var i = 0; i < deferred.length; i++) {",
|
37
|
-
Template.indent([
|
38
|
-
runtimeTemplate.destructureArray(
|
39
|
-
["chunkIds", "fn", "priority"],
|
40
|
-
"deferred[i]"
|
41
|
-
),
|
42
|
-
"var fulfilled = true;",
|
43
|
-
"for (var j = 0; j < chunkIds.length; j++) {",
|
24
|
+
`${RuntimeGlobals.onChunksLoaded} = ${runtimeTemplate.basicFunction(
|
25
|
+
"result, chunkIds, fn, priority",
|
26
|
+
[
|
27
|
+
"if(chunkIds) {",
|
44
28
|
Template.indent([
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
29
|
+
"priority = priority || 0;",
|
30
|
+
"for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];",
|
31
|
+
"deferred[i] = [chunkIds, fn, priority];",
|
32
|
+
"return;"
|
33
|
+
]),
|
34
|
+
"}",
|
35
|
+
"var notFulfilled = Infinity;",
|
36
|
+
"for (var i = 0; i < deferred.length; i++) {",
|
37
|
+
Template.indent([
|
38
|
+
runtimeTemplate.destructureArray(
|
39
|
+
["chunkIds", "fn", "priority"],
|
40
|
+
"deferred[i]"
|
41
|
+
),
|
42
|
+
"var fulfilled = true;",
|
43
|
+
"for (var j = 0; j < chunkIds.length; j++) {",
|
53
44
|
Template.indent([
|
54
|
-
|
55
|
-
|
45
|
+
`if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(${
|
46
|
+
RuntimeGlobals.onChunksLoaded
|
47
|
+
}).every(${runtimeTemplate.returningFunction(
|
48
|
+
`${RuntimeGlobals.onChunksLoaded}[key](chunkIds[j])`,
|
49
|
+
"key"
|
50
|
+
)})) {`,
|
51
|
+
Template.indent(["chunkIds.splice(j--, 1);"]),
|
52
|
+
"} else {",
|
53
|
+
Template.indent([
|
54
|
+
"fulfilled = false;",
|
55
|
+
"if(priority < notFulfilled) notFulfilled = priority;"
|
56
|
+
]),
|
57
|
+
"}"
|
56
58
|
]),
|
59
|
+
"}",
|
60
|
+
"if(fulfilled) {",
|
61
|
+
Template.indent(["deferred.splice(i--, 1)", "result = fn();"]),
|
57
62
|
"}"
|
58
63
|
]),
|
59
64
|
"}",
|
60
|
-
"
|
61
|
-
|
62
|
-
|
63
|
-
]),
|
64
|
-
"}",
|
65
|
-
"return result;"
|
66
|
-
])};`
|
65
|
+
"return result;"
|
66
|
+
]
|
67
|
+
)};`
|
67
68
|
]);
|
68
69
|
}
|
69
70
|
}
|
@@ -201,9 +201,8 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
201
201
|
if (!SerializerMiddleware.isLazy(thing))
|
202
202
|
throw new Error("Unexpected function " + thing);
|
203
203
|
/** @type {SerializedType | (() => SerializedType)} */
|
204
|
-
let serializedData =
|
205
|
-
thing
|
206
|
-
);
|
204
|
+
let serializedData =
|
205
|
+
SerializerMiddleware.getLazySerializedValue(thing);
|
207
206
|
if (serializedData === undefined) {
|
208
207
|
if (SerializerMiddleware.isLazy(thing, this)) {
|
209
208
|
const data = this._serialize(thing(), context);
|
@@ -135,7 +135,9 @@ const serialize = async (middleware, data, name, writeFile) => {
|
|
135
135
|
const backgroundJobs = [];
|
136
136
|
const resolvedData = (
|
137
137
|
await Promise.all(
|
138
|
-
/** @type {Promise<Buffer[] | Buffer | SerializeResult>[]} */ (
|
138
|
+
/** @type {Promise<Buffer[] | Buffer | SerializeResult>[]} */ (
|
139
|
+
processedData
|
140
|
+
)
|
139
141
|
)
|
140
142
|
).map(item => {
|
141
143
|
if (Array.isArray(item) || Buffer.isBuffer(item)) return item;
|
@@ -450,9 +450,8 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
450
450
|
);
|
451
451
|
}
|
452
452
|
|
453
|
-
const { request, name, serializer } =
|
454
|
-
item
|
455
|
-
);
|
453
|
+
const { request, name, serializer } =
|
454
|
+
ObjectMiddleware.getSerializerFor(item);
|
456
455
|
const key = `${request}/${name}`;
|
457
456
|
const lastIndex = objectTypeLookup.get(key);
|
458
457
|
|
@@ -500,9 +499,8 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
500
499
|
if (!SerializerMiddleware.isLazy(item))
|
501
500
|
throw new Error("Unexpected function " + item);
|
502
501
|
/** @type {SerializedType} */
|
503
|
-
const serializedData =
|
504
|
-
item
|
505
|
-
);
|
502
|
+
const serializedData =
|
503
|
+
SerializerMiddleware.getLazySerializedValue(item);
|
506
504
|
if (serializedData !== undefined) {
|
507
505
|
if (typeof serializedData === "function") {
|
508
506
|
result.push(serializedData);
|
@@ -539,7 +537,13 @@ class ObjectMiddleware extends SerializerMiddleware {
|
|
539
537
|
// This happens because the optimized code v8 generates
|
540
538
|
// is optimized for our "ctx.write" method so it will reference
|
541
539
|
// it from e. g. Dependency.prototype.serialize -(IC)-> ctx.write
|
542
|
-
data =
|
540
|
+
data =
|
541
|
+
result =
|
542
|
+
referenceable =
|
543
|
+
bufferDedupeMap =
|
544
|
+
objectTypeLookup =
|
545
|
+
ctx =
|
546
|
+
undefined;
|
543
547
|
}
|
544
548
|
}
|
545
549
|
|
@@ -1078,9 +1078,8 @@ const SIMPLE_EXTRACTORS = {
|
|
1078
1078
|
const { compilation, type } = context;
|
1079
1079
|
const built = compilation.builtModules.has(module);
|
1080
1080
|
const codeGenerated = compilation.codeGeneratedModules.has(module);
|
1081
|
-
const buildTimeExecuted =
|
1082
|
-
module
|
1083
|
-
);
|
1081
|
+
const buildTimeExecuted =
|
1082
|
+
compilation.buildTimeExecutedModules.has(module);
|
1084
1083
|
/** @type {{[x: string]: number}} */
|
1085
1084
|
const sizes = {};
|
1086
1085
|
for (const sourceType of module.getSourceTypes()) {
|
@@ -818,9 +818,8 @@ const SIMPLE_ITEMS_JOINER = {
|
|
818
818
|
"asset.chunkNames": itemsJoinCommaBracketsWithName("name"),
|
819
819
|
"asset.auxiliaryChunkNames": itemsJoinCommaBracketsWithName("auxiliary name"),
|
820
820
|
"asset.chunkIdHints": itemsJoinCommaBracketsWithName("id hint"),
|
821
|
-
"asset.auxiliaryChunkIdHints":
|
822
|
-
"auxiliary id hint"
|
823
|
-
),
|
821
|
+
"asset.auxiliaryChunkIdHints":
|
822
|
+
itemsJoinCommaBracketsWithName("auxiliary id hint"),
|
824
823
|
"module.chunks": itemsJoinOneLine,
|
825
824
|
"module.issuerPath": items =>
|
826
825
|
items
|
@@ -912,11 +911,13 @@ const joinExplicitNewLine = (items, indenter) => {
|
|
912
911
|
.trim();
|
913
912
|
};
|
914
913
|
|
915
|
-
const joinError =
|
916
|
-
|
917
|
-
|
918
|
-
""
|
919
|
-
|
914
|
+
const joinError =
|
915
|
+
error =>
|
916
|
+
(items, { red, yellow }) =>
|
917
|
+
`${error ? red("ERROR") : yellow("WARNING")} in ${joinExplicitNewLine(
|
918
|
+
items,
|
919
|
+
""
|
920
|
+
)}`;
|
920
921
|
|
921
922
|
/** @type {Record<string, (items: ({ element: string, content: string })[], context: StatsPrinterContext) => string>} */
|
922
923
|
const SIMPLE_ELEMENT_JOINERS = {
|
@@ -1130,7 +1131,8 @@ const AVAILABLE_FORMATS = {
|
|
1130
1131
|
format: red
|
1131
1132
|
},
|
1132
1133
|
{
|
1133
|
-
regExp:
|
1134
|
+
regExp:
|
1135
|
+
/\b(error|failed|unexpected|invalid|not found|not supported|not available|not possible|not implemented|doesn't support|conflict|conflicting|not existing|duplicate)\b/gi,
|
1134
1136
|
format: red
|
1135
1137
|
}
|
1136
1138
|
];
|
@@ -71,7 +71,8 @@ class StatsFactory {
|
|
71
71
|
getItemFactory: new HookMap(() => new SyncBailHook(["item", "context"]))
|
72
72
|
});
|
73
73
|
const hooks = this.hooks;
|
74
|
-
this._caches =
|
74
|
+
this._caches =
|
75
|
+
/** @type {Record<keyof typeof hooks, Map<string, SyncBailHook<[any[], StatsFactoryContext]>[]>>} */ ({});
|
75
76
|
for (const key of Object.keys(hooks)) {
|
76
77
|
this._caches[key] = new Map();
|
77
78
|
}
|
@@ -87,9 +87,9 @@ class StatsPrinter {
|
|
87
87
|
* @returns {T[]} hooks
|
88
88
|
*/
|
89
89
|
_getAllLevelHooks(hookMap, type) {
|
90
|
-
let cache = /** @type {Map<string, T[]>} */ (
|
91
|
-
hookMap
|
92
|
-
)
|
90
|
+
let cache = /** @type {Map<string, T[]>} */ (
|
91
|
+
this._levelHookCache.get(hookMap)
|
92
|
+
);
|
93
93
|
if (cache === undefined) {
|
94
94
|
cache = new Map();
|
95
95
|
this._levelHookCache.set(hookMap, cache);
|
@@ -164,9 +164,9 @@ class LazyBucketSortedSet {
|
|
164
164
|
}
|
165
165
|
};
|
166
166
|
} else {
|
167
|
-
const oldEntry = /** @type {LazyBucketSortedSet<T, any>} */ (
|
168
|
-
key
|
169
|
-
)
|
167
|
+
const oldEntry = /** @type {LazyBucketSortedSet<T, any>} */ (
|
168
|
+
this._map.get(key)
|
169
|
+
);
|
170
170
|
const finishUpdate = oldEntry.startUpdate(item);
|
171
171
|
return remove => {
|
172
172
|
if (remove) {
|
package/lib/util/cleverMerge.js
CHANGED
@@ -539,7 +539,9 @@ const resolveByProperty = (obj, byProperty, ...values) => {
|
|
539
539
|
}
|
540
540
|
const { [byProperty]: _byValue, ..._remaining } = /** @type {object} */ (obj);
|
541
541
|
const remaining = /** @type {T} */ (_remaining);
|
542
|
-
const byValue = /** @type {Record<string, T> | function(...any[]): T} */ (
|
542
|
+
const byValue = /** @type {Record<string, T> | function(...any[]): T} */ (
|
543
|
+
_byValue
|
544
|
+
);
|
543
545
|
if (typeof byValue === "object") {
|
544
546
|
const key = values[0];
|
545
547
|
if (key in byValue) {
|
package/lib/util/comparators.js
CHANGED
@@ -68,9 +68,8 @@ const compareModulesById = (chunkGraph, a, b) => {
|
|
68
68
|
return compareIds(chunkGraph.getModuleId(a), chunkGraph.getModuleId(b));
|
69
69
|
};
|
70
70
|
/** @type {ParameterizedComparator<ChunkGraph, Module>} */
|
71
|
-
exports.compareModulesById =
|
72
|
-
compareModulesById
|
73
|
-
);
|
71
|
+
exports.compareModulesById =
|
72
|
+
createCachedParameterizedComparator(compareModulesById);
|
74
73
|
|
75
74
|
/**
|
76
75
|
* @param {number} a number
|
@@ -138,9 +137,10 @@ const compareModulesByPostOrderIndexOrIdentifier = (moduleGraph, a, b) => {
|
|
138
137
|
return compareIds(a.identifier(), b.identifier());
|
139
138
|
};
|
140
139
|
/** @type {ParameterizedComparator<ModuleGraph, Module>} */
|
141
|
-
exports.compareModulesByPostOrderIndexOrIdentifier =
|
142
|
-
|
143
|
-
|
140
|
+
exports.compareModulesByPostOrderIndexOrIdentifier =
|
141
|
+
createCachedParameterizedComparator(
|
142
|
+
compareModulesByPostOrderIndexOrIdentifier
|
143
|
+
);
|
144
144
|
|
145
145
|
/**
|
146
146
|
* @param {ModuleGraph} moduleGraph the module graph
|
@@ -157,9 +157,10 @@ const compareModulesByPreOrderIndexOrIdentifier = (moduleGraph, a, b) => {
|
|
157
157
|
return compareIds(a.identifier(), b.identifier());
|
158
158
|
};
|
159
159
|
/** @type {ParameterizedComparator<ModuleGraph, Module>} */
|
160
|
-
exports.compareModulesByPreOrderIndexOrIdentifier =
|
161
|
-
|
162
|
-
|
160
|
+
exports.compareModulesByPreOrderIndexOrIdentifier =
|
161
|
+
createCachedParameterizedComparator(
|
162
|
+
compareModulesByPreOrderIndexOrIdentifier
|
163
|
+
);
|
163
164
|
|
164
165
|
/**
|
165
166
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
@@ -284,10 +285,9 @@ const concatComparators = (c1, c2, ...cRest) => {
|
|
284
285
|
const [c3, ...cRest2] = cRest;
|
285
286
|
return concatComparators(c1, concatComparators(c2, c3, ...cRest2));
|
286
287
|
}
|
287
|
-
const cacheEntry = /** @type {Comparator<T>} */ (
|
288
|
-
c1,
|
289
|
-
|
290
|
-
));
|
288
|
+
const cacheEntry = /** @type {Comparator<T>} */ (
|
289
|
+
concatComparatorsCache.get(c1, c2)
|
290
|
+
);
|
291
291
|
if (cacheEntry !== undefined) return cacheEntry;
|
292
292
|
/**
|
293
293
|
* @param {T} a first value
|
package/lib/util/identifier.js
CHANGED
@@ -244,7 +244,8 @@ const _absolutify = (context, request) => {
|
|
244
244
|
const absolutify = makeCacheable(_absolutify);
|
245
245
|
exports.absolutify = absolutify;
|
246
246
|
|
247
|
-
const PATH_QUERY_FRAGMENT_REGEXP =
|
247
|
+
const PATH_QUERY_FRAGMENT_REGEXP =
|
248
|
+
/^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
|
248
249
|
|
249
250
|
/** @typedef {{ resource: string, path: string, query: string, fragment: string }} ParsedResource */
|
250
251
|
|
package/lib/validateSchema.js
CHANGED
@@ -21,8 +21,7 @@ const DID_YOU_MEAN = {
|
|
21
21
|
"output.environment (output.ecmaVersion was a temporary configuration option during webpack 5 beta)",
|
22
22
|
ecmaversion:
|
23
23
|
"output.environment (output.ecmaVersion was a temporary configuration option during webpack 5 beta)",
|
24
|
-
ecma:
|
25
|
-
"output.environment (output.ecmaVersion was a temporary configuration option during webpack 5 beta)",
|
24
|
+
ecma: "output.environment (output.ecmaVersion was a temporary configuration option during webpack 5 beta)",
|
26
25
|
path: "output.path",
|
27
26
|
pathinfo: "output.pathinfo",
|
28
27
|
pathInfo: "output.pathinfo",
|
@@ -109,7 +108,10 @@ const validateSchema = (schema, options, validationConfiguration) => {
|
|
109
108
|
}
|
110
109
|
|
111
110
|
if (error.keyword === "additionalProperties") {
|
112
|
-
const params =
|
111
|
+
const params =
|
112
|
+
/** @type {import("ajv").AdditionalPropertiesParams} */ (
|
113
|
+
error.params
|
114
|
+
);
|
113
115
|
if (
|
114
116
|
Object.prototype.hasOwnProperty.call(
|
115
117
|
DID_YOU_MEAN,
|
@@ -91,9 +91,8 @@ class AsyncWebAssemblyModulesPlugin {
|
|
91
91
|
compiler.hooks.compilation.tap(
|
92
92
|
"AsyncWebAssemblyModulesPlugin",
|
93
93
|
(compilation, { normalModuleFactory }) => {
|
94
|
-
const hooks =
|
95
|
-
compilation
|
96
|
-
);
|
94
|
+
const hooks =
|
95
|
+
AsyncWebAssemblyModulesPlugin.getCompilationHooks(compilation);
|
97
96
|
compilation.dependencyFactories.set(
|
98
97
|
WebAssemblyImportDependency,
|
99
98
|
normalModuleFactory
|
@@ -109,7 +108,8 @@ class AsyncWebAssemblyModulesPlugin {
|
|
109
108
|
normalModuleFactory.hooks.createGenerator
|
110
109
|
.for("webassembly/async")
|
111
110
|
.tap("AsyncWebAssemblyModulesPlugin", () => {
|
112
|
-
const AsyncWebAssemblyJavascriptGenerator =
|
111
|
+
const AsyncWebAssemblyJavascriptGenerator =
|
112
|
+
getAsyncWebAssemblyJavascriptGenerator();
|
113
113
|
const AsyncWebAssemblyGenerator = getAsyncWebAssemblyGenerator();
|
114
114
|
|
115
115
|
return Generator.byType({
|
@@ -40,10 +40,11 @@ class WasmFinalizeExportsPlugin {
|
|
40
40
|
connection.originModule.type.startsWith("webassembly") ===
|
41
41
|
false
|
42
42
|
) {
|
43
|
-
const referencedExports =
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
const referencedExports =
|
44
|
+
compilation.getDependencyReferencedExports(
|
45
|
+
connection.dependency,
|
46
|
+
undefined
|
47
|
+
);
|
47
48
|
|
48
49
|
for (const info of referencedExports) {
|
49
50
|
const names = Array.isArray(info) ? info : info.name;
|
@@ -240,31 +240,27 @@ const rewriteImportedGlobals = state => bin => {
|
|
240
240
|
* @param {RuntimeSpec} state.runtime runtime
|
241
241
|
* @returns {ArrayBufferTransform} transform
|
242
242
|
*/
|
243
|
-
const rewriteExportNames =
|
244
|
-
ast,
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
path.remove();
|
262
|
-
return;
|
243
|
+
const rewriteExportNames =
|
244
|
+
({ ast, moduleGraph, module, externalExports, runtime }) =>
|
245
|
+
bin => {
|
246
|
+
return editWithAST(ast, bin, {
|
247
|
+
ModuleExport(path) {
|
248
|
+
const isExternal = externalExports.has(path.node.name);
|
249
|
+
if (isExternal) {
|
250
|
+
path.remove();
|
251
|
+
return;
|
252
|
+
}
|
253
|
+
const usedName = moduleGraph
|
254
|
+
.getExportsInfo(module)
|
255
|
+
.getUsedName(path.node.name, runtime);
|
256
|
+
if (!usedName) {
|
257
|
+
path.remove();
|
258
|
+
return;
|
259
|
+
}
|
260
|
+
path.node.name = usedName;
|
263
261
|
}
|
264
|
-
|
265
|
-
|
266
|
-
});
|
267
|
-
};
|
262
|
+
});
|
263
|
+
};
|
268
264
|
|
269
265
|
/**
|
270
266
|
* Mangle import names and modules
|
@@ -273,20 +269,22 @@ const rewriteExportNames = ({
|
|
273
269
|
* @param {Map<string, UsedWasmDependency>} state.usedDependencyMap mappings to mangle names
|
274
270
|
* @returns {ArrayBufferTransform} transform
|
275
271
|
*/
|
276
|
-
const rewriteImports =
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
272
|
+
const rewriteImports =
|
273
|
+
({ ast, usedDependencyMap }) =>
|
274
|
+
bin => {
|
275
|
+
return editWithAST(ast, bin, {
|
276
|
+
ModuleImport(path) {
|
277
|
+
const result = usedDependencyMap.get(
|
278
|
+
path.node.module + ":" + path.node.name
|
279
|
+
);
|
282
280
|
|
283
|
-
|
284
|
-
|
285
|
-
|
281
|
+
if (result !== undefined) {
|
282
|
+
path.node.module = result.module;
|
283
|
+
path.node.name = result.name;
|
284
|
+
}
|
286
285
|
}
|
287
|
-
}
|
288
|
-
}
|
289
|
-
};
|
286
|
+
});
|
287
|
+
};
|
290
288
|
|
291
289
|
/**
|
292
290
|
* Add an init function.
|
@@ -303,63 +301,69 @@ const rewriteImports = ({ ast, usedDependencyMap }) => bin => {
|
|
303
301
|
* @param {t.Index} state.nextTypeIndex index of the next type
|
304
302
|
* @returns {ArrayBufferTransform} transform
|
305
303
|
*/
|
306
|
-
const addInitFunction =
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
const
|
318
|
-
|
319
|
-
|
320
|
-
|
304
|
+
const addInitFunction =
|
305
|
+
({
|
306
|
+
ast,
|
307
|
+
initFuncId,
|
308
|
+
startAtFuncOffset,
|
309
|
+
importedGlobals,
|
310
|
+
additionalInitCode,
|
311
|
+
nextFuncIndex,
|
312
|
+
nextTypeIndex
|
313
|
+
}) =>
|
314
|
+
bin => {
|
315
|
+
const funcParams = importedGlobals.map(importedGlobal => {
|
316
|
+
// used for debugging
|
317
|
+
const id = t.identifier(
|
318
|
+
`${importedGlobal.module}.${importedGlobal.name}`
|
319
|
+
);
|
321
320
|
|
322
|
-
|
323
|
-
|
324
|
-
const args = [t.indexLiteral(index)];
|
325
|
-
const body = [
|
326
|
-
t.instruction("get_local", args),
|
327
|
-
t.instruction("set_global", args)
|
328
|
-
];
|
321
|
+
return t.funcParam(importedGlobal.descr.valtype, id);
|
322
|
+
});
|
329
323
|
|
330
|
-
funcBody
|
331
|
-
|
324
|
+
const funcBody = [];
|
325
|
+
importedGlobals.forEach((importedGlobal, index) => {
|
326
|
+
const args = [t.indexLiteral(index)];
|
327
|
+
const body = [
|
328
|
+
t.instruction("get_local", args),
|
329
|
+
t.instruction("set_global", args)
|
330
|
+
];
|
332
331
|
|
333
|
-
|
334
|
-
|
335
|
-
}
|
332
|
+
funcBody.push(...body);
|
333
|
+
});
|
336
334
|
|
337
|
-
|
338
|
-
|
339
|
-
|
335
|
+
if (typeof startAtFuncOffset === "number") {
|
336
|
+
funcBody.push(
|
337
|
+
t.callInstruction(t.numberLiteralFromRaw(startAtFuncOffset))
|
338
|
+
);
|
339
|
+
}
|
340
340
|
|
341
|
-
|
341
|
+
for (const instr of additionalInitCode) {
|
342
|
+
funcBody.push(instr);
|
343
|
+
}
|
342
344
|
|
343
|
-
|
345
|
+
funcBody.push(t.instruction("end"));
|
344
346
|
|
345
|
-
|
346
|
-
const funcSignature = t.signature(funcParams, funcResults);
|
347
|
-
const func = t.func(initFuncId, funcSignature, funcBody);
|
347
|
+
const funcResults = [];
|
348
348
|
|
349
|
-
|
350
|
-
|
349
|
+
// Code section
|
350
|
+
const funcSignature = t.signature(funcParams, funcResults);
|
351
|
+
const func = t.func(initFuncId, funcSignature, funcBody);
|
351
352
|
|
352
|
-
|
353
|
-
|
353
|
+
// Type section
|
354
|
+
const functype = t.typeInstruction(undefined, funcSignature);
|
354
355
|
|
355
|
-
|
356
|
-
|
357
|
-
initFuncId.value,
|
358
|
-
t.moduleExportDescr("Func", nextFuncIndex)
|
359
|
-
);
|
356
|
+
// Func section
|
357
|
+
const funcindex = t.indexInFuncSection(nextTypeIndex);
|
360
358
|
|
361
|
-
|
362
|
-
|
359
|
+
// Export section
|
360
|
+
const moduleExport = t.moduleExport(
|
361
|
+
initFuncId.value,
|
362
|
+
t.moduleExportDescr("Func", nextFuncIndex)
|
363
|
+
);
|
364
|
+
|
365
|
+
return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]);
|
366
|
+
};
|
363
367
|
|
364
368
|
/**
|
365
369
|
* Extract mangle mappings from module
|
@@ -447,7 +451,9 @@ class WebAssemblyGenerator extends Generator {
|
|
447
451
|
module.dependencies
|
448
452
|
.filter(d => d instanceof WebAssemblyExportImportedDependency)
|
449
453
|
.map(d => {
|
450
|
-
const wasmDep = /** @type {WebAssemblyExportImportedDependency} */ (
|
454
|
+
const wasmDep = /** @type {WebAssemblyExportImportedDependency} */ (
|
455
|
+
d
|
456
|
+
);
|
451
457
|
return wasmDep.exportName;
|
452
458
|
})
|
453
459
|
);
|
@@ -61,7 +61,8 @@ class WebAssemblyModulesPlugin {
|
|
61
61
|
normalModuleFactory.hooks.createGenerator
|
62
62
|
.for("webassembly/sync")
|
63
63
|
.tap("WebAssemblyModulesPlugin", () => {
|
64
|
-
const WebAssemblyJavascriptGenerator =
|
64
|
+
const WebAssemblyJavascriptGenerator =
|
65
|
+
getWebAssemblyJavascriptGenerator();
|
65
66
|
const WebAssemblyGenerator = getWebAssemblyGenerator();
|
66
67
|
|
67
68
|
return Generator.byType({
|
@@ -89,7 +89,8 @@ class WebAssemblyParser extends Parser {
|
|
89
89
|
|
90
90
|
// extract imports and exports
|
91
91
|
const exports = [];
|
92
|
-
let jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports =
|
92
|
+
let jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports =
|
93
|
+
undefined);
|
93
94
|
|
94
95
|
const importedGlobals = [];
|
95
96
|
t.traverse(module, {
|
@@ -102,13 +103,13 @@ class WebAssemblyParser extends Parser {
|
|
102
103
|
/** @type {t.FuncSignature} */
|
103
104
|
const funcSignature = moduleContext.getFunction(funcIdx);
|
104
105
|
|
105
|
-
const incompatibleType =
|
106
|
-
funcSignature
|
107
|
-
);
|
106
|
+
const incompatibleType =
|
107
|
+
getJsIncompatibleTypeOfFuncSignature(funcSignature);
|
108
108
|
|
109
109
|
if (incompatibleType) {
|
110
110
|
if (jsIncompatibleExports === undefined) {
|
111
|
-
jsIncompatibleExports =
|
111
|
+
jsIncompatibleExports =
|
112
|
+
state.module.buildMeta.jsIncompatibleExports = {};
|
112
113
|
}
|
113
114
|
jsIncompatibleExports[node.name] = incompatibleType;
|
114
115
|
}
|
@@ -66,10 +66,8 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
|
|
66
66
|
scriptType
|
67
67
|
}
|
68
68
|
} = compilation;
|
69
|
-
const {
|
70
|
-
|
71
|
-
linkPrefetch
|
72
|
-
} = JsonpChunkLoadingRuntimeModule.getCompilationHooks(compilation);
|
69
|
+
const { linkPreload, linkPrefetch } =
|
70
|
+
JsonpChunkLoadingRuntimeModule.getCompilationHooks(compilation);
|
73
71
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
74
72
|
const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
|
75
73
|
const withLoading = this._runtimeRequirements.has(
|