webpack 5.112.0 → 5.112.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.
- package/bin/webpack.js +13 -7
- package/lib/Compilation.js +152 -60
- package/lib/Compiler.js +12 -25
- package/lib/asset/AssetBytesGenerator.js +14 -6
- package/lib/asset/AssetBytesParser.js +10 -8
- package/lib/asset/AssetGenerator.js +36 -48
- package/lib/asset/AssetModule.js +11 -0
- package/lib/asset/AssetModulesPlugin.js +5 -4
- package/lib/asset/AssetParser.js +8 -8
- package/lib/asset/AssetSourceGenerator.js +16 -8
- package/lib/asset/AssetSourceParser.js +10 -8
- package/lib/asset/WebManifestGenerator.js +11 -6
- package/lib/asset/WebManifestParser.js +3 -3
- package/lib/async-modules/AsyncModuleHelpers.js +8 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
- package/lib/cache/CacheFacade.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +6 -10
- package/lib/cache/ResolverCachePlugin.js +58 -8
- package/lib/config/WebpackOptionsApply.js +8 -28
- package/lib/config/cli.js +9 -6
- package/lib/config/defaults.js +24 -13
- package/lib/config/getClaimedAssetTypes.js +2 -2
- package/lib/config/target.js +1 -1
- package/lib/context/ContextModule.js +1 -1
- package/lib/context/ContextModuleFactory.js +1 -1
- package/lib/context/ContextReplacementPlugin.js +3 -9
- package/lib/css/CssGenerator.js +40 -37
- package/lib/css/CssModule.js +10 -0
- package/lib/css/CssModulesPlugin.js +2 -2
- package/lib/css/CssParser.js +33 -32
- package/lib/css/conventions.js +1 -1
- package/lib/css/data.js +224 -219
- package/lib/css/syntax-parser.js +1159 -298
- package/lib/css/syntax-printer.js +90 -35
- package/lib/debug/ProfilingPlugin.js +65 -43
- package/lib/define/DefinePlugin.js +10 -15
- package/lib/define/DotenvPlugin.js +10 -6
- package/lib/define/EnvironmentPlugin.js +4 -2
- package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
- package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
- package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
- package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
- package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
- package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
- package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
- package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
- package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
- package/lib/dependencies/core/CachedConstDependency.js +9 -6
- package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
- package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
- package/lib/dependencies/css/CssUrlDependency.js +2 -6
- package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
- package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
- package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
- package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
- package/lib/dependencies/esm/ESMExports.js +2 -10
- package/lib/dependencies/esm/ESMImportDependency.js +17 -2
- package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
- package/lib/dependencies/esm/ESMImportGuard.js +11 -23
- package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
- package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
- package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
- package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
- package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
- package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
- package/lib/dependencies/helpers/DynamicExports.js +4 -6
- package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
- package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
- package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
- package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
- package/lib/dependencies/import/ImportParserPlugin.js +3 -6
- package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
- package/lib/dependencies/url/URLParserPlugin.js +1 -1
- package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
- package/lib/devtool/ModuleFilenameHelpers.js +1 -1
- package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
- package/lib/dll/DelegatedModule.js +3 -3
- package/lib/dll/DllModule.js +3 -1
- package/lib/dll/DllReferencePlugin.js +1 -4
- package/lib/errors/AbstractMethodError.js +1 -1
- package/lib/errors/ErrorHelpers.js +2 -1
- package/lib/errors/HookWebpackError.js +2 -1
- package/lib/errors/JSONParseError.js +4 -4
- package/lib/errors/WebpackError.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
- package/lib/externals/ExternalModule.js +12 -9
- package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
- package/lib/externals/ExternalsPlugin.js +1 -1
- package/lib/fs/FileSystemInfo.js +4 -4
- package/lib/graph/AsyncDependenciesBlock.js +1 -1
- package/lib/graph/ChunkGraph.js +5 -0
- package/lib/graph/Dependency.js +8 -2
- package/lib/graph/ExportsInfo.js +1 -1
- package/lib/graph/ModuleGraph.js +14 -3
- package/lib/graph/buildChunkGraph.js +17 -19
- package/lib/graph/findGraphRoots.js +1 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
- package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
- package/lib/hmr/LazyCompilationPlugin.js +1 -7
- package/lib/html/HtmlGenerator.js +25 -17
- package/lib/html/HtmlModule.js +11 -1
- package/lib/html/HtmlModulesPlugin.js +12 -11
- package/lib/html/HtmlParser.js +10 -9
- package/lib/html/builtinEmbeddedRenderer.js +31 -33
- package/lib/html/data.js +42 -21
- package/lib/html/htmlMinify.js +4 -1
- package/lib/html/syntax-parser.js +34 -35
- package/lib/html/syntax-printer.js +2 -3
- package/lib/html/xmlMinify.js +4 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -12
- package/lib/javascript/APIPlugin.js +7 -13
- package/lib/javascript/BasicEvaluatedExpression.js +5 -5
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
- package/lib/javascript/ConstPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +16 -11
- package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
- package/lib/javascript/JavascriptModule.js +10 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -4
- package/lib/javascript/JavascriptParser.js +99 -11
- package/lib/javascript/ScopeAnalyzer.js +183 -107
- package/lib/javascript/UseStrictPlugin.js +2 -5
- package/lib/javascript/jsMinify.js +1 -1
- package/lib/javascript/regexp.js +2 -2
- package/lib/javascript/syntax-parser.js +2114 -1506
- package/lib/javascript/syntax-printer-data.js +167 -1
- package/lib/javascript/syntax-printer.js +9554 -2782
- package/lib/json/JsonGenerator.js +15 -7
- package/lib/json/JsonModule.js +11 -0
- package/lib/json/JsonParser.js +7 -6
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +399 -23
- package/lib/loaders/LoaderRunner.js +76 -38
- package/lib/loaders/loadLoader.js +16 -10
- package/lib/module/Generator.js +17 -9
- package/lib/module/Module.js +2 -2
- package/lib/module/NormalModule.js +7 -5
- package/lib/module/NormalModuleFactory.js +11 -17
- package/lib/module/Parser.js +9 -2
- package/lib/module/extractSourceMap.js +69 -18
- package/lib/module/findCaseMismatch.js +2 -2
- package/lib/node/ExternalModuleInitFragment.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
- package/lib/node/nodeConsole.js +4 -3
- package/lib/optimize/CircularModulesPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +2 -6
- package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
- package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
- package/lib/optimize/InlineExports.js +4 -7
- package/lib/optimize/LazyBarrels.js +41 -5
- package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
- package/lib/optimize/RealContentHashPlugin.js +2 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
- package/lib/optimize/SplitChunksPlugin.js +11 -24
- package/lib/optimize/TupleQueue.js +1 -1
- package/lib/output/CleanPlugin.js +3 -1
- package/lib/output/CopyPlugin.js +3 -4
- package/lib/performance/EvalUsagePlugin.js +1 -3
- package/lib/performance/HotspotsPlugin.js +33 -9
- package/lib/performance/PureAnnotationsPlugin.js +16 -10
- package/lib/performance/TopLevelThisPlugin.js +17 -9
- package/lib/prefetch/ResourceHintPlugin.js +1 -1
- package/lib/provide/ProvidedDependency.js +36 -4
- package/lib/rules/BasicEffectRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +15 -5
- package/lib/rules/UseEffectRulePlugin.js +1 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
- package/lib/runtime/RuntimeGlobals.js +6 -0
- package/lib/runtime/RuntimePlugin.js +2 -0
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/schemes/VirtualUrlPlugin.js +3 -1
- package/lib/serialization/AggregateErrorSerializer.js +3 -3
- package/lib/serialization/BinaryMiddleware.js +4 -1
- package/lib/serialization/ErrorObjectSerializer.js +2 -5
- package/lib/serialization/ObjectMiddleware.js +17 -15
- package/lib/serialization/PlainObjectSerializer.js +3 -7
- package/lib/serialization/Serializer.js +21 -11
- package/lib/serialization/SerializerMiddleware.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
- package/lib/stats/StatsFactory.js +194 -24
- package/lib/stats/StatsPrinter.js +126 -13
- package/lib/template/DependencyTemplate.js +1 -1
- package/lib/template/RuntimeTemplate.js +13 -32
- package/lib/template/Template.js +1 -1
- package/lib/util/SourceProcessor.js +98 -15
- package/lib/util/WeakTupleMap.js +10 -4
- package/lib/util/cleverMerge.js +61 -33
- package/lib/util/comparators.js +9 -5
- package/lib/util/dataURL.js +2 -0
- package/lib/util/deprecation.js +4 -3
- package/lib/util/globUtils.js +1 -4
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/makeSerializable.js +6 -4
- package/lib/util/memoize.js +1 -1
- package/lib/util/parseJson.js +2 -2
- package/lib/util/serialization.js +31 -27
- package/lib/wasm/AsyncWasmModule.js +12 -2
- package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
- package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
- package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
- package/lib/wasm-sync/SyncWasmModule.js +16 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm-sync/WebAssemblyParser.js +10 -12
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
- package/lib/web/FetchCompileWasmPlugin.js +2 -6
- package/package.json +16 -18
- package/schemas/WebpackOptions.check.js +3 -3
- package/schemas/WebpackOptions.json +2 -2
- package/schemas/plugins/BannerPlugin.check.js +3 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
- package/schemas/plugins/HtmlParserOptions.check.js +3 -3
- package/schemas/plugins/IgnorePlugin.check.js +3 -3
- package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
- package/schemas/plugins/ManifestPlugin.check.js +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +3 -3
- package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
- package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
- package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
- package/schemas/plugins/container/ExternalsType.check.js +3 -3
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssParserOptions.check.js +3 -3
- package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
- package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
- package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.js +3 -3
- package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
- package/schemas/plugins/output/CleanOptions.check.js +7 -0
- package/schemas/plugins/output/CleanOptions.json +3 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
- package/types.d.ts +1482 -358
|
@@ -38,12 +38,7 @@ const { STAGE_DEFAULT } = require("./OptimizationStages");
|
|
|
38
38
|
*/
|
|
39
39
|
/** @import ESMExportImportedSpecifierDependency from "../dependencies/esm/ESMExportImportedSpecifierDependency" */
|
|
40
40
|
/** @import Compiler from "../Compiler" */
|
|
41
|
-
/** @import Module
|
|
42
|
-
/**
|
|
43
|
-
* @import {
|
|
44
|
-
* JavascriptModuleBuildInfo
|
|
45
|
-
* } from "../javascript/JavascriptModule"
|
|
46
|
-
*/
|
|
41
|
+
/** @import Module from "../module/Module" */
|
|
47
42
|
/** @import ModuleGraphConnection from "../graph/ModuleGraphConnection" */
|
|
48
43
|
/** @import { ExportInfo, TargetItemWithConnection } from "../graph/ExportsInfo" */
|
|
49
44
|
/** @import JavascriptParser, { Range } from "../javascript/JavascriptParser" */
|
|
@@ -407,7 +402,7 @@ class SideEffectsFlagPlugin {
|
|
|
407
402
|
const hasSideEffects = SideEffectsFlagPlugin.moduleHasSideEffects(
|
|
408
403
|
resolved.relativePath,
|
|
409
404
|
resolved.sideEffects,
|
|
410
|
-
|
|
405
|
+
cache
|
|
411
406
|
);
|
|
412
407
|
module.factoryMeta.sideEffectFree = !hasSideEffects;
|
|
413
408
|
}
|
|
@@ -545,16 +540,13 @@ class SideEffectsFlagPlugin {
|
|
|
545
540
|
);
|
|
546
541
|
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
|
547
542
|
if (sideEffectsStatement === undefined) {
|
|
548
|
-
|
|
549
|
-
(parser.state.module.buildMeta).sideEffectFree = true;
|
|
543
|
+
parser.state.module.buildMeta.sideEffectFree = true;
|
|
550
544
|
} else {
|
|
551
545
|
const type = sideEffectsStatement.type;
|
|
552
546
|
const loc = parser.getLocation(sideEffectsStatement);
|
|
553
547
|
const at = formatLocation(loc);
|
|
554
548
|
|
|
555
|
-
const buildInfo =
|
|
556
|
-
parser.state.module.buildInfo
|
|
557
|
-
);
|
|
549
|
+
const buildInfo = parser.state.module.buildInfo;
|
|
558
550
|
recordOptimizationBailout(
|
|
559
551
|
buildInfo,
|
|
560
552
|
`Statement (${type}) with side effects in source code at ${at}`
|
|
@@ -701,9 +693,7 @@ class SideEffectsFlagPlugin {
|
|
|
701
693
|
if (pureFunctions === undefined || pureFunctions.size === 0) {
|
|
702
694
|
return;
|
|
703
695
|
}
|
|
704
|
-
const buildInfo =
|
|
705
|
-
parser.state.module.buildInfo
|
|
706
|
-
);
|
|
696
|
+
const buildInfo = parser.state.module.buildInfo;
|
|
707
697
|
if (buildInfo.pureFunctions) {
|
|
708
698
|
for (const fn of pureFunctions) {
|
|
709
699
|
buildInfo.pureFunctions.add(fn);
|
|
@@ -838,9 +828,7 @@ class SideEffectsFlagPlugin {
|
|
|
838
828
|
candidate.connection
|
|
839
829
|
)) &&
|
|
840
830
|
(Boolean(dep.name) ||
|
|
841
|
-
hasSingleStarReexport(
|
|
842
|
-
/** @type {Module} */ (candidate.module)
|
|
843
|
-
)),
|
|
831
|
+
hasSingleStarReexport(candidate.module)),
|
|
844
832
|
({
|
|
845
833
|
module: newModule,
|
|
846
834
|
export: exportName,
|
|
@@ -904,9 +892,7 @@ class SideEffectsFlagPlugin {
|
|
|
904
892
|
moduleGraph.updateModule(dep, target.module);
|
|
905
893
|
moduleGraph.updateParent(
|
|
906
894
|
dep,
|
|
907
|
-
|
|
908
|
-
target.connection
|
|
909
|
-
),
|
|
895
|
+
target.connection,
|
|
910
896
|
/** @type {Module} */ (connection.originModule)
|
|
911
897
|
);
|
|
912
898
|
moduleGraph.addExplanation(
|
|
@@ -409,7 +409,7 @@ const mergeSizes = (...sizes) => {
|
|
|
409
409
|
* @returns {boolean} true, if there are sizes > 0
|
|
410
410
|
*/
|
|
411
411
|
const hasNonZeroSizes = (sizes) => {
|
|
412
|
-
for (const key of
|
|
412
|
+
for (const key of Object.keys(sizes)) {
|
|
413
413
|
if (sizes[key] > 0) return true;
|
|
414
414
|
}
|
|
415
415
|
return false;
|
|
@@ -445,7 +445,7 @@ const combineSizes = (a, b, combine) => {
|
|
|
445
445
|
* @returns {boolean} true if there are sizes and all existing sizes are at least `minSize`
|
|
446
446
|
*/
|
|
447
447
|
const checkMinSize = (sizes, minSize) => {
|
|
448
|
-
for (const key of
|
|
448
|
+
for (const key of Object.keys(minSize)) {
|
|
449
449
|
const size = sizes[key];
|
|
450
450
|
if (size === undefined || size === 0) continue;
|
|
451
451
|
if (size < minSize[key]) return false;
|
|
@@ -461,9 +461,7 @@ const checkMinSize = (sizes, minSize) => {
|
|
|
461
461
|
* @returns {boolean} true if there are sizes and all existing sizes are at least `minSizeReduction`
|
|
462
462
|
*/
|
|
463
463
|
const checkMinSizeReduction = (sizes, minSizeReduction, chunkCount) => {
|
|
464
|
-
for (const key of
|
|
465
|
-
Object.keys(minSizeReduction)
|
|
466
|
-
)) {
|
|
464
|
+
for (const key of Object.keys(minSizeReduction)) {
|
|
467
465
|
const size = sizes[key];
|
|
468
466
|
if (size === undefined || size === 0) continue;
|
|
469
467
|
if (size * chunkCount < minSizeReduction[key]) return false;
|
|
@@ -480,7 +478,7 @@ const checkMinSizeReduction = (sizes, minSizeReduction, chunkCount) => {
|
|
|
480
478
|
const getViolatingMinSizes = (sizes, minSize) => {
|
|
481
479
|
/** @type {SourceTypes | undefined} */
|
|
482
480
|
let list;
|
|
483
|
-
for (const key of
|
|
481
|
+
for (const key of Object.keys(minSize)) {
|
|
484
482
|
const size = sizes[key];
|
|
485
483
|
if (size === undefined || size === 0) continue;
|
|
486
484
|
if (size < minSize[key]) {
|
|
@@ -498,7 +496,7 @@ const getViolatingMinSizes = (sizes, minSize) => {
|
|
|
498
496
|
*/
|
|
499
497
|
const totalSize = (sizes) => {
|
|
500
498
|
let size = 0;
|
|
501
|
-
for (const key of
|
|
499
|
+
for (const key of Object.keys(sizes)) {
|
|
502
500
|
size += sizes[key];
|
|
503
501
|
}
|
|
504
502
|
return size;
|
|
@@ -514,7 +512,7 @@ const normalizeName = (name) => {
|
|
|
514
512
|
return () => name;
|
|
515
513
|
}
|
|
516
514
|
if (typeof name === "function") {
|
|
517
|
-
return
|
|
515
|
+
return name;
|
|
518
516
|
}
|
|
519
517
|
};
|
|
520
518
|
|
|
@@ -1222,8 +1220,7 @@ class SplitChunksPlugin {
|
|
|
1222
1220
|
const sizeByKey = boundsChunkSetSizes ? new Map() : undefined;
|
|
1223
1221
|
const groups = boundsChunkSetSizes
|
|
1224
1222
|
? /** @type {IntersectionCacheGroup[]} */ (
|
|
1225
|
-
|
|
1226
|
-
.groups
|
|
1223
|
+
intersectionSettings.groups
|
|
1227
1224
|
)
|
|
1228
1225
|
: undefined;
|
|
1229
1226
|
for (const module of compilation.modules) {
|
|
@@ -1289,9 +1286,7 @@ class SplitChunksPlugin {
|
|
|
1289
1286
|
: undefined;
|
|
1290
1287
|
const groups = boundsExportsChunkSetSizes
|
|
1291
1288
|
? /** @type {IntersectionCacheGroup[]} */ (
|
|
1292
|
-
|
|
1293
|
-
exportsIntersectionSettings
|
|
1294
|
-
).groups
|
|
1289
|
+
exportsIntersectionSettings.groups
|
|
1295
1290
|
)
|
|
1296
1291
|
: undefined;
|
|
1297
1292
|
for (const module of compilation.modules) {
|
|
@@ -2065,11 +2060,7 @@ class SplitChunksPlugin {
|
|
|
2065
2060
|
if (count < cacheGroup.minChunks) continue;
|
|
2066
2061
|
// Select chunks by configuration
|
|
2067
2062
|
const { chunks: selectedChunks, key: selectedChunksKey } =
|
|
2068
|
-
getSelectedChunks(
|
|
2069
|
-
chunkCombination,
|
|
2070
|
-
/** @type {ChunkFilterFn} */
|
|
2071
|
-
(cacheGroup.chunksFilter)
|
|
2072
|
-
);
|
|
2063
|
+
getSelectedChunks(chunkCombination, cacheGroup.chunksFilter);
|
|
2073
2064
|
|
|
2074
2065
|
addModuleToChunksInfoMap(
|
|
2075
2066
|
cacheGroup,
|
|
@@ -2265,9 +2256,7 @@ class SplitChunksPlugin {
|
|
|
2265
2256
|
limit: byAsyncRequests
|
|
2266
2257
|
? "maxAsyncRequests"
|
|
2267
2258
|
: "maxInitialRequests",
|
|
2268
|
-
maxRequests
|
|
2269
|
-
/** @type {number} */
|
|
2270
|
-
(maxRequests),
|
|
2259
|
+
maxRequests,
|
|
2271
2260
|
modules: item.modules.size
|
|
2272
2261
|
});
|
|
2273
2262
|
}
|
|
@@ -2496,9 +2485,7 @@ class SplitChunksPlugin {
|
|
|
2496
2485
|
if (Object.keys(maxSize).length === 0) {
|
|
2497
2486
|
continue;
|
|
2498
2487
|
}
|
|
2499
|
-
for (const key of
|
|
2500
|
-
Object.keys(maxSize)
|
|
2501
|
-
)) {
|
|
2488
|
+
for (const key of Object.keys(maxSize)) {
|
|
2502
2489
|
const maxSizeValue = maxSize[key];
|
|
2503
2490
|
const minSizeValue = minSize[key];
|
|
2504
2491
|
if (
|
package/lib/output/CopyPlugin.js
CHANGED
|
@@ -44,7 +44,7 @@ const createCompilationHooks = () => ({
|
|
|
44
44
|
/** @import CacheFacade from "../cache/CacheFacade" */
|
|
45
45
|
/** @import { Snapshot } from "../fs/FileSystemInfo" */
|
|
46
46
|
/** @import { Logger } from "../logging/Logger" */
|
|
47
|
-
/** @import { Dirent, InputFileSystem, IStats } from "../fs/fs" */
|
|
47
|
+
/** @import { Dirent, InputFileSystem, IStats, JsonObject } from "../fs/fs" */
|
|
48
48
|
/** @import { GlobMatchOptions } from "../util/globUtils" */
|
|
49
49
|
/** @import { Source } from "webpack-sources" */
|
|
50
50
|
|
|
@@ -62,7 +62,7 @@ const createCompilationHooks = () => ({
|
|
|
62
62
|
* @returns {string | Buffer | Promise<string | Buffer>} content of the asset
|
|
63
63
|
*/
|
|
64
64
|
|
|
65
|
-
/** @typedef {
|
|
65
|
+
/** @typedef {JsonObject} CopyTransformCacheKeys */
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* @callback CopyTransformCacheKeysFunction
|
|
@@ -186,8 +186,7 @@ const mapLimit = (items, limit, fn) =>
|
|
|
186
186
|
*/
|
|
187
187
|
const stat = (fs, filePath) =>
|
|
188
188
|
new Promise((resolve, reject) => {
|
|
189
|
-
|
|
190
|
-
(fs.stat)(filePath, (err, stats) => {
|
|
189
|
+
fs.stat(filePath, (err, stats) => {
|
|
191
190
|
if (err) {
|
|
192
191
|
if (err.code === "ENOENT" || err.code === "ENOTDIR") {
|
|
193
192
|
return resolve(undefined);
|
|
@@ -56,9 +56,7 @@ class EvalUsagePlugin {
|
|
|
56
56
|
parser.hooks.call.for("eval").tap(PLUGIN_NAME, () => {
|
|
57
57
|
// Kept on the module rather than in a map here, so a module the
|
|
58
58
|
// filesystem cache restores rather than parses still reports.
|
|
59
|
-
const buildInfo =
|
|
60
|
-
parser.state.module.buildInfo
|
|
61
|
-
);
|
|
59
|
+
const buildInfo = parser.state.module.buildInfo;
|
|
62
60
|
|
|
63
61
|
getBuildDiagnostics(buildInfo).usesEval = true;
|
|
64
62
|
});
|
|
@@ -12,6 +12,19 @@ const { compareStrings } = require("../util/comparators");
|
|
|
12
12
|
const { contextify } = require("../util/identifier");
|
|
13
13
|
|
|
14
14
|
/** @typedef {import("tapable").FullTap} FullTap */
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The callback an `async` tap reports its error or result through.
|
|
18
|
+
* @template R the hook's result
|
|
19
|
+
* @typedef {(error?: Error | null, result?: R) => void} TapCallback
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* An `async` tap's function, the hook's callback after its arguments.
|
|
24
|
+
* @template {unknown[]} A the hook's arguments
|
|
25
|
+
* @template R the hook's result
|
|
26
|
+
* @typedef {(...args: [...A, TapCallback<R>]) => void} AsyncTapFunction
|
|
27
|
+
*/
|
|
15
28
|
/** @typedef {import("../../declarations/WebpackOptions").PerformanceOptions} PerformanceOptions */
|
|
16
29
|
/** @typedef {import("../Compiler")} Compiler */
|
|
17
30
|
/** @typedef {import("../Compilation")} Compilation */
|
|
@@ -146,15 +159,17 @@ class HotspotsPlugin {
|
|
|
146
159
|
return {
|
|
147
160
|
...tapInfo,
|
|
148
161
|
/**
|
|
149
|
-
* @
|
|
150
|
-
* @
|
|
162
|
+
* @template {unknown[]} A the hook's arguments
|
|
163
|
+
* @template R the hook's result
|
|
164
|
+
* @param {[...A, TapCallback<R>]} args the tap's arguments, callback last
|
|
165
|
+
* @returns {void}
|
|
151
166
|
*/
|
|
152
167
|
fn: (...args) => {
|
|
153
|
-
const callback = args.pop();
|
|
168
|
+
const callback = /** @type {TapCallback<R>} */ (args.pop());
|
|
154
169
|
|
|
155
170
|
/**
|
|
156
|
-
* @param {
|
|
157
|
-
* @returns {
|
|
171
|
+
* @param {Parameters<TapCallback<R>>} result what the tap reported
|
|
172
|
+
* @returns {void}
|
|
158
173
|
*/
|
|
159
174
|
const finish = (...result) =>
|
|
160
175
|
measure(pluginTime, name, hookName, () => callback(...result));
|
|
@@ -162,7 +177,11 @@ class HotspotsPlugin {
|
|
|
162
177
|
// The completion callback is the plugin's own code as well, so it
|
|
163
178
|
// is charged to the plugin rather than to whoever resumed it.
|
|
164
179
|
return measure(pluginTime, name, hookName, () =>
|
|
165
|
-
|
|
180
|
+
/** @type {AsyncTapFunction<A, R>} */ (fn)(
|
|
181
|
+
// `pop()` took the callback off, which the tuple type cannot follow.
|
|
182
|
+
.../** @type {A} */ (/** @type {unknown[]} */ (args)),
|
|
183
|
+
finish
|
|
184
|
+
)
|
|
166
185
|
);
|
|
167
186
|
}
|
|
168
187
|
};
|
|
@@ -171,10 +190,15 @@ class HotspotsPlugin {
|
|
|
171
190
|
return {
|
|
172
191
|
...tapInfo,
|
|
173
192
|
/**
|
|
174
|
-
* @
|
|
175
|
-
* @
|
|
193
|
+
* @template {unknown[]} A the hook's arguments
|
|
194
|
+
* @template R what the tap returns: the hook's result, or a promise of it
|
|
195
|
+
* @param {A} args the tap's arguments
|
|
196
|
+
* @returns {R} whatever the tap returned
|
|
176
197
|
*/
|
|
177
|
-
fn: (...args) =>
|
|
198
|
+
fn: (...args) =>
|
|
199
|
+
measure(pluginTime, name, hookName, () =>
|
|
200
|
+
/** @type {(...args: A) => R} */ (fn)(...args)
|
|
201
|
+
)
|
|
178
202
|
};
|
|
179
203
|
};
|
|
180
204
|
|
|
@@ -22,6 +22,14 @@ const { CompilerHintNotationRegExp } = require("../util/magicComment");
|
|
|
22
22
|
/** @import JavascriptParser from "../javascript/JavascriptParser" */
|
|
23
23
|
/** @import { PureAnnotationDetails } from "../errors/PureAnnotationsWarning" */
|
|
24
24
|
|
|
25
|
+
/** @typedef {{ [Key in string]?: AstValue }} AstFields */
|
|
26
|
+
/** @typedef {AstValue[]} AstArray */
|
|
27
|
+
/**
|
|
28
|
+
* A value found while walking an estree AST structurally: a node, a field of
|
|
29
|
+
* one, or a literal's value.
|
|
30
|
+
* @typedef {string | number | boolean | bigint | RegExp | null | undefined | AstArray | AstFields} AstValue
|
|
31
|
+
*/
|
|
32
|
+
|
|
25
33
|
const PLUGIN_NAME = "PureAnnotationsPlugin";
|
|
26
34
|
|
|
27
35
|
// Enough to name the offenders without listing every module.
|
|
@@ -46,8 +54,10 @@ const collectStarts = (ast) => {
|
|
|
46
54
|
const starts = [];
|
|
47
55
|
/** @type {Set<number>} */
|
|
48
56
|
const annotated = new Set();
|
|
49
|
-
/** @type {
|
|
50
|
-
const queue = [
|
|
57
|
+
/** @type {AstValue[]} */
|
|
58
|
+
const queue = [
|
|
59
|
+
/** @type {AstValue} */ (/** @type {Program | AstValue} */ (ast))
|
|
60
|
+
];
|
|
51
61
|
|
|
52
62
|
while (queue.length > 0) {
|
|
53
63
|
const node = queue.pop();
|
|
@@ -55,18 +65,16 @@ const collectStarts = (ast) => {
|
|
|
55
65
|
if (!node || typeof node !== "object") continue;
|
|
56
66
|
|
|
57
67
|
if (Array.isArray(node)) {
|
|
58
|
-
for (const item of
|
|
68
|
+
for (const item of node) queue.push(item);
|
|
59
69
|
continue;
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
// Walked structurally rather than per node type, so a node the estree
|
|
63
73
|
// types do not name is still reached.
|
|
64
|
-
const fields = /** @type {
|
|
74
|
+
const fields = /** @type {AstFields} */ (node);
|
|
65
75
|
const { type, range } = fields;
|
|
66
76
|
|
|
67
|
-
const start = Array.isArray(range)
|
|
68
|
-
? /** @type {unknown[]} */ (range)[0]
|
|
69
|
-
: undefined;
|
|
77
|
+
const start = Array.isArray(range) ? range[0] : undefined;
|
|
70
78
|
|
|
71
79
|
if (typeof type === "string" && typeof start === "number") {
|
|
72
80
|
starts.push(start);
|
|
@@ -151,9 +159,7 @@ class PureAnnotationsPlugin {
|
|
|
151
159
|
|
|
152
160
|
// Kept on the module rather than in a map here, so a module the
|
|
153
161
|
// filesystem cache restores rather than parses still reports.
|
|
154
|
-
const buildInfo =
|
|
155
|
-
parser.state.module.buildInfo
|
|
156
|
-
);
|
|
162
|
+
const buildInfo = parser.state.module.buildInfo;
|
|
157
163
|
|
|
158
164
|
getBuildDiagnostics(buildInfo).ineffectivePureAnnotations = wasted;
|
|
159
165
|
});
|
|
@@ -14,13 +14,21 @@ const {
|
|
|
14
14
|
const { getBuildDiagnostics } = require("../util/buildDiagnostics");
|
|
15
15
|
const { compareStrings } = require("../util/comparators");
|
|
16
16
|
|
|
17
|
-
/** @import {
|
|
17
|
+
/** @import { Program } from "estree" */
|
|
18
18
|
/** @import { PerformanceOptions } from "../../declarations/WebpackOptions" */
|
|
19
19
|
/** @import Compiler from "../Compiler" */
|
|
20
20
|
/** @import Module, { BuildInfo } from "../module/Module" */
|
|
21
21
|
/** @import JavascriptParser from "../javascript/JavascriptParser" */
|
|
22
22
|
/** @import { TopLevelThisDetails } from "../errors/TopLevelThisWarning" */
|
|
23
23
|
|
|
24
|
+
/** @typedef {{ [Key in string]?: AstValue }} AstFields */
|
|
25
|
+
/** @typedef {AstValue[]} AstArray */
|
|
26
|
+
/**
|
|
27
|
+
* A value found while walking an estree AST structurally: a node, a field of
|
|
28
|
+
* one, or a literal's value.
|
|
29
|
+
* @typedef {string | number | boolean | bigint | RegExp | null | undefined | AstArray | AstFields} AstValue
|
|
30
|
+
*/
|
|
31
|
+
|
|
24
32
|
const PLUGIN_NAME = "TopLevelThisPlugin";
|
|
25
33
|
|
|
26
34
|
// Enough to name the offenders without listing every module.
|
|
@@ -41,8 +49,10 @@ const CLASS_TYPES = new Set(["ClassDeclaration", "ClassExpression"]);
|
|
|
41
49
|
*/
|
|
42
50
|
const countTopLevelThis = (ast) => {
|
|
43
51
|
let count = 0;
|
|
44
|
-
/** @type {
|
|
45
|
-
const queue = [
|
|
52
|
+
/** @type {AstValue[]} */
|
|
53
|
+
const queue = [
|
|
54
|
+
/** @type {AstValue} */ (/** @type {Program | AstValue} */ (ast))
|
|
55
|
+
];
|
|
46
56
|
|
|
47
57
|
while (queue.length > 0) {
|
|
48
58
|
const node = queue.pop();
|
|
@@ -50,13 +60,13 @@ const countTopLevelThis = (ast) => {
|
|
|
50
60
|
if (!node || typeof node !== "object") continue;
|
|
51
61
|
|
|
52
62
|
if (Array.isArray(node)) {
|
|
53
|
-
for (const item of
|
|
63
|
+
for (const item of node) queue.push(item);
|
|
54
64
|
continue;
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
// Walked structurally rather than per node type, so a node the estree
|
|
58
68
|
// types do not name is still reached.
|
|
59
|
-
const fields = /** @type {
|
|
69
|
+
const fields = /** @type {AstFields} */ (node);
|
|
60
70
|
const { type } = fields;
|
|
61
71
|
|
|
62
72
|
if (typeof type !== "string") continue;
|
|
@@ -71,7 +81,7 @@ const countTopLevelThis = (ast) => {
|
|
|
71
81
|
queue.push(fields.superClass);
|
|
72
82
|
|
|
73
83
|
const body =
|
|
74
|
-
/** @type {{ body: { computed?: boolean, key?:
|
|
84
|
+
/** @type {{ body: { computed?: boolean, key?: AstValue }[] } | null | undefined} */
|
|
75
85
|
(fields.body);
|
|
76
86
|
|
|
77
87
|
for (const element of (body && body.body) || []) {
|
|
@@ -130,9 +140,7 @@ class TopLevelThisPlugin {
|
|
|
130
140
|
|
|
131
141
|
// Kept on the module rather than in a map here, so a module the
|
|
132
142
|
// filesystem cache restores rather than parses still reports.
|
|
133
|
-
const buildInfo =
|
|
134
|
-
/** @type {BuildInfo} */
|
|
135
|
-
(parser.state.module.buildInfo);
|
|
143
|
+
const buildInfo = parser.state.module.buildInfo;
|
|
136
144
|
|
|
137
145
|
getBuildDiagnostics(buildInfo).topLevelThis = count;
|
|
138
146
|
});
|
|
@@ -558,7 +558,7 @@ const collectStartupAssetHintLines = (
|
|
|
558
558
|
if (urlDep.mediaAttribute) existing.media = urlDep.mediaAttribute;
|
|
559
559
|
} else {
|
|
560
560
|
perAsset.set(key, {
|
|
561
|
-
assetModule
|
|
561
|
+
assetModule,
|
|
562
562
|
originModule: module,
|
|
563
563
|
request: dep.request,
|
|
564
564
|
preload: Boolean(dep.preload),
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
|
|
9
|
+
const isGeneratorLowered = require("../async-modules/isGeneratorLowered");
|
|
8
10
|
const ModuleDependency = require("../dependencies/core/ModuleDependency");
|
|
9
11
|
const Dependency = require("../graph/Dependency");
|
|
10
12
|
const { isInlinedUsedName } = require("../optimize/InlineExports");
|
|
@@ -16,6 +18,7 @@ const { propertyAccess } = require("../util/property");
|
|
|
16
18
|
/** @import { ReplaceSource } from "webpack-sources" */
|
|
17
19
|
/**
|
|
18
20
|
* @import {
|
|
21
|
+
* DependencyKinds,
|
|
19
22
|
* ReferencedExports,
|
|
20
23
|
* UpdateHashContext,
|
|
21
24
|
* ExportInfoName
|
|
@@ -103,6 +106,9 @@ class ProvidedDependency extends ModuleDependency {
|
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
108
|
|
|
109
|
+
/** @type {Set<keyof DependencyKinds>} */
|
|
110
|
+
ProvidedDependency.KINDS = new Set([...ModuleDependency.KINDS, "provided"]);
|
|
111
|
+
|
|
106
112
|
makeSerializable(ProvidedDependency, [
|
|
107
113
|
"webpack/lib/provide/ProvidedDependency",
|
|
108
114
|
// TODO in the next major release: remove, they restore pre-move cache packs
|
|
@@ -121,6 +127,7 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
|
|
|
121
127
|
dependency,
|
|
122
128
|
source,
|
|
123
129
|
{
|
|
130
|
+
module,
|
|
124
131
|
runtime,
|
|
125
132
|
runtimeTemplate,
|
|
126
133
|
moduleGraph,
|
|
@@ -143,24 +150,49 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
|
|
|
143
150
|
runtimeRequirements
|
|
144
151
|
});
|
|
145
152
|
|
|
153
|
+
// An async module only exposes its exports once awaited, and only an ESM
|
|
154
|
+
// consumer is async itself (see `InferAsyncModulesPlugin`).
|
|
155
|
+
const isAsync =
|
|
156
|
+
moduleGraph.isAsync(connection.module) && moduleGraph.isAsync(module);
|
|
157
|
+
const target = isAsync ? dep.identifier : moduleRaw;
|
|
146
158
|
const provided = !usedName
|
|
147
|
-
?
|
|
159
|
+
? target
|
|
148
160
|
: isInlinedUsedName(usedName)
|
|
149
|
-
? `(${
|
|
161
|
+
? `(${target}, ${usedName.render(
|
|
150
162
|
Template.toNormalComment(
|
|
151
163
|
`inlined export ${propertyAccess(dep.ids)}`
|
|
152
164
|
)
|
|
153
165
|
)})`
|
|
154
|
-
: `${
|
|
166
|
+
: `${target}${propertyAccess(/** @type {string[]} */ (usedName), 0)}`;
|
|
155
167
|
|
|
156
168
|
initFragments.push(
|
|
157
169
|
new InitFragment(
|
|
158
|
-
`/* provided dependency */ var ${dep.identifier} = ${
|
|
170
|
+
`/* provided dependency */ var ${dep.identifier} = ${
|
|
171
|
+
isAsync ? moduleRaw : provided
|
|
172
|
+
};\n`,
|
|
159
173
|
InitFragment.STAGE_PROVIDES,
|
|
160
174
|
1,
|
|
161
175
|
`provided ${dep.identifier}`
|
|
162
176
|
)
|
|
163
177
|
);
|
|
178
|
+
if (isAsync) {
|
|
179
|
+
initFragments.push(
|
|
180
|
+
new AwaitDependenciesInitFragment(
|
|
181
|
+
new Map([[dep.identifier, dep.identifier]]),
|
|
182
|
+
isGeneratorLowered(module, moduleGraph, runtimeTemplate)
|
|
183
|
+
)
|
|
184
|
+
);
|
|
185
|
+
if (provided !== target) {
|
|
186
|
+
initFragments.push(
|
|
187
|
+
new InitFragment(
|
|
188
|
+
`${dep.identifier} = ${provided};\n`,
|
|
189
|
+
InitFragment.STAGE_ASYNC_ESM_IMPORTS,
|
|
190
|
+
1,
|
|
191
|
+
`provided async ${dep.identifier}`
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
164
196
|
source.replace(dep.range[0], dep.range[1] - 1, dep.identifier);
|
|
165
197
|
}
|
|
166
198
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @typedef {import("./RuleSetCompiler").KeysOfTypes<T, V>} KeysOfTypes
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
/** @typedef {KeysOfTypes<RuleSetRule, string | boolean |
|
|
18
|
+
/** @typedef {KeysOfTypes<RuleSetRule, string | boolean | EXPECTED_OBJECT>} BasicEffectRuleKeys */
|
|
19
19
|
|
|
20
20
|
const PLUGIN_NAME = "BasicEffectRulePlugin";
|
|
21
21
|
|
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
} = require("../util/identifier");
|
|
14
14
|
|
|
15
15
|
/** @import { ResolveRequest } from "enhanced-resolve" */
|
|
16
|
+
/** @import { JsonValue } from "../fs/fs" */
|
|
16
17
|
/**
|
|
17
18
|
* @import {
|
|
18
19
|
* Falsy,
|
|
@@ -84,7 +85,7 @@ const {
|
|
|
84
85
|
* Defines the effect use type used by this module.
|
|
85
86
|
* @typedef {object} EffectUse
|
|
86
87
|
* @property {EffectUseType} type
|
|
87
|
-
* @property {{ loader: string, options?:
|
|
88
|
+
* @property {{ loader: string, options?: RuleSetLoaderOptions | null, ident?: string }} value
|
|
88
89
|
*/
|
|
89
90
|
|
|
90
91
|
/**
|
|
@@ -164,7 +165,7 @@ class RuleSetCompiler {
|
|
|
164
165
|
for (const condition of rule.conditions) {
|
|
165
166
|
const p = condition.property;
|
|
166
167
|
if (Array.isArray(p)) {
|
|
167
|
-
/** @type {
|
|
168
|
+
/** @type {EffectData | EffectData[keyof EffectData] | JsonValue} */
|
|
168
169
|
let current = data;
|
|
169
170
|
for (const subProperty of p) {
|
|
170
171
|
if (
|
|
@@ -172,14 +173,22 @@ class RuleSetCompiler {
|
|
|
172
173
|
typeof current === "object" &&
|
|
173
174
|
Object.prototype.hasOwnProperty.call(current, subProperty)
|
|
174
175
|
) {
|
|
175
|
-
current =
|
|
176
|
+
current = /** @type {Record<string, JsonValue>} */ (current)[
|
|
177
|
+
subProperty
|
|
178
|
+
];
|
|
176
179
|
} else {
|
|
177
180
|
current = undefined;
|
|
178
181
|
break;
|
|
179
182
|
}
|
|
180
183
|
}
|
|
181
184
|
if (current !== undefined) {
|
|
182
|
-
if (
|
|
185
|
+
if (
|
|
186
|
+
!condition.fn(
|
|
187
|
+
/** @type {EffectData[keyof EffectData]} */ (current)
|
|
188
|
+
)
|
|
189
|
+
) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
183
192
|
continue;
|
|
184
193
|
}
|
|
185
194
|
} else if (p in data) {
|
|
@@ -526,8 +535,9 @@ class RuleSetCompiler {
|
|
|
526
535
|
|
|
527
536
|
/**
|
|
528
537
|
* Returns an error object.
|
|
538
|
+
* @template T
|
|
529
539
|
* @param {string} path current path
|
|
530
|
-
* @param {
|
|
540
|
+
* @param {T} value value at the error location
|
|
531
541
|
* @param {string} message message explaining the problem
|
|
532
542
|
* @returns {Error} an error object
|
|
533
543
|
*/
|
|
@@ -9,6 +9,7 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
|
|
|
9
9
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
10
10
|
|
|
11
11
|
/** @import Compilation from "../Compilation" */
|
|
12
|
+
/** @import Chunk from "../graph/Chunk" */
|
|
12
13
|
|
|
13
14
|
class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
14
15
|
/**
|
|
@@ -32,6 +33,11 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
|
32
33
|
const { runtimeTemplate } = compilation;
|
|
33
34
|
const fn = RuntimeGlobals.asyncModule;
|
|
34
35
|
const defer = this._deferInterop;
|
|
36
|
+
const exposeExports =
|
|
37
|
+
defer ||
|
|
38
|
+
compilation.chunkGraph
|
|
39
|
+
.getTreeRuntimeRequirements(/** @type {Chunk} */ (this.chunk))
|
|
40
|
+
.has(RuntimeGlobals.asyncModuleExportSymbol);
|
|
35
41
|
const strictErrors = this._strictModuleErrorHandling;
|
|
36
42
|
const moduleCache = this.receivesHotUpdates()
|
|
37
43
|
? RuntimeGlobals.moduleCache
|
|
@@ -54,7 +60,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
|
54
60
|
: [`${cst} hasSymbol = typeof Symbol === "function";`]),
|
|
55
61
|
`${cst} webpackQueues = ${renderSymbol("webpack queues", "__webpack_queues__")};`,
|
|
56
62
|
`${cst} webpackExports = ${
|
|
57
|
-
|
|
63
|
+
exposeExports ? `${RuntimeGlobals.asyncModuleExportSymbol}= ` : ""
|
|
58
64
|
}${renderSymbol("webpack exports", RuntimeGlobals.exports)};`,
|
|
59
65
|
`${cst} webpackError = ${renderSymbol("webpack error", "__webpack_error__")};`,
|
|
60
66
|
...(strictErrors ? [`${cst} cycleGroups = {};`] : []),
|