webpack 5.102.0 → 5.103.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.
- package/README.md +121 -134
- package/lib/ChunkGraph.js +2 -2
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +25 -2
- package/lib/Compilation.js +30 -13
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +3 -1
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +12 -12
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DotenvPlugin.js +457 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +20 -28
- package/lib/ExternalModuleFactoryPlugin.js +10 -8
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +9 -12
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +0 -6
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +419 -121
- package/lib/NormalModule.js +18 -17
- package/lib/NormalModuleFactory.js +75 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +125 -57
- package/lib/SourceMapDevToolPlugin.js +26 -8
- package/lib/WebpackOptionsApply.js +33 -9
- package/lib/asset/AssetBytesGenerator.js +2 -1
- package/lib/asset/AssetGenerator.js +3 -5
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/browserslistTargetHandler.js +82 -76
- package/lib/config/defaults.js +105 -20
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +7 -1
- package/lib/css/CssGenerator.js +283 -57
- package/lib/css/CssLoadingRuntimeModule.js +2 -0
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +86 -40
- package/lib/css/CssParser.js +1174 -667
- package/lib/css/walkCssTokens.js +98 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssIcssExportDependency.js +247 -8
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
- package/lib/dependencies/CssIcssImportDependency.js +60 -54
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
- package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
- package/lib/dependencies/CssImportDependency.js +15 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
- package/lib/dependencies/HarmonyImportDependency.js +27 -28
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportContextDependency.js +13 -0
- package/lib/dependencies/ImportDependency.js +10 -4
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaPlugin.js +98 -10
- package/lib/dependencies/ImportParserPlugin.js +19 -21
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +1 -3
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +5 -7
- package/lib/ids/IdHelpers.js +5 -2
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +101 -101
- package/lib/javascript/JavascriptModulesPlugin.js +25 -16
- package/lib/javascript/JavascriptParser.js +143 -39
- package/lib/json/JsonParser.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +0 -10
- package/lib/library/SystemLibraryPlugin.js +19 -5
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +161 -135
- package/lib/optimize/RealContentHashPlugin.js +5 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/serialization/FileMiddleware.js +1 -1
- package/lib/serialization/ObjectMiddleware.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
- package/lib/util/Hash.js +35 -5
- package/lib/util/comparators.js +4 -3
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +85 -15
- package/lib/util/hash/BatchedHash.js +47 -8
- package/lib/util/hash/wasm-hash.js +53 -13
- package/lib/util/internalSerializables.js +4 -4
- package/lib/util/jsonParseEvenBetterErrors.js +10 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
- package/lib/wasm-async/AsyncWebAssemblyParser.js +0 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
- package/lib/wasm-sync/WebAssemblyParser.js +0 -9
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +28 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +110 -15
- package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +788 -127
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -252
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
package/lib/NormalModule.js
CHANGED
|
@@ -96,7 +96,6 @@ const memoize = require("./util/memoize");
|
|
|
96
96
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
97
97
|
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
|
98
98
|
/** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
|
99
|
-
/** @typedef {import("../declarations/WebpackOptions").RuleSetRule["extractSourceMap"]} ExtractSourceMapOptions */
|
|
100
99
|
/**
|
|
101
100
|
* @template T
|
|
102
101
|
* @typedef {import("./util/deprecation").FakeHook<T>} FakeHook
|
|
@@ -255,7 +254,7 @@ makeSerializable(
|
|
|
255
254
|
* @property {Generator} generator the generator used
|
|
256
255
|
* @property {GeneratorOptions=} generatorOptions the options of the generator used
|
|
257
256
|
* @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
|
|
258
|
-
* @property {boolean
|
|
257
|
+
* @property {boolean} extractSourceMap enable/disable extracting source map
|
|
259
258
|
*/
|
|
260
259
|
|
|
261
260
|
/**
|
|
@@ -353,34 +352,36 @@ class NormalModule extends Module {
|
|
|
353
352
|
super(type, context || getContext(resource), layer);
|
|
354
353
|
|
|
355
354
|
// Info from Factory
|
|
356
|
-
/** @type {
|
|
355
|
+
/** @type {NormalModuleCreateData['request']} */
|
|
357
356
|
this.request = request;
|
|
358
|
-
/** @type {
|
|
357
|
+
/** @type {NormalModuleCreateData['userRequest']} */
|
|
359
358
|
this.userRequest = userRequest;
|
|
360
|
-
/** @type {
|
|
359
|
+
/** @type {NormalModuleCreateData['rawRequest']} */
|
|
361
360
|
this.rawRequest = rawRequest;
|
|
362
361
|
/** @type {boolean} */
|
|
363
362
|
this.binary = /^(asset|webassembly)\b/.test(type);
|
|
364
|
-
/** @type {
|
|
363
|
+
/** @type {NormalModuleCreateData['parser'] | undefined} */
|
|
365
364
|
this.parser = parser;
|
|
366
|
-
/** @type {
|
|
365
|
+
/** @type {NormalModuleCreateData['parserOptions']} */
|
|
367
366
|
this.parserOptions = parserOptions;
|
|
368
|
-
/** @type {
|
|
367
|
+
/** @type {NormalModuleCreateData['generator'] | undefined} */
|
|
369
368
|
this.generator = generator;
|
|
370
|
-
/** @type {
|
|
369
|
+
/** @type {NormalModuleCreateData['generatorOptions']} */
|
|
371
370
|
this.generatorOptions = generatorOptions;
|
|
372
|
-
/** @type {
|
|
371
|
+
/** @type {NormalModuleCreateData['resource']} */
|
|
373
372
|
this.resource = resource;
|
|
373
|
+
/** @type {NormalModuleCreateData['resourceResolveData']} */
|
|
374
374
|
this.resourceResolveData = resourceResolveData;
|
|
375
|
-
/** @type {
|
|
375
|
+
/** @type {NormalModuleCreateData['matchResource']} */
|
|
376
376
|
this.matchResource = matchResource;
|
|
377
|
-
/** @type {
|
|
377
|
+
/** @type {NormalModuleCreateData['loaders']} */
|
|
378
378
|
this.loaders = loaders;
|
|
379
379
|
if (resolveOptions !== undefined) {
|
|
380
380
|
// already declared in super class
|
|
381
|
+
/** @type {NormalModuleCreateData['resolveOptions']} */
|
|
381
382
|
this.resolveOptions = resolveOptions;
|
|
382
383
|
}
|
|
383
|
-
/** @type {
|
|
384
|
+
/** @type {NormalModuleCreateData['extractSourceMap']} */
|
|
384
385
|
this.extractSourceMap = extractSourceMap;
|
|
385
386
|
|
|
386
387
|
// Info from Build
|
|
@@ -487,6 +488,7 @@ class NormalModule extends Module {
|
|
|
487
488
|
this.context = m.context;
|
|
488
489
|
this.matchResource = m.matchResource;
|
|
489
490
|
this.loaders = m.loaders;
|
|
491
|
+
this.extractSourceMap = m.extractSourceMap;
|
|
490
492
|
}
|
|
491
493
|
|
|
492
494
|
/**
|
|
@@ -1211,7 +1213,7 @@ class NormalModule extends Module {
|
|
|
1211
1213
|
hash.update("meta");
|
|
1212
1214
|
hash.update(JSON.stringify(this.buildMeta));
|
|
1213
1215
|
/** @type {BuildInfo} */
|
|
1214
|
-
(this.buildInfo).hash =
|
|
1216
|
+
(this.buildInfo).hash = hash.digest("hex");
|
|
1215
1217
|
}
|
|
1216
1218
|
|
|
1217
1219
|
/**
|
|
@@ -1721,7 +1723,6 @@ class NormalModule extends Module {
|
|
|
1721
1723
|
write(this._lastSuccessfulBuildMeta);
|
|
1722
1724
|
write(this._forceBuild);
|
|
1723
1725
|
write(this._codeGeneratorData);
|
|
1724
|
-
write(this.extractSourceMap);
|
|
1725
1726
|
super.serialize(context);
|
|
1726
1727
|
}
|
|
1727
1728
|
|
|
@@ -1746,7 +1747,8 @@ class NormalModule extends Module {
|
|
|
1746
1747
|
parserOptions: /** @type {EXPECTED_ANY} */ (null),
|
|
1747
1748
|
generator: /** @type {EXPECTED_ANY} */ (null),
|
|
1748
1749
|
generatorOptions: /** @type {EXPECTED_ANY} */ (null),
|
|
1749
|
-
resolveOptions: /** @type {EXPECTED_ANY} */ (null)
|
|
1750
|
+
resolveOptions: /** @type {EXPECTED_ANY} */ (null),
|
|
1751
|
+
extractSourceMap: /** @type {EXPECTED_ANY} */ (null)
|
|
1750
1752
|
});
|
|
1751
1753
|
obj.deserialize(context);
|
|
1752
1754
|
return obj;
|
|
@@ -1762,7 +1764,6 @@ class NormalModule extends Module {
|
|
|
1762
1764
|
this._lastSuccessfulBuildMeta = read();
|
|
1763
1765
|
this._forceBuild = read();
|
|
1764
1766
|
this._codeGeneratorData = read();
|
|
1765
|
-
this.extractSourceMap = read();
|
|
1766
1767
|
super.deserialize(context);
|
|
1767
1768
|
}
|
|
1768
1769
|
}
|
|
@@ -114,6 +114,7 @@ const {
|
|
|
114
114
|
/** @typedef {import("./ModuleTypeConstants").ASSET_MODULE_TYPE_INLINE} ASSET_MODULE_TYPE_INLINE */
|
|
115
115
|
/** @typedef {import("./ModuleTypeConstants").ASSET_MODULE_TYPE_RESOURCE} ASSET_MODULE_TYPE_RESOURCE */
|
|
116
116
|
/** @typedef {import("./ModuleTypeConstants").ASSET_MODULE_TYPE_SOURCE} ASSET_MODULE_TYPE_SOURCE */
|
|
117
|
+
/** @typedef {import("./ModuleTypeConstants").ASSET_MODULE_TYPE_BYTES} ASSET_MODULE_TYPE_BYTES */
|
|
117
118
|
/** @typedef {import("./ModuleTypeConstants").WEBASSEMBLY_MODULE_TYPE_ASYNC} WEBASSEMBLY_MODULE_TYPE_ASYNC */
|
|
118
119
|
/** @typedef {import("./ModuleTypeConstants").WEBASSEMBLY_MODULE_TYPE_SYNC} WEBASSEMBLY_MODULE_TYPE_SYNC */
|
|
119
120
|
/** @typedef {import("./ModuleTypeConstants").CSS_MODULE_TYPE} CSS_MODULE_TYPE */
|
|
@@ -268,6 +269,76 @@ const ruleSetCompiler = new RuleSetCompiler([
|
|
|
268
269
|
new UseEffectRulePlugin()
|
|
269
270
|
]);
|
|
270
271
|
|
|
272
|
+
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
|
273
|
+
/** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
|
274
|
+
/** @typedef {import("./javascript/JavascriptGenerator")} JavascriptGenerator */
|
|
275
|
+
/** @typedef {import("../declarations/WebpackOptions").EmptyGeneratorOptions} EmptyGeneratorOptions */
|
|
276
|
+
|
|
277
|
+
/** @typedef {import("./json/JsonParser")} JsonParser */
|
|
278
|
+
/** @typedef {import("../declarations/WebpackOptions").JsonParserOptions} JsonParserOptions */
|
|
279
|
+
/** @typedef {import("./json/JsonGenerator")} JsonGenerator */
|
|
280
|
+
/** @typedef {import("../declarations/WebpackOptions").JsonGeneratorOptions} JsonGeneratorOptions */
|
|
281
|
+
|
|
282
|
+
/** @typedef {import("./asset/AssetParser")} AssetParser */
|
|
283
|
+
/** @typedef {import("./asset/AssetSourceParser")} AssetSourceParser */
|
|
284
|
+
/** @typedef {import("./asset/AssetBytesParser")} AssetBytesParser */
|
|
285
|
+
/** @typedef {import("../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
|
|
286
|
+
/** @typedef {import("../declarations/WebpackOptions").EmptyParserOptions} EmptyParserOptions */
|
|
287
|
+
/** @typedef {import("./asset/AssetGenerator")} AssetGenerator */
|
|
288
|
+
/** @typedef {import("../declarations/WebpackOptions").AssetGeneratorOptions} AssetGeneratorOptions */
|
|
289
|
+
/** @typedef {import("../declarations/WebpackOptions").AssetInlineGeneratorOptions} AssetInlineGeneratorOptions */
|
|
290
|
+
/** @typedef {import("../declarations/WebpackOptions").AssetResourceGeneratorOptions} AssetResourceGeneratorOptions */
|
|
291
|
+
/** @typedef {import("./asset/AssetSourceGenerator")} AssetSourceGenerator */
|
|
292
|
+
/** @typedef {import("./asset/AssetBytesGenerator")} AssetBytesGenerator */
|
|
293
|
+
|
|
294
|
+
/** @typedef {import("./wasm-async/AsyncWebAssemblyParser")} AsyncWebAssemblyParser */
|
|
295
|
+
/** @typedef {import("./wasm-sync/WebAssemblyParser")} WebAssemblyParser */
|
|
296
|
+
|
|
297
|
+
/** @typedef {import("./css/CssParser")} CssParser */
|
|
298
|
+
/** @typedef {import("../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
|
|
299
|
+
/** @typedef {import("../declarations/WebpackOptions").CssAutoParserOptions} CssAutoParserOptions */
|
|
300
|
+
/** @typedef {import("../declarations/WebpackOptions").CssGlobalParserOptions} CssGlobalParserOptions */
|
|
301
|
+
/** @typedef {import("../declarations/WebpackOptions").CssModuleParserOptions} CssModuleParserOptions */
|
|
302
|
+
/** @typedef {import("./css/CssGenerator")} CssGenerator */
|
|
303
|
+
/** @typedef {import("../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
|
|
304
|
+
/** @typedef {import("../declarations/WebpackOptions").CssGlobalGeneratorOptions} CssGlobalGeneratorOptions */
|
|
305
|
+
/** @typedef {import("../declarations/WebpackOptions").CssModuleGeneratorOptions} CssModuleGeneratorOptions */
|
|
306
|
+
/** @typedef {import("../declarations/WebpackOptions").CssAutoGeneratorOptions} CssAutoGeneratorOptions */
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @typedef {[
|
|
310
|
+
* [JAVASCRIPT_MODULE_TYPE_AUTO, JavascriptParser, JavascriptParserOptions, JavascriptGenerator, EmptyGeneratorOptions],
|
|
311
|
+
* [JAVASCRIPT_MODULE_TYPE_DYNAMIC, JavascriptParser, JavascriptParserOptions, JavascriptGenerator, EmptyGeneratorOptions],
|
|
312
|
+
* [JAVASCRIPT_MODULE_TYPE_ESM, JavascriptParser, JavascriptParserOptions, JavascriptGenerator, EmptyGeneratorOptions],
|
|
313
|
+
* [JSON_MODULE_TYPE, JsonParser, JsonParserOptions, JsonGenerator, JsonGeneratorOptions],
|
|
314
|
+
* [ASSET_MODULE_TYPE, AssetParser, AssetParserOptions, AssetGenerator, AssetGeneratorOptions],
|
|
315
|
+
* [ASSET_MODULE_TYPE_INLINE, AssetParser, EmptyParserOptions, AssetGenerator, AssetGeneratorOptions],
|
|
316
|
+
* [ASSET_MODULE_TYPE_RESOURCE, AssetParser, EmptyParserOptions, AssetGenerator, AssetGeneratorOptions],
|
|
317
|
+
* [ASSET_MODULE_TYPE_SOURCE, AssetSourceParser, EmptyParserOptions, AssetSourceGenerator, EmptyGeneratorOptions],
|
|
318
|
+
* [ASSET_MODULE_TYPE_BYTES, AssetBytesParser, EmptyParserOptions, AssetBytesGenerator, EmptyGeneratorOptions],
|
|
319
|
+
* [WEBASSEMBLY_MODULE_TYPE_ASYNC, AsyncWebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions],
|
|
320
|
+
* [WEBASSEMBLY_MODULE_TYPE_SYNC, WebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions],
|
|
321
|
+
* [CSS_MODULE_TYPE, CssParser, CssParserOptions, CssGenerator, CssGeneratorOptions],
|
|
322
|
+
* [CSS_MODULE_TYPE_AUTO, CssParser, CssAutoParserOptions, CssGenerator, CssAutoGeneratorOptions],
|
|
323
|
+
* [CSS_MODULE_TYPE_MODULE, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
|
|
324
|
+
* [CSS_MODULE_TYPE_GLOBAL, CssParser, CssGlobalParserOptions, CssGenerator, CssGlobalGeneratorOptions],
|
|
325
|
+
* [string, Parser, ParserOptions, Generator, GeneratorOptions],
|
|
326
|
+
* ]} ParsersAndGeneratorsByTypes
|
|
327
|
+
*/
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* @template {unknown[]} T
|
|
331
|
+
* @template {number[]} I
|
|
332
|
+
* @typedef {{ [K in keyof I]: K extends keyof I ? I[K] extends keyof T ? T[I[K]] : never : never }} ExtractTupleElements
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* @template {unknown[]} T
|
|
337
|
+
* @template {number[]} A
|
|
338
|
+
* @template [R=void]
|
|
339
|
+
* @typedef {T extends [infer Head extends [string, ...unknown[]], ...infer Tail extends [string, ...unknown[]][]] ? Record<Head[0], SyncBailHook<ExtractTupleElements<Head, A>, R extends number ? Head[R] : R>> & RecordFactoryFromTuple<Tail, A, R> : unknown } RecordFactoryFromTuple
|
|
340
|
+
*/
|
|
341
|
+
|
|
271
342
|
class NormalModuleFactory extends ModuleFactory {
|
|
272
343
|
/**
|
|
273
344
|
* @param {object} param params
|
|
@@ -306,15 +377,15 @@ class NormalModuleFactory extends ModuleFactory {
|
|
|
306
377
|
createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
|
|
307
378
|
/** @type {SyncWaterfallHook<[Module, CreateData, ResolveData]>} */
|
|
308
379
|
module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
|
|
309
|
-
/** @type {
|
|
380
|
+
/** @type {import("tapable").TypedHookMap<RecordFactoryFromTuple<ParsersAndGeneratorsByTypes, [2], 1>>} */
|
|
310
381
|
createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
|
|
311
|
-
/** @type {
|
|
382
|
+
/** @type {import("tapable").TypedHookMap<RecordFactoryFromTuple<ParsersAndGeneratorsByTypes, [1, 2]>>} */
|
|
312
383
|
parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
|
|
313
|
-
/** @type {
|
|
384
|
+
/** @type {import("tapable").TypedHookMap<RecordFactoryFromTuple<ParsersAndGeneratorsByTypes, [4], 3>>} */
|
|
314
385
|
createGenerator: new HookMap(
|
|
315
386
|
() => new SyncBailHook(["generatorOptions"])
|
|
316
387
|
),
|
|
317
|
-
/** @type {
|
|
388
|
+
/** @type {import("tapable").TypedHookMap<RecordFactoryFromTuple<ParsersAndGeneratorsByTypes, [3, 4]>>} */
|
|
318
389
|
generator: new HookMap(
|
|
319
390
|
() => new SyncHook(["generator", "generatorOptions"])
|
|
320
391
|
),
|
package/lib/RuntimeGlobals.js
CHANGED
|
@@ -78,11 +78,29 @@ module.exports.createScript = "__webpack_require__.ts";
|
|
|
78
78
|
*/
|
|
79
79
|
module.exports.createScriptUrl = "__webpack_require__.tu";
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* merge multiple CSS stylesheets (CSSStyleSheet or string) into one CSS text string
|
|
83
|
+
* Arguments: (sheets: Array<CSSStyleSheet | string> | CSSStyleSheet | string) => string
|
|
84
|
+
*/
|
|
85
|
+
module.exports.cssMergeStyleSheets = "__webpack_require__.mcs";
|
|
86
|
+
|
|
81
87
|
/**
|
|
82
88
|
* The current scope when getting a module from a remote
|
|
83
89
|
*/
|
|
84
90
|
module.exports.currentRemoteGetScope = "__webpack_require__.R";
|
|
85
91
|
|
|
92
|
+
/**
|
|
93
|
+
* resolve async transitive dependencies for deferred module
|
|
94
|
+
*/
|
|
95
|
+
module.exports.deferredModuleAsyncTransitiveDependencies =
|
|
96
|
+
"__webpack_require__.zT";
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* the internal symbol for getting the async transitive dependencies for deferred module
|
|
100
|
+
*/
|
|
101
|
+
module.exports.deferredModuleAsyncTransitiveDependenciesSymbol =
|
|
102
|
+
"__webpack_require__.zS";
|
|
103
|
+
|
|
86
104
|
/**
|
|
87
105
|
* the exported property define getters function
|
|
88
106
|
*/
|
|
@@ -258,14 +276,14 @@ module.exports.loadScript = "__webpack_require__.l";
|
|
|
258
276
|
module.exports.makeDeferredNamespaceObject = "__webpack_require__.z";
|
|
259
277
|
|
|
260
278
|
/**
|
|
261
|
-
*
|
|
279
|
+
* define compatibility on export
|
|
262
280
|
*/
|
|
263
|
-
module.exports.
|
|
281
|
+
module.exports.makeNamespaceObject = "__webpack_require__.r";
|
|
264
282
|
|
|
265
283
|
/**
|
|
266
|
-
*
|
|
284
|
+
* make a optimized deferred namespace object
|
|
267
285
|
*/
|
|
268
|
-
module.exports.
|
|
286
|
+
module.exports.makeOptimizedDeferredNamespaceObject = "__webpack_require__.zO";
|
|
269
287
|
|
|
270
288
|
/**
|
|
271
289
|
* the internal module object
|
package/lib/RuntimePlugin.js
CHANGED
|
@@ -24,7 +24,10 @@ const GetTrustedTypesPolicyRuntimeModule = require("./runtime/GetTrustedTypesPol
|
|
|
24
24
|
const GlobalRuntimeModule = require("./runtime/GlobalRuntimeModule");
|
|
25
25
|
const HasOwnPropertyRuntimeModule = require("./runtime/HasOwnPropertyRuntimeModule");
|
|
26
26
|
const LoadScriptRuntimeModule = require("./runtime/LoadScriptRuntimeModule");
|
|
27
|
-
const
|
|
27
|
+
const {
|
|
28
|
+
MakeDeferredNamespaceObjectRuntimeModule,
|
|
29
|
+
MakeOptimizedDeferredNamespaceObjectRuntimeModule
|
|
30
|
+
} = require("./runtime/MakeDeferredNamespaceObjectRuntime");
|
|
28
31
|
const MakeNamespaceObjectRuntimeModule = require("./runtime/MakeNamespaceObjectRuntimeModule");
|
|
29
32
|
const NonceRuntimeModule = require("./runtime/NonceRuntimeModule");
|
|
30
33
|
const OnChunksLoadedRuntimeModule = require("./runtime/OnChunksLoadedRuntimeModule");
|
|
@@ -78,6 +81,7 @@ const GLOBALS_ON_REQUIRE = [
|
|
|
78
81
|
RuntimeGlobals.loadScript,
|
|
79
82
|
RuntimeGlobals.systemContext,
|
|
80
83
|
RuntimeGlobals.onChunksLoaded,
|
|
84
|
+
RuntimeGlobals.makeOptimizedDeferredNamespaceObject,
|
|
81
85
|
RuntimeGlobals.makeDeferredNamespaceObject
|
|
82
86
|
];
|
|
83
87
|
|
|
@@ -96,11 +100,11 @@ const TREE_DEPENDENCIES = {
|
|
|
96
100
|
RuntimeGlobals.makeNamespaceObject,
|
|
97
101
|
RuntimeGlobals.require
|
|
98
102
|
],
|
|
103
|
+
[RuntimeGlobals.makeOptimizedDeferredNamespaceObject]: [
|
|
104
|
+
RuntimeGlobals.require
|
|
105
|
+
],
|
|
99
106
|
[RuntimeGlobals.makeDeferredNamespaceObject]: [
|
|
100
|
-
RuntimeGlobals.definePropertyGetters,
|
|
101
|
-
RuntimeGlobals.makeNamespaceObject,
|
|
102
107
|
RuntimeGlobals.createFakeNamespaceObject,
|
|
103
|
-
RuntimeGlobals.hasOwnProperty,
|
|
104
108
|
RuntimeGlobals.require
|
|
105
109
|
],
|
|
106
110
|
[RuntimeGlobals.initializeSharing]: [RuntimeGlobals.shareScopeMap],
|
|
@@ -190,12 +194,23 @@ class RuntimePlugin {
|
|
|
190
194
|
);
|
|
191
195
|
return true;
|
|
192
196
|
});
|
|
197
|
+
compilation.hooks.runtimeRequirementInTree
|
|
198
|
+
.for(RuntimeGlobals.makeOptimizedDeferredNamespaceObject)
|
|
199
|
+
.tap("RuntimePlugin", (chunk, runtimeRequirement) => {
|
|
200
|
+
compilation.addRuntimeModule(
|
|
201
|
+
chunk,
|
|
202
|
+
new MakeOptimizedDeferredNamespaceObjectRuntimeModule(
|
|
203
|
+
runtimeRequirement.has(RuntimeGlobals.asyncModule)
|
|
204
|
+
)
|
|
205
|
+
);
|
|
206
|
+
return true;
|
|
207
|
+
});
|
|
193
208
|
compilation.hooks.runtimeRequirementInTree
|
|
194
209
|
.for(RuntimeGlobals.makeDeferredNamespaceObject)
|
|
195
210
|
.tap("RuntimePlugin", (chunk, runtimeRequirement) => {
|
|
196
211
|
compilation.addRuntimeModule(
|
|
197
212
|
chunk,
|
|
198
|
-
new
|
|
213
|
+
new MakeDeferredNamespaceObjectRuntimeModule(
|
|
199
214
|
runtimeRequirement.has(RuntimeGlobals.asyncModule)
|
|
200
215
|
)
|
|
201
216
|
);
|
|
@@ -238,7 +253,13 @@ class RuntimePlugin {
|
|
|
238
253
|
|
|
239
254
|
if (publicPath === "auto") {
|
|
240
255
|
const module = new AutoPublicPathRuntimeModule();
|
|
241
|
-
if (
|
|
256
|
+
if (
|
|
257
|
+
scriptType !== "module" &&
|
|
258
|
+
!outputOptions.environment.globalThis
|
|
259
|
+
) {
|
|
260
|
+
set.add(RuntimeGlobals.global);
|
|
261
|
+
}
|
|
262
|
+
|
|
242
263
|
compilation.addRuntimeModule(chunk, module);
|
|
243
264
|
} else {
|
|
244
265
|
const module = new PublicPathRuntimeModule(publicPath);
|
package/lib/RuntimeTemplate.js
CHANGED
|
@@ -11,15 +11,24 @@ const Template = require("./Template");
|
|
|
11
11
|
const {
|
|
12
12
|
getOutgoingAsyncModules
|
|
13
13
|
} = require("./async-modules/AsyncModuleHelpers");
|
|
14
|
+
const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
|
|
14
15
|
const {
|
|
15
16
|
getMakeDeferredNamespaceModeFromExportsType,
|
|
16
17
|
getOptimizedDeferredModule
|
|
17
18
|
} = require("./runtime/MakeDeferredNamespaceObjectRuntime");
|
|
18
19
|
const { equals } = require("./util/ArrayHelpers");
|
|
19
20
|
const compileBooleanMatcher = require("./util/compileBooleanMatcher");
|
|
21
|
+
const memoize = require("./util/memoize");
|
|
20
22
|
const propertyAccess = require("./util/propertyAccess");
|
|
21
23
|
const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|
22
24
|
|
|
25
|
+
const getHarmonyImportDependency = memoize(() =>
|
|
26
|
+
require("./dependencies/HarmonyImportDependency")
|
|
27
|
+
);
|
|
28
|
+
const getImportDependency = memoize(() =>
|
|
29
|
+
require("./dependencies/ImportDependency")
|
|
30
|
+
);
|
|
31
|
+
|
|
23
32
|
/** @typedef {import("./config/defaults").OutputNormalizedWithDefaults} OutputOptions */
|
|
24
33
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
|
25
34
|
/** @typedef {import("./Chunk")} Chunk */
|
|
@@ -32,6 +41,8 @@ const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|
|
32
41
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
|
33
42
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
|
34
43
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
|
44
|
+
/** @typedef {import("./dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
45
|
+
/** @typedef {import("./NormalModuleFactory").ModuleDependency} ModuleDependency */
|
|
35
46
|
|
|
36
47
|
/**
|
|
37
48
|
* @param {Module} module the module
|
|
@@ -617,6 +628,7 @@ class RuntimeTemplate {
|
|
|
617
628
|
* @param {string} options.message a message for the comment
|
|
618
629
|
* @param {boolean=} options.strict if the current module is in strict esm mode
|
|
619
630
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
|
631
|
+
* @param {Dependency} options.dependency dependency
|
|
620
632
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
621
633
|
* @returns {string} the promise expression
|
|
622
634
|
*/
|
|
@@ -628,6 +640,7 @@ class RuntimeTemplate {
|
|
|
628
640
|
message,
|
|
629
641
|
strict,
|
|
630
642
|
weak,
|
|
643
|
+
dependency,
|
|
631
644
|
runtimeRequirements
|
|
632
645
|
}) {
|
|
633
646
|
if (!module) {
|
|
@@ -684,42 +697,45 @@ class RuntimeTemplate {
|
|
|
684
697
|
type: "statements"
|
|
685
698
|
})} } `;
|
|
686
699
|
}
|
|
687
|
-
const moduleIdExpr = this.moduleId({
|
|
688
|
-
module,
|
|
689
|
-
chunkGraph,
|
|
690
|
-
request,
|
|
691
|
-
weak
|
|
692
|
-
});
|
|
693
700
|
const exportsType = module.getExportsType(chunkGraph.moduleGraph, strict);
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
701
|
+
|
|
702
|
+
const isModuleDeferred =
|
|
703
|
+
(dependency instanceof getHarmonyImportDependency() ||
|
|
704
|
+
dependency instanceof getImportDependency()) &&
|
|
705
|
+
ImportPhaseUtils.isDefer(dependency.phase) &&
|
|
706
|
+
!(/** @type {BuildMeta} */ (module.buildMeta).async);
|
|
707
|
+
|
|
708
|
+
if (isModuleDeferred) {
|
|
709
|
+
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
710
|
+
const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
|
|
711
|
+
const asyncDeps = Array.from(
|
|
712
|
+
getOutgoingAsyncModules(chunkGraph.moduleGraph, module),
|
|
713
|
+
(m) => chunkGraph.getModuleId(m)
|
|
714
|
+
).filter((id) => id !== null);
|
|
715
|
+
if (asyncDeps.length) {
|
|
697
716
|
if (header) {
|
|
698
|
-
const rawModule = this.moduleRaw({
|
|
699
|
-
module,
|
|
700
|
-
chunkGraph,
|
|
701
|
-
request,
|
|
702
|
-
weak,
|
|
703
|
-
runtimeRequirements
|
|
704
|
-
});
|
|
705
717
|
appending = `.then(${this.basicFunction(
|
|
706
718
|
"",
|
|
707
|
-
`${header}return ${
|
|
719
|
+
`${header}return ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(${JSON.stringify(asyncDeps)});`
|
|
708
720
|
)})`;
|
|
709
721
|
} else {
|
|
710
722
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
711
|
-
appending = `.then(${
|
|
723
|
+
appending = `.then(${this.returningFunction(`${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(${JSON.stringify(asyncDeps)})`)})`;
|
|
712
724
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
725
|
+
appending += `.then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${mode}))`;
|
|
726
|
+
} else if (header) {
|
|
727
|
+
appending = `.then(${this.basicFunction(
|
|
728
|
+
"",
|
|
729
|
+
`${header}return ${RuntimeGlobals.makeDeferredNamespaceObject}(${comment}${idExpr}, ${mode});`
|
|
730
|
+
)})`;
|
|
731
|
+
} else {
|
|
732
|
+
runtimeRequirements.add(RuntimeGlobals.require);
|
|
733
|
+
appending = `.then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${mode}))`;
|
|
734
|
+
}
|
|
735
|
+
} else {
|
|
736
|
+
let fakeType = 16;
|
|
737
|
+
switch (exportsType) {
|
|
738
|
+
case "namespace":
|
|
723
739
|
if (header) {
|
|
724
740
|
const rawModule = this.moduleRaw({
|
|
725
741
|
module,
|
|
@@ -736,23 +752,56 @@ class RuntimeTemplate {
|
|
|
736
752
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
737
753
|
appending = `.then(${RuntimeGlobals.require}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}))`;
|
|
738
754
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
fakeType |=
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
755
|
+
break;
|
|
756
|
+
case "dynamic":
|
|
757
|
+
fakeType |= 4;
|
|
758
|
+
/* fall through */
|
|
759
|
+
case "default-with-named":
|
|
760
|
+
fakeType |= 2;
|
|
761
|
+
/* fall through */
|
|
762
|
+
case "default-only":
|
|
763
|
+
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
764
|
+
if (chunkGraph.moduleGraph.isAsync(module)) {
|
|
765
|
+
if (header) {
|
|
766
|
+
const rawModule = this.moduleRaw({
|
|
767
|
+
module,
|
|
768
|
+
chunkGraph,
|
|
769
|
+
request,
|
|
770
|
+
weak,
|
|
771
|
+
runtimeRequirements
|
|
772
|
+
});
|
|
773
|
+
appending = `.then(${this.basicFunction(
|
|
774
|
+
"",
|
|
775
|
+
`${header}return ${rawModule};`
|
|
776
|
+
)})`;
|
|
777
|
+
} else {
|
|
778
|
+
runtimeRequirements.add(RuntimeGlobals.require);
|
|
779
|
+
appending = `.then(${RuntimeGlobals.require}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}))`;
|
|
780
|
+
}
|
|
781
|
+
appending += `.then(${this.returningFunction(
|
|
782
|
+
`${RuntimeGlobals.createFakeNamespaceObject}(m, ${fakeType})`,
|
|
783
|
+
"m"
|
|
750
784
|
)})`;
|
|
751
785
|
} else {
|
|
752
|
-
|
|
786
|
+
fakeType |= 1;
|
|
787
|
+
if (header) {
|
|
788
|
+
const moduleIdExpr = this.moduleId({
|
|
789
|
+
module,
|
|
790
|
+
chunkGraph,
|
|
791
|
+
request,
|
|
792
|
+
weak
|
|
793
|
+
});
|
|
794
|
+
const returnExpression = `${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, ${fakeType})`;
|
|
795
|
+
appending = `.then(${this.basicFunction(
|
|
796
|
+
"",
|
|
797
|
+
`${header}return ${returnExpression};`
|
|
798
|
+
)})`;
|
|
799
|
+
} else {
|
|
800
|
+
appending = `.then(${RuntimeGlobals.createFakeNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${fakeType}))`;
|
|
801
|
+
}
|
|
753
802
|
}
|
|
754
|
-
|
|
755
|
-
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
756
805
|
}
|
|
757
806
|
|
|
758
807
|
return `${promise || "Promise.resolve()"}${appending}`;
|
|
@@ -806,7 +855,7 @@ class RuntimeTemplate {
|
|
|
806
855
|
* @param {Module} options.originModule module in which the statement is emitted
|
|
807
856
|
* @param {boolean=} options.weak true, if this is a weak dependency
|
|
808
857
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
809
|
-
* @param {
|
|
858
|
+
* @param {ModuleDependency} options.dependency module dependency
|
|
810
859
|
* @returns {[string, string]} the import statement and the compat statement
|
|
811
860
|
*/
|
|
812
861
|
importStatement({
|
|
@@ -818,7 +867,7 @@ class RuntimeTemplate {
|
|
|
818
867
|
importVar,
|
|
819
868
|
originModule,
|
|
820
869
|
weak,
|
|
821
|
-
|
|
870
|
+
dependency,
|
|
822
871
|
runtimeRequirements
|
|
823
872
|
}) {
|
|
824
873
|
if (!module) {
|
|
@@ -866,15 +915,22 @@ class RuntimeTemplate {
|
|
|
866
915
|
);
|
|
867
916
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
868
917
|
let importContent;
|
|
869
|
-
|
|
918
|
+
|
|
919
|
+
const isModuleDeferred =
|
|
920
|
+
(dependency instanceof getHarmonyImportDependency() ||
|
|
921
|
+
dependency instanceof getImportDependency()) &&
|
|
922
|
+
ImportPhaseUtils.isDefer(dependency.phase) &&
|
|
923
|
+
!(/** @type {BuildMeta} */ (module.buildMeta).async);
|
|
924
|
+
|
|
925
|
+
if (isModuleDeferred) {
|
|
870
926
|
/** @type {Set<Module>} */
|
|
871
927
|
const outgoingAsyncModules = getOutgoingAsyncModules(moduleGraph, module);
|
|
872
928
|
|
|
873
929
|
importContent = `/* deferred harmony import */ ${optDeclaration}${importVar} = ${getOptimizedDeferredModule(
|
|
874
|
-
this,
|
|
875
|
-
exportsType,
|
|
876
930
|
moduleId,
|
|
877
|
-
|
|
931
|
+
exportsType,
|
|
932
|
+
Array.from(outgoingAsyncModules, (mod) => chunkGraph.getModuleId(mod)),
|
|
933
|
+
runtimeRequirements
|
|
878
934
|
)};\n`;
|
|
879
935
|
|
|
880
936
|
return [importContent, ""];
|
|
@@ -908,7 +964,7 @@ class RuntimeTemplate {
|
|
|
908
964
|
* @param {InitFragment<GenerateContext>[]} options.initFragments init fragments will be added here
|
|
909
965
|
* @param {RuntimeSpec} options.runtime runtime for which this code will be generated
|
|
910
966
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
911
|
-
* @param {
|
|
967
|
+
* @param {ModuleDependency} options.dependency module dependency
|
|
912
968
|
* @returns {string} expression
|
|
913
969
|
*/
|
|
914
970
|
exportFromImport({
|
|
@@ -926,7 +982,7 @@ class RuntimeTemplate {
|
|
|
926
982
|
initFragments,
|
|
927
983
|
runtime,
|
|
928
984
|
runtimeRequirements,
|
|
929
|
-
|
|
985
|
+
dependency
|
|
930
986
|
}) {
|
|
931
987
|
if (!module) {
|
|
932
988
|
return this.missingModule({
|
|
@@ -942,14 +998,26 @@ class RuntimeTemplate {
|
|
|
942
998
|
(originModule.buildMeta).strictHarmonyModule
|
|
943
999
|
);
|
|
944
1000
|
|
|
945
|
-
const
|
|
946
|
-
|
|
1001
|
+
const isModuleDeferred =
|
|
1002
|
+
(dependency instanceof getHarmonyImportDependency() ||
|
|
1003
|
+
dependency instanceof getImportDependency()) &&
|
|
1004
|
+
ImportPhaseUtils.isDefer(dependency.phase) &&
|
|
1005
|
+
!(/** @type {BuildMeta} */ (module.buildMeta).async);
|
|
947
1006
|
|
|
948
1007
|
if (defaultInterop) {
|
|
949
1008
|
// when the defaultInterop is used (when a ESM imports a CJS module),
|
|
950
1009
|
if (exportName.length > 0 && exportName[0] === "default") {
|
|
951
|
-
if (
|
|
952
|
-
const
|
|
1010
|
+
if (isModuleDeferred && exportsType !== "namespace") {
|
|
1011
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
1012
|
+
const name = exportName.slice(1);
|
|
1013
|
+
const used = exportsInfo.getUsedName(name, runtime);
|
|
1014
|
+
if (!used) {
|
|
1015
|
+
const comment = Template.toNormalComment(
|
|
1016
|
+
`unused export ${propertyAccess(exportName)}`
|
|
1017
|
+
);
|
|
1018
|
+
return `${comment} undefined`;
|
|
1019
|
+
}
|
|
1020
|
+
const access = `${importVar}.a${propertyAccess(used)}`;
|
|
953
1021
|
if (isCall || asiSafe === undefined) {
|
|
954
1022
|
return access;
|
|
955
1023
|
}
|
|
@@ -993,7 +1061,7 @@ class RuntimeTemplate {
|
|
|
993
1061
|
) {
|
|
994
1062
|
return "/* __esModule */true";
|
|
995
1063
|
}
|
|
996
|
-
} else if (
|
|
1064
|
+
} else if (isModuleDeferred) {
|
|
997
1065
|
// now exportName.length is 0
|
|
998
1066
|
// fall through to the end of this function, create the namespace there.
|
|
999
1067
|
} else if (
|
|
@@ -1036,7 +1104,7 @@ class RuntimeTemplate {
|
|
|
1036
1104
|
? ""
|
|
1037
1105
|
: `${Template.toNormalComment(propertyAccess(exportName))} `;
|
|
1038
1106
|
const access = `${importVar}${
|
|
1039
|
-
|
|
1107
|
+
isModuleDeferred ? ".a" : ""
|
|
1040
1108
|
}${comment}${propertyAccess(used)}`;
|
|
1041
1109
|
if (isCall && callContext === false) {
|
|
1042
1110
|
return asiSafe
|
|
@@ -1047,7 +1115,7 @@ class RuntimeTemplate {
|
|
|
1047
1115
|
}
|
|
1048
1116
|
return access;
|
|
1049
1117
|
}
|
|
1050
|
-
if (
|
|
1118
|
+
if (isModuleDeferred) {
|
|
1051
1119
|
initFragments.push(
|
|
1052
1120
|
new InitFragment(
|
|
1053
1121
|
`var ${importVar}_deferred_namespace_cache;\n`,
|