webpack 5.36.2 → 5.38.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.

Files changed (113) hide show
  1. package/README.md +5 -8
  2. package/bin/webpack.js +0 -0
  3. package/lib/CacheFacade.js +3 -3
  4. package/lib/Chunk.js +10 -5
  5. package/lib/Compilation.js +45 -57
  6. package/lib/Compiler.js +9 -6
  7. package/lib/ConcatenationScope.js +2 -1
  8. package/lib/ContextModule.js +3 -3
  9. package/lib/ContextReplacementPlugin.js +4 -3
  10. package/lib/DefinePlugin.js +16 -12
  11. package/lib/EntryPlugin.js +4 -4
  12. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  13. package/lib/ExportsInfo.js +20 -13
  14. package/lib/FileSystemInfo.js +25 -31
  15. package/lib/FlagDependencyExportsPlugin.js +8 -7
  16. package/lib/FlagDependencyUsagePlugin.js +2 -4
  17. package/lib/HotModuleReplacementPlugin.js +27 -32
  18. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  19. package/lib/MainTemplate.js +2 -3
  20. package/lib/ModuleFilenameHelpers.js +4 -2
  21. package/lib/ModuleGraphConnection.js +6 -2
  22. package/lib/ModuleInfoHeaderPlugin.js +2 -3
  23. package/lib/MultiCompiler.js +31 -27
  24. package/lib/NormalModule.js +42 -8
  25. package/lib/NormalModuleFactory.js +2 -0
  26. package/lib/RecordIdsPlugin.js +5 -4
  27. package/lib/ResolverFactory.js +10 -7
  28. package/lib/RuntimeGlobals.js +7 -0
  29. package/lib/RuntimePlugin.js +19 -1
  30. package/lib/SourceMapDevToolPlugin.js +14 -15
  31. package/lib/Template.js +4 -2
  32. package/lib/Watching.js +91 -47
  33. package/lib/asset/AssetGenerator.js +46 -29
  34. package/lib/asset/AssetModulesPlugin.js +1 -1
  35. package/lib/buildChunkGraph.js +21 -21
  36. package/lib/cache/PackFileCacheStrategy.js +12 -9
  37. package/lib/config/defaults.js +31 -10
  38. package/lib/config/normalization.js +16 -7
  39. package/lib/config/target.js +7 -2
  40. package/lib/debug/ProfilingPlugin.js +4 -3
  41. package/lib/dependencies/AMDRequireDependency.js +3 -3
  42. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
  43. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
  44. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
  45. package/lib/dependencies/CommonJsPlugin.js +8 -7
  46. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  47. package/lib/dependencies/ContextDependencyHelpers.js +10 -8
  48. package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
  49. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
  50. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
  51. package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
  52. package/lib/dependencies/ImportDependency.js +3 -3
  53. package/lib/dependencies/ImportParserPlugin.js +2 -4
  54. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
  55. package/lib/dependencies/RequireEnsureDependency.js +3 -3
  56. package/lib/dependencies/WorkerDependency.js +6 -6
  57. package/lib/dependencies/WorkerPlugin.js +32 -20
  58. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  59. package/lib/ids/HashedModuleIdsPlugin.js +3 -3
  60. package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
  61. package/lib/index.js +5 -3
  62. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
  63. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
  64. package/lib/javascript/JavascriptGenerator.js +3 -1
  65. package/lib/javascript/JavascriptModulesPlugin.js +15 -23
  66. package/lib/javascript/JavascriptParser.js +10 -8
  67. package/lib/library/AssignLibraryPlugin.js +4 -2
  68. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  69. package/lib/node/NodeWatchFileSystem.js +19 -4
  70. package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
  71. package/lib/optimize/ConcatenatedModule.js +31 -27
  72. package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
  73. package/lib/optimize/InnerGraph.js +9 -11
  74. package/lib/optimize/InnerGraphPlugin.js +3 -1
  75. package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
  76. package/lib/optimize/RealContentHashPlugin.js +14 -16
  77. package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
  78. package/lib/optimize/SplitChunksPlugin.js +13 -15
  79. package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
  80. package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
  81. package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
  82. package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
  83. package/lib/schemes/DataUriPlugin.js +21 -2
  84. package/lib/serialization/BinaryMiddleware.js +5 -3
  85. package/lib/serialization/FileMiddleware.js +3 -1
  86. package/lib/serialization/ObjectMiddleware.js +11 -7
  87. package/lib/stats/DefaultStatsFactoryPlugin.js +7 -7
  88. package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
  89. package/lib/stats/StatsFactory.js +2 -1
  90. package/lib/stats/StatsPrinter.js +3 -3
  91. package/lib/util/LazyBucketSortedSet.js +3 -3
  92. package/lib/util/cleverMerge.js +3 -1
  93. package/lib/util/comparators.js +13 -13
  94. package/lib/util/createHash.js +5 -4
  95. package/lib/util/fs.js +8 -8
  96. package/lib/util/identifier.js +2 -1
  97. package/lib/util/internalSerializables.js +2 -0
  98. package/lib/util/serialization.js +108 -59
  99. package/lib/validateSchema.js +5 -3
  100. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
  101. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
  102. package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
  103. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
  104. package/lib/wasm-sync/WebAssemblyParser.js +6 -5
  105. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
  106. package/lib/webpack.js +11 -7
  107. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
  108. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
  109. package/package.json +10 -7
  110. package/schemas/WebpackOptions.check.js +1 -1
  111. package/schemas/WebpackOptions.json +107 -60
  112. package/types.d.ts +480 -285
  113. package/lib/util/DataURI.js +0 -32
@@ -4,72 +4,121 @@
4
4
 
5
5
  "use strict";
6
6
 
7
- const BinaryMiddleware = require("../serialization/BinaryMiddleware");
8
- const FileMiddleware = require("../serialization/FileMiddleware");
9
- const ObjectMiddleware = require("../serialization/ObjectMiddleware");
10
- const Serializer = require("../serialization/Serializer");
11
- const SerializerMiddleware = require("../serialization/SerializerMiddleware");
12
- const SingleItemMiddleware = require("../serialization/SingleItemMiddleware");
13
- const internalSerializables = require("./internalSerializables");
7
+ const memoize = require("./memoize");
14
8
 
9
+ /** @typedef {import("../serialization/BinaryMiddleware").MEASURE_END_OPERATION_TYPE} MEASURE_END_OPERATION */
10
+ /** @typedef {import("../serialization/BinaryMiddleware").MEASURE_START_OPERATION_TYPE} MEASURE_START_OPERATION */
15
11
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
12
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
+ /** @typedef {import("../serialization/Serializer")} Serializer */
17
14
 
18
- const { register, registerLoader, registerNotSerializable } = ObjectMiddleware;
15
+ const getBinaryMiddleware = memoize(() =>
16
+ require("../serialization/BinaryMiddleware")
17
+ );
18
+ const getObjectMiddleware = memoize(() =>
19
+ require("../serialization/ObjectMiddleware")
20
+ );
21
+ const getSingleItemMiddleware = memoize(() =>
22
+ require("../serialization/SingleItemMiddleware")
23
+ );
24
+ const getSerializer = memoize(() => require("../serialization/Serializer"));
25
+ const getSerializerMiddleware = memoize(() =>
26
+ require("../serialization/SerializerMiddleware")
27
+ );
19
28
 
20
- const binaryMiddleware = new BinaryMiddleware();
29
+ const getBinaryMiddlewareInstance = memoize(
30
+ () => new (getBinaryMiddleware())()
31
+ );
21
32
 
22
- // Expose serialization API
23
- exports.register = register;
24
- exports.registerLoader = registerLoader;
25
- exports.registerNotSerializable = registerNotSerializable;
26
- exports.NOT_SERIALIZABLE = ObjectMiddleware.NOT_SERIALIZABLE;
27
- exports.MEASURE_START_OPERATION = BinaryMiddleware.MEASURE_START_OPERATION;
28
- exports.MEASURE_END_OPERATION = BinaryMiddleware.MEASURE_END_OPERATION;
29
- exports.buffersSerializer = new Serializer([
30
- new SingleItemMiddleware(),
31
- new ObjectMiddleware(context => {
32
- if (context.write) {
33
- context.writeLazy = value => {
34
- context.write(SerializerMiddleware.createLazy(value, binaryMiddleware));
35
- };
33
+ const registerSerializers = memoize(() => {
34
+ require("./registerExternalSerializer");
35
+
36
+ // Load internal paths with a relative require
37
+ // This allows bundling all internal serializers
38
+ const internalSerializables = require("./internalSerializables");
39
+ getObjectMiddleware().registerLoader(/^webpack\/lib\//, req => {
40
+ const loader = internalSerializables[req.slice("webpack/lib/".length)];
41
+ if (loader) {
42
+ loader();
43
+ } else {
44
+ console.warn(`${req} not found in internalSerializables`);
36
45
  }
37
- }),
38
- binaryMiddleware
39
- ]);
40
- exports.createFileSerializer = fs => {
41
- const fileMiddleware = new FileMiddleware(fs);
42
- return new Serializer([
43
- new SingleItemMiddleware(),
44
- new ObjectMiddleware(context => {
45
- if (context.write) {
46
- context.writeLazy = value => {
47
- context.write(
48
- SerializerMiddleware.createLazy(value, binaryMiddleware)
49
- );
50
- };
51
- context.writeSeparate = (value, options) => {
52
- context.write(
53
- SerializerMiddleware.createLazy(value, fileMiddleware, options)
54
- );
55
- };
56
- }
57
- }),
58
- binaryMiddleware,
59
- fileMiddleware
60
- ]);
61
- };
46
+ return true;
47
+ });
48
+ });
62
49
 
63
- require("./registerExternalSerializer");
50
+ /** @type {Serializer} */
51
+ let buffersSerializer;
64
52
 
65
- // Load internal paths with a relative require
66
- // This allows bundling all internal serializers
67
- registerLoader(/^webpack\/lib\//, req => {
68
- const loader = internalSerializables[req.slice("webpack/lib/".length)];
69
- if (loader) {
70
- loader();
71
- } else {
72
- console.warn(`${req} not found in internalSerializables`);
53
+ // Expose serialization API
54
+ module.exports = {
55
+ get register() {
56
+ return getObjectMiddleware().register;
57
+ },
58
+ get registerLoader() {
59
+ return getObjectMiddleware().registerLoader;
60
+ },
61
+ get registerNotSerializable() {
62
+ return getObjectMiddleware().registerNotSerializable;
63
+ },
64
+ get NOT_SERIALIZABLE() {
65
+ return getObjectMiddleware().NOT_SERIALIZABLE;
66
+ },
67
+ /** @type {MEASURE_START_OPERATION} */
68
+ get MEASURE_START_OPERATION() {
69
+ return getBinaryMiddleware().MEASURE_START_OPERATION;
70
+ },
71
+ /** @type {MEASURE_END_OPERATION} */
72
+ get MEASURE_END_OPERATION() {
73
+ return getBinaryMiddleware().MEASURE_END_OPERATION;
74
+ },
75
+ get buffersSerializer() {
76
+ if (buffersSerializer !== undefined) return buffersSerializer;
77
+ registerSerializers();
78
+ const Serializer = getSerializer();
79
+ const binaryMiddleware = getBinaryMiddlewareInstance();
80
+ const SerializerMiddleware = getSerializerMiddleware();
81
+ const SingleItemMiddleware = getSingleItemMiddleware();
82
+ return (buffersSerializer = new Serializer([
83
+ new SingleItemMiddleware(),
84
+ new (getObjectMiddleware())(context => {
85
+ if (context.write) {
86
+ context.writeLazy = value => {
87
+ context.write(
88
+ SerializerMiddleware.createLazy(value, binaryMiddleware)
89
+ );
90
+ };
91
+ }
92
+ }),
93
+ binaryMiddleware
94
+ ]));
95
+ },
96
+ createFileSerializer: fs => {
97
+ registerSerializers();
98
+ const Serializer = getSerializer();
99
+ const FileMiddleware = require("../serialization/FileMiddleware");
100
+ const fileMiddleware = new FileMiddleware(fs);
101
+ const binaryMiddleware = getBinaryMiddlewareInstance();
102
+ const SerializerMiddleware = getSerializerMiddleware();
103
+ const SingleItemMiddleware = getSingleItemMiddleware();
104
+ return new Serializer([
105
+ new SingleItemMiddleware(),
106
+ new (getObjectMiddleware())(context => {
107
+ if (context.write) {
108
+ context.writeLazy = value => {
109
+ context.write(
110
+ SerializerMiddleware.createLazy(value, binaryMiddleware)
111
+ );
112
+ };
113
+ context.writeSeparate = (value, options) => {
114
+ context.write(
115
+ SerializerMiddleware.createLazy(value, fileMiddleware, options)
116
+ );
117
+ };
118
+ }
119
+ }),
120
+ binaryMiddleware,
121
+ fileMiddleware
122
+ ]);
73
123
  }
74
- return true;
75
- });
124
+ };
@@ -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 = /** @type {import("ajv").AdditionalPropertiesParams} */ (error.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 = AsyncWebAssemblyModulesPlugin.getCompilationHooks(
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 = getAsyncWebAssemblyJavascriptGenerator();
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 = compilation.getDependencyReferencedExports(
44
- connection.dependency,
45
- undefined
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
- moduleGraph,
246
- module,
247
- externalExports,
248
- runtime
249
- }) => bin => {
250
- return editWithAST(ast, bin, {
251
- ModuleExport(path) {
252
- const isExternal = externalExports.has(path.node.name);
253
- if (isExternal) {
254
- path.remove();
255
- return;
256
- }
257
- const usedName = moduleGraph
258
- .getExportsInfo(module)
259
- .getUsedName(path.node.name, runtime);
260
- if (!usedName) {
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
- path.node.name = usedName;
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 = ({ ast, usedDependencyMap }) => bin => {
277
- return editWithAST(ast, bin, {
278
- ModuleImport(path) {
279
- const result = usedDependencyMap.get(
280
- path.node.module + ":" + path.node.name
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
- if (result !== undefined) {
284
- path.node.module = result.module;
285
- path.node.name = result.name;
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
- ast,
308
- initFuncId,
309
- startAtFuncOffset,
310
- importedGlobals,
311
- additionalInitCode,
312
- nextFuncIndex,
313
- nextTypeIndex
314
- }) => bin => {
315
- const funcParams = importedGlobals.map(importedGlobal => {
316
- // used for debugging
317
- const id = t.identifier(`${importedGlobal.module}.${importedGlobal.name}`);
318
-
319
- return t.funcParam(importedGlobal.descr.valtype, id);
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
- const funcBody = [];
323
- importedGlobals.forEach((importedGlobal, index) => {
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.push(...body);
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
- if (typeof startAtFuncOffset === "number") {
334
- funcBody.push(t.callInstruction(t.numberLiteralFromRaw(startAtFuncOffset)));
335
- }
332
+ funcBody.push(...body);
333
+ });
336
334
 
337
- for (const instr of additionalInitCode) {
338
- funcBody.push(instr);
339
- }
335
+ if (typeof startAtFuncOffset === "number") {
336
+ funcBody.push(
337
+ t.callInstruction(t.numberLiteralFromRaw(startAtFuncOffset))
338
+ );
339
+ }
340
340
 
341
- funcBody.push(t.instruction("end"));
341
+ for (const instr of additionalInitCode) {
342
+ funcBody.push(instr);
343
+ }
342
344
 
343
- const funcResults = [];
345
+ funcBody.push(t.instruction("end"));
344
346
 
345
- // Code section
346
- const funcSignature = t.signature(funcParams, funcResults);
347
- const func = t.func(initFuncId, funcSignature, funcBody);
347
+ const funcResults = [];
348
348
 
349
- // Type section
350
- const functype = t.typeInstruction(undefined, funcSignature);
349
+ // Code section
350
+ const funcSignature = t.signature(funcParams, funcResults);
351
+ const func = t.func(initFuncId, funcSignature, funcBody);
351
352
 
352
- // Func section
353
- const funcindex = t.indexInFuncSection(nextTypeIndex);
353
+ // Type section
354
+ const functype = t.typeInstruction(undefined, funcSignature);
354
355
 
355
- // Export section
356
- const moduleExport = t.moduleExport(
357
- initFuncId.value,
358
- t.moduleExportDescr("Func", nextFuncIndex)
359
- );
356
+ // Func section
357
+ const funcindex = t.indexInFuncSection(nextTypeIndex);
360
358
 
361
- return addWithAST(ast, bin, [func, moduleExport, funcindex, functype]);
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} */ (d);
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 = getWebAssemblyJavascriptGenerator();
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 = undefined);
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 = getJsIncompatibleTypeOfFuncSignature(
106
- funcSignature
107
- );
106
+ const incompatibleType =
107
+ getJsIncompatibleTypeOfFuncSignature(funcSignature);
108
108
 
109
109
  if (incompatibleType) {
110
110
  if (jsIncompatibleExports === undefined) {
111
- jsIncompatibleExports = state.module.buildMeta.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
- linkPreload,
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[]} childOptions options array
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[] & MultiCompilerOptions} options options objects
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[] & MultiCompilerOptions)} options options
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(options, options);
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(options);
124
- watch = options.watch;
125
- watchOptions = options.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(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId));`
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(${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
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
  "}",