webpack 5.36.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/bin/webpack.js +0 -0
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +10 -5
- package/lib/ChunkGraph.js +58 -35
- package/lib/Compilation.js +116 -98
- package/lib/Compiler.js +31 -17
- 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/EntryPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/FileSystemInfo.js +25 -31
- package/lib/FlagDependencyExportsPlugin.js +8 -7
- package/lib/FlagDependencyUsagePlugin.js +2 -4
- package/lib/HotModuleReplacementPlugin.js +20 -30
- package/lib/InitFragment.js +21 -6
- package/lib/JavascriptMetaInfoPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -3
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraph.js +2 -2
- package/lib/ModuleGraphConnection.js +6 -2
- package/lib/ModuleInfoHeaderPlugin.js +2 -3
- package/lib/MultiCompiler.js +31 -27
- package/lib/NormalModule.js +38 -7
- package/lib/NormalModuleFactory.js +27 -23
- package/lib/RecordIdsPlugin.js +5 -4
- package/lib/ResolverFactory.js +10 -7
- package/lib/RuntimeGlobals.js +7 -0
- package/lib/RuntimePlugin.js +19 -1
- package/lib/SourceMapDevToolPlugin.js +14 -15
- package/lib/Template.js +4 -2
- package/lib/Watching.js +83 -46
- package/lib/WebpackOptionsApply.js +1 -0
- package/lib/asset/AssetGenerator.js +19 -23
- package/lib/buildChunkGraph.js +28 -23
- package/lib/cache/PackFileCacheStrategy.js +77 -13
- package/lib/config/defaults.js +24 -10
- package/lib/config/normalization.js +17 -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/CreateScriptUrlDependency.js +54 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
- package/lib/dependencies/HarmonyExportInitFragment.js +47 -0
- 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 +47 -20
- 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/CreateScriptUrlRuntimeModule.js +61 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
- package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
- 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/fs.js +8 -8
- package/lib/util/identifier.js +2 -1
- package/lib/util/internalSerializables.js +2 -0
- 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/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
- package/package.json +9 -6
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +103 -60
- package/types.d.ts +463 -280
@@ -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/fs.js
CHANGED
@@ -51,14 +51,14 @@ const path = require("path");
|
|
51
51
|
* @property {string | Buffer} name
|
52
52
|
*/
|
53
53
|
|
54
|
-
/** @typedef {function(NodeJS.ErrnoException=): void} Callback */
|
55
|
-
/** @typedef {function(NodeJS.ErrnoException=, Buffer=): void} BufferCallback */
|
56
|
-
/** @typedef {function(NodeJS.ErrnoException=, Buffer|string=): void} BufferOrStringCallback */
|
57
|
-
/** @typedef {function(NodeJS.ErrnoException=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */
|
58
|
-
/** @typedef {function(NodeJS.ErrnoException=, string=): void} StringCallback */
|
59
|
-
/** @typedef {function(NodeJS.ErrnoException=, number=): void} NumberCallback */
|
60
|
-
/** @typedef {function(NodeJS.ErrnoException=, IStats=): void} StatsCallback */
|
61
|
-
/** @typedef {function((NodeJS.ErrnoException | Error)=, any=): void} ReadJsonCallback */
|
54
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=): void} Callback */
|
55
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, Buffer=): void} BufferCallback */
|
56
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, Buffer|string=): void} BufferOrStringCallback */
|
57
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */
|
58
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, string=): void} StringCallback */
|
59
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, number=): void} NumberCallback */
|
60
|
+
/** @typedef {function((NodeJS.ErrnoException | null)=, IStats=): void} StatsCallback */
|
61
|
+
/** @typedef {function((NodeJS.ErrnoException | Error | null)=, any=): void} ReadJsonCallback */
|
62
62
|
|
63
63
|
/**
|
64
64
|
* @typedef {Object} Watcher
|
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
|
|
@@ -45,6 +45,8 @@ module.exports = {
|
|
45
45
|
require("../dependencies/AMDRequireItemDependency"),
|
46
46
|
"dependencies/CachedConstDependency": () =>
|
47
47
|
require("../dependencies/CachedConstDependency"),
|
48
|
+
"dependencies/CreateScriptUrlDependency": () =>
|
49
|
+
require("../dependencies/CreateScriptUrlDependency"),
|
48
50
|
"dependencies/CommonJsRequireContextDependency": () =>
|
49
51
|
require("../dependencies/CommonJsRequireContextDependency"),
|
50
52
|
"dependencies/CommonJsExportRequireDependency": () =>
|
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(
|
package/lib/webpack.js
CHANGED
@@ -36,7 +36,7 @@ const getValidateSchema = memoize(() => require("./validateSchema"));
|
|
36
36
|
*/
|
37
37
|
|
38
38
|
/**
|
39
|
-
* @param {WebpackOptions
|
39
|
+
* @param {ReadonlyArray<WebpackOptions>} childOptions options array
|
40
40
|
* @param {MultiCompilerOptions} options options
|
41
41
|
* @returns {MultiCompiler} a multi-compiler
|
42
42
|
*/
|
@@ -92,14 +92,14 @@ const createCompiler = rawOptions => {
|
|
92
92
|
|
93
93
|
/**
|
94
94
|
* @callback WebpackFunctionMulti
|
95
|
-
* @param {WebpackOptions
|
95
|
+
* @param {ReadonlyArray<WebpackOptions> & MultiCompilerOptions} options options objects
|
96
96
|
* @param {Callback<MultiStats>=} callback callback
|
97
97
|
* @returns {MultiCompiler} the multi compiler object
|
98
98
|
*/
|
99
99
|
|
100
100
|
const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
|
101
101
|
/**
|
102
|
-
* @param {WebpackOptions | (WebpackOptions
|
102
|
+
* @param {WebpackOptions | (ReadonlyArray<WebpackOptions> & MultiCompilerOptions)} options options
|
103
103
|
* @param {Callback<Stats> & Callback<MultiStats>=} callback callback
|
104
104
|
* @returns {Compiler | MultiCompiler}
|
105
105
|
*/
|
@@ -115,14 +115,18 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
|
|
115
115
|
let watchOptions;
|
116
116
|
if (Array.isArray(options)) {
|
117
117
|
/** @type {MultiCompiler} */
|
118
|
-
compiler = createMultiCompiler(
|
118
|
+
compiler = createMultiCompiler(
|
119
|
+
options,
|
120
|
+
/** @type {MultiCompilerOptions} */ (options)
|
121
|
+
);
|
119
122
|
watch = options.some(options => options.watch);
|
120
123
|
watchOptions = options.map(options => options.watchOptions || {});
|
121
124
|
} else {
|
125
|
+
const webpackOptions = /** @type {WebpackOptions} */ (options);
|
122
126
|
/** @type {Compiler} */
|
123
|
-
compiler = createCompiler(
|
124
|
-
watch =
|
125
|
-
watchOptions =
|
127
|
+
compiler = createCompiler(webpackOptions);
|
128
|
+
watch = webpackOptions.watch;
|
129
|
+
watchOptions = webpackOptions.watchOptions || {};
|
126
130
|
}
|
127
131
|
return { compiler, watch, watchOptions };
|
128
132
|
};
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
|
+
const CreateScriptUrlRuntimeModule = require("../runtime/CreateScriptUrlRuntimeModule");
|
9
10
|
const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
|
10
11
|
const ImportScriptsChunkLoadingRuntimeModule = require("./ImportScriptsChunkLoadingRuntimeModule");
|
11
12
|
|
@@ -39,11 +40,13 @@ class ImportScriptsChunkLoadingPlugin {
|
|
39
40
|
if (onceForChunkSet.has(chunk)) return;
|
40
41
|
onceForChunkSet.add(chunk);
|
41
42
|
if (!isEnabledForChunk(chunk)) return;
|
43
|
+
const withCreateScriptUrl = !!compilation.outputOptions.trustedTypes;
|
42
44
|
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
43
45
|
set.add(RuntimeGlobals.hasOwnProperty);
|
46
|
+
if (withCreateScriptUrl) set.add(RuntimeGlobals.createScriptUrl);
|
44
47
|
compilation.addRuntimeModule(
|
45
48
|
chunk,
|
46
|
-
new ImportScriptsChunkLoadingRuntimeModule(set)
|
49
|
+
new ImportScriptsChunkLoadingRuntimeModule(set, withCreateScriptUrl)
|
47
50
|
);
|
48
51
|
};
|
49
52
|
compilation.hooks.runtimeRequirementInTree
|
@@ -58,6 +61,15 @@ class ImportScriptsChunkLoadingPlugin {
|
|
58
61
|
compilation.hooks.runtimeRequirementInTree
|
59
62
|
.for(RuntimeGlobals.baseURI)
|
60
63
|
.tap("ImportScriptsChunkLoadingPlugin", handler);
|
64
|
+
compilation.hooks.runtimeRequirementInTree
|
65
|
+
.for(RuntimeGlobals.createScriptUrl)
|
66
|
+
.tap("RuntimePlugin", (chunk, set) => {
|
67
|
+
compilation.addRuntimeModule(
|
68
|
+
chunk,
|
69
|
+
new CreateScriptUrlRuntimeModule()
|
70
|
+
);
|
71
|
+
return true;
|
72
|
+
});
|
61
73
|
|
62
74
|
compilation.hooks.runtimeRequirementInTree
|
63
75
|
.for(RuntimeGlobals.ensureChunkHandlers)
|
@@ -16,9 +16,10 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
16
16
|
const { getUndoPath } = require("../util/identifier");
|
17
17
|
|
18
18
|
class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
19
|
-
constructor(runtimeRequirements) {
|
19
|
+
constructor(runtimeRequirements, withCreateScriptUrl) {
|
20
20
|
super("importScripts chunk loading", RuntimeModule.STAGE_ATTACH);
|
21
21
|
this.runtimeRequirements = runtimeRequirements;
|
22
|
+
this._withCreateScriptUrl = withCreateScriptUrl;
|
22
23
|
}
|
23
24
|
|
24
25
|
/**
|
@@ -31,7 +32,8 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
31
32
|
compilation: {
|
32
33
|
runtimeTemplate,
|
33
34
|
outputOptions: { globalObject, chunkLoadingGlobal, hotUpdateGlobal }
|
34
|
-
}
|
35
|
+
},
|
36
|
+
_withCreateScriptUrl: withCreateScriptUrl
|
35
37
|
} = this;
|
36
38
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
37
39
|
const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
|
@@ -121,7 +123,11 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
121
123
|
? "if(true) { // all chunks have JS"
|
122
124
|
: `if(${hasJsMatcher("chunkId")}) {`,
|
123
125
|
Template.indent(
|
124
|
-
`importScripts(${
|
126
|
+
`importScripts(${
|
127
|
+
withCreateScriptUrl
|
128
|
+
? `${RuntimeGlobals.createScriptUrl}(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId))`
|
129
|
+
: `${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId)`
|
130
|
+
});`
|
125
131
|
),
|
126
132
|
"}"
|
127
133
|
]),
|
@@ -158,7 +164,11 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
|
|
158
164
|
"success = true;"
|
159
165
|
])};`,
|
160
166
|
"// start update chunk loading",
|
161
|
-
`importScripts(${
|
167
|
+
`importScripts(${
|
168
|
+
withCreateScriptUrl
|
169
|
+
? `${RuntimeGlobals.createScriptUrl}(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId))`
|
170
|
+
: `${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId)`
|
171
|
+
});`,
|
162
172
|
'if(!success) throw new Error("Loading update chunk failed for unknown reason");'
|
163
173
|
]),
|
164
174
|
"}",
|