webpack 5.76.1 → 5.88.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +10 -4
- package/bin/webpack.js +26 -2
- package/hot/dev-server.js +2 -1
- package/hot/lazy-compilation-node.js +10 -0
- package/hot/lazy-compilation-web.js +9 -0
- package/hot/log-apply-result.js +5 -0
- package/hot/log.js +22 -0
- package/hot/only-dev-server.js +2 -1
- package/hot/poll.js +3 -0
- package/hot/signal.js +4 -0
- package/lib/APIPlugin.js +174 -116
- package/lib/AsyncDependenciesBlock.js +13 -5
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +6 -1
- package/lib/CacheFacade.js +4 -0
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +36 -18
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +25 -10
- package/lib/CleanPlugin.js +30 -7
- package/lib/CodeGenerationResults.js +2 -2
- package/lib/CompatibilityPlugin.js +85 -46
- package/lib/Compilation.js +17 -8
- package/lib/Compiler.js +18 -14
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +95 -47
- package/lib/ContextModule.js +20 -6
- package/lib/ContextModuleFactory.js +2 -1
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/CssModule.js +169 -0
- package/lib/DefinePlugin.js +152 -86
- package/lib/DelegatedModule.js +22 -4
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/DependenciesBlock.js +17 -1
- package/lib/Dependency.js +19 -5
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllEntryPlugin.js +16 -1
- package/lib/DllModule.js +17 -2
- package/lib/DllModuleFactory.js +1 -1
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +62 -22
- package/lib/EvalSourceMapDevToolPlugin.js +9 -2
- package/lib/ExportsInfo.js +25 -4
- package/lib/ExportsInfoApiPlugin.js +30 -14
- package/lib/ExternalModule.js +30 -9
- package/lib/FileSystemInfo.js +61 -25
- package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
- package/lib/FlagDependencyExportsPlugin.js +336 -348
- package/lib/FlagDependencyUsagePlugin.js +9 -9
- package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
- package/lib/Generator.js +7 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +60 -46
- package/lib/IgnoreErrorModuleFactory.js +1 -1
- package/lib/InitFragment.js +28 -5
- package/lib/JavascriptMetaInfoPlugin.js +27 -15
- package/lib/LibManifestPlugin.js +22 -5
- package/lib/LoaderOptionsPlugin.js +12 -2
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +44 -12
- package/lib/ModuleBuildError.js +9 -0
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleError.js +9 -0
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleFilenameHelpers.js +114 -4
- package/lib/ModuleGraph.js +33 -23
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleParseError.js +9 -0
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +169 -0
- package/lib/ModuleWarning.js +9 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/NodeStuffPlugin.js +65 -35
- package/lib/NormalModule.js +12 -2
- package/lib/NormalModuleFactory.js +56 -8
- package/lib/NormalModuleReplacementPlugin.js +5 -3
- package/lib/NullFactory.js +1 -1
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/ProgressPlugin.js +71 -15
- package/lib/ProvidePlugin.js +30 -14
- package/lib/RawModule.js +13 -2
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/RequireJsStuffPlugin.js +22 -15
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +12 -11
- package/lib/RuntimePlugin.js +10 -3
- package/lib/RuntimeTemplate.js +29 -11
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +47 -11
- package/lib/Template.js +5 -3
- package/lib/UseStrictPlugin.js +29 -11
- package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
- package/lib/WarnDeprecatedOptionPlugin.js +7 -0
- package/lib/WatchIgnorePlugin.js +4 -0
- package/lib/Watching.js +62 -25
- package/lib/WebpackError.js +14 -5
- package/lib/WebpackIsIncludedPlugin.js +22 -13
- package/lib/WebpackOptionsApply.js +41 -44
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +24 -9
- package/lib/asset/AssetModulesPlugin.js +28 -12
- package/lib/asset/AssetParser.js +15 -7
- package/lib/asset/AssetSourceParser.js +8 -3
- package/lib/asset/RawDataUrlModule.js +15 -4
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/buildChunkGraph.js +37 -21
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
- package/lib/cache/PackFileCacheStrategy.js +59 -22
- package/lib/cache/ResolverCachePlugin.js +3 -0
- package/lib/config/browserslistTargetHandler.js +10 -10
- package/lib/config/defaults.js +306 -105
- package/lib/config/normalization.js +110 -71
- package/lib/config/target.js +37 -10
- package/lib/container/ContainerEntryModule.js +11 -1
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/ContainerExposedDependency.js +9 -0
- package/lib/container/ContainerPlugin.js +3 -1
- package/lib/container/FallbackDependency.js +13 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +12 -2
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/RemoteModule.js +11 -1
- package/lib/container/RemoteRuntimeModule.js +3 -2
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +5 -1
- package/lib/css/CssLoadingRuntimeModule.js +53 -22
- package/lib/css/CssModulesPlugin.js +253 -74
- package/lib/css/CssParser.js +697 -282
- package/lib/css/walkCssTokens.js +269 -138
- package/lib/debug/ProfilingPlugin.js +33 -12
- package/lib/dependencies/AMDDefineDependency.js +54 -10
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +13 -2
- package/lib/dependencies/AMDPlugin.js +33 -20
- package/lib/dependencies/AMDRequireArrayDependency.js +13 -0
- package/lib/dependencies/AMDRequireContextDependency.js +15 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
- package/lib/dependencies/AMDRequireDependency.js +16 -1
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CachedConstDependency.js +14 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
- package/lib/dependencies/CommonJsExportsDependency.js +16 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +77 -5
- package/lib/dependencies/CommonJsFullRequireDependency.js +10 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +174 -63
- package/lib/dependencies/CommonJsPlugin.js +51 -26
- package/lib/dependencies/CommonJsRequireContextDependency.js +17 -0
- package/lib/dependencies/CommonJsRequireDependency.js +7 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +16 -0
- package/lib/dependencies/ConstDependency.js +11 -2
- package/lib/dependencies/ContextDependency.js +15 -2
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/ContextElementDependency.js +8 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +10 -1
- package/lib/dependencies/CriticalDependencyWarning.js +3 -0
- package/lib/dependencies/CssExportDependency.js +8 -0
- package/lib/dependencies/CssImportDependency.js +55 -3
- package/lib/dependencies/CssLocalIdentifierDependency.js +18 -1
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +10 -1
- package/lib/dependencies/CssUrlDependency.js +46 -16
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/DllEntryDependency.js +14 -0
- package/lib/dependencies/DynamicExports.js +10 -6
- package/lib/dependencies/ExportsInfoDependency.js +25 -4
- package/lib/dependencies/HarmonyAcceptDependency.js +10 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +32 -6
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +5 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +20 -3
- package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +22 -6
- package/lib/dependencies/HarmonyExportInitFragment.js +2 -1
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
- package/lib/dependencies/HarmonyExports.js +11 -5
- package/lib/dependencies/HarmonyImportDependency.js +10 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +53 -22
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +139 -16
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -5
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportContextDependency.js +15 -0
- package/lib/dependencies/ImportDependency.js +15 -4
- package/lib/dependencies/ImportEagerDependency.js +7 -4
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +51 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +18 -5
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportMetaPlugin.js +103 -51
- package/lib/dependencies/ImportParserPlugin.js +83 -25
- package/lib/dependencies/ImportPlugin.js +21 -7
- package/lib/dependencies/ImportWeakDependency.js +7 -4
- package/lib/dependencies/JsonExportsDependency.js +9 -1
- package/lib/dependencies/LocalModule.js +16 -0
- package/lib/dependencies/LocalModuleDependency.js +15 -0
- package/lib/dependencies/LocalModulesHelpers.js +18 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
- package/lib/dependencies/ModuleDependency.js +9 -1
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +14 -2
- package/lib/dependencies/PureExpressionDependency.js +10 -1
- package/lib/dependencies/RequireContextDependency.js +6 -0
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
- package/lib/dependencies/RequireContextPlugin.js +19 -6
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
- package/lib/dependencies/RequireEnsureDependency.js +16 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +27 -7
- package/lib/dependencies/RequireHeaderDependency.js +14 -1
- package/lib/dependencies/RequireIncludeDependency.js +5 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
- package/lib/dependencies/RequireIncludePlugin.js +25 -5
- package/lib/dependencies/RequireResolveContextDependency.js +17 -0
- package/lib/dependencies/RequireResolveDependency.js +6 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
- package/lib/dependencies/StaticExportsDependency.js +8 -0
- package/lib/dependencies/SystemPlugin.js +48 -21
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +13 -4
- package/lib/dependencies/URLPlugin.js +31 -18
- package/lib/dependencies/UnsupportedDependency.js +13 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
- package/lib/dependencies/WorkerDependency.js +47 -3
- package/lib/dependencies/WorkerPlugin.js +105 -32
- package/lib/dependencies/getFunctionExpression.js +7 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +21 -8
- package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +19 -12
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +14 -5
- package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
- package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
- package/lib/ids/HashedModuleIdsPlugin.js +9 -2
- package/lib/ids/IdHelpers.js +6 -0
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +14 -3
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +3 -2
- package/lib/index.js +8 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
- package/lib/javascript/BasicEvaluatedExpression.js +137 -11
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +7 -3
- package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
- package/lib/javascript/JavascriptModulesPlugin.js +217 -198
- package/lib/javascript/JavascriptParser.js +941 -256
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonData.js +26 -1
- package/lib/json/JsonGenerator.js +21 -7
- package/lib/json/JsonModulesPlugin.js +14 -5
- package/lib/json/JsonParser.js +27 -13
- package/lib/library/AbstractLibraryPlugin.js +4 -0
- package/lib/library/AmdLibraryPlugin.js +22 -6
- package/lib/library/AssignLibraryPlugin.js +19 -5
- package/lib/library/EnableLibraryPlugin.js +4 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +8 -4
- package/lib/library/SystemLibraryPlugin.js +2 -1
- package/lib/library/UmdLibraryPlugin.js +24 -2
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
- package/lib/node/NodeTargetPlugin.js +3 -0
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +18 -9
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +12 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
- package/lib/node/RequireChunkLoadingRuntimeModule.js +15 -8
- package/lib/node/nodeConsole.js +2 -4
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/ConcatenatedModule.js +8 -6
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +57 -48
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +86 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +53 -44
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +9 -6
- package/lib/runtime/AutoPublicPathRuntimeModule.js +16 -5
- package/lib/runtime/BaseUriRuntimeModule.js +8 -4
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
- package/lib/runtime/CompatRuntimeModule.js +7 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
- package/lib/runtime/EnsureChunkRuntimeModule.js +18 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +45 -26
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +27 -6
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +65 -50
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +9 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +13 -4
- package/lib/runtime/StartupEntrypointRuntimeModule.js +11 -7
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/schemes/DataUriPlugin.js +16 -3
- package/lib/schemes/HttpUriPlugin.js +38 -0
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +164 -1
- package/lib/serialization/DateObjectSerializer.js +15 -4
- package/lib/serialization/ErrorObjectSerializer.js +23 -8
- package/lib/serialization/FileMiddleware.js +17 -0
- package/lib/serialization/MapObjectSerializer.js +24 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
- package/lib/serialization/ObjectMiddleware.js +33 -2
- package/lib/serialization/PlainObjectSerializer.js +23 -12
- package/lib/serialization/RegExpObjectSerializer.js +16 -5
- package/lib/serialization/SetObjectSerializer.js +21 -6
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedModule.js +13 -2
- package/lib/sharing/ConsumeSharedPlugin.js +4 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +22 -7
- package/lib/sharing/ProvideSharedDependency.js +17 -0
- package/lib/sharing/ProvideSharedModule.js +11 -1
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +19 -9
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +320 -7
- package/lib/stats/DefaultStatsFactoryPlugin.js +105 -29
- package/lib/stats/DefaultStatsPresetPlugin.js +9 -0
- package/lib/stats/DefaultStatsPrinterPlugin.js +43 -0
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/LazySet.js +10 -2
- package/lib/util/MapHelpers.js +19 -5
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/StackedCacheMap.js +7 -1
- package/lib/util/StringXor.js +51 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/binarySearchBounds.js +49 -0
- package/lib/util/compileBooleanMatcher.js +31 -0
- package/lib/util/createHash.js +35 -13
- package/lib/util/deprecation.js +18 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +4 -0
- package/lib/util/internalSerializables.js +1 -0
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/memoize.js +3 -3
- package/lib/util/numberHash.js +75 -21
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/propertyAccess.js +9 -54
- package/lib/util/propertyName.js +79 -0
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +84 -21
- package/lib/util/semver.js +2 -1
- package/lib/util/serialization.js +10 -0
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +15 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +14 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +28 -8
- package/lib/wasm-async/AsyncWebAssemblyParser.js +11 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +39 -8
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +19 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
- package/lib/wasm-sync/WebAssemblyParser.js +15 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
- package/lib/web/FetchCompileWasmPlugin.js +59 -42
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +26 -9
- package/lib/webpack.js +12 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +20 -17
- package/module.d.ts +55 -37
- package/package.json +59 -56
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +133 -6
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +8 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +1629 -683
@@ -5,10 +5,19 @@
|
|
5
5
|
"use strict";
|
6
6
|
|
7
7
|
const { Tracer } = require("chrome-trace-event");
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
11
|
+
JAVASCRIPT_MODULE_TYPE_ESM,
|
12
|
+
WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
13
|
+
WEBASSEMBLY_MODULE_TYPE_SYNC,
|
14
|
+
JSON_MODULE_TYPE
|
15
|
+
} = require("../ModuleTypeConstants");
|
8
16
|
const createSchemaValidation = require("../util/create-schema-validation");
|
9
17
|
const { dirname, mkdirpSync } = require("../util/fs");
|
10
18
|
|
11
19
|
/** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
|
20
|
+
/** @typedef {import("../Compiler")} Compiler */
|
12
21
|
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
13
22
|
|
14
23
|
const validate = createSchemaValidation(
|
@@ -64,6 +73,11 @@ class Profiler {
|
|
64
73
|
]);
|
65
74
|
}
|
66
75
|
|
76
|
+
/**
|
77
|
+
* @param {string} method method name
|
78
|
+
* @param {object} [params] params
|
79
|
+
* @returns {Promise<TODO>} Promise for the result
|
80
|
+
*/
|
67
81
|
sendCommand(method, params) {
|
68
82
|
if (this.hasSession()) {
|
69
83
|
return new Promise((res, rej) => {
|
@@ -92,6 +106,8 @@ class Profiler {
|
|
92
106
|
return this.sendCommand("Profiler.stop").then(({ profile }) => {
|
93
107
|
const hrtime = process.hrtime();
|
94
108
|
const endTime = hrtime[0] * 1000000 + Math.round(hrtime[1] / 1000);
|
109
|
+
// Avoid coverage problems due indirect changes
|
110
|
+
/* istanbul ignore next */
|
95
111
|
if (profile.startTime < this._startTime || profile.endTime > endTime) {
|
96
112
|
// In some cases timestamps mismatch and we need to adjust them
|
97
113
|
// Both process.hrtime and the inspector timestamps claim to be relative
|
@@ -182,7 +198,7 @@ const createTrace = (fs, outputPath) => {
|
|
182
198
|
};
|
183
199
|
};
|
184
200
|
|
185
|
-
const
|
201
|
+
const PLUGIN_NAME = "ProfilingPlugin";
|
186
202
|
|
187
203
|
class ProfilingPlugin {
|
188
204
|
/**
|
@@ -193,6 +209,11 @@ class ProfilingPlugin {
|
|
193
209
|
this.outputPath = options.outputPath || "events.json";
|
194
210
|
}
|
195
211
|
|
212
|
+
/**
|
213
|
+
* Apply the plugin
|
214
|
+
* @param {Compiler} compiler the compiler instance
|
215
|
+
* @returns {void}
|
216
|
+
*/
|
196
217
|
apply(compiler) {
|
197
218
|
const tracer = createTrace(
|
198
219
|
compiler.intermediateFileSystem,
|
@@ -216,7 +237,7 @@ class ProfilingPlugin {
|
|
216
237
|
});
|
217
238
|
|
218
239
|
compiler.hooks.compilation.tap(
|
219
|
-
|
240
|
+
PLUGIN_NAME,
|
220
241
|
(compilation, { normalModuleFactory, contextModuleFactory }) => {
|
221
242
|
interceptAllHooksFor(compilation, tracer, "Compilation");
|
222
243
|
interceptAllHooksFor(
|
@@ -237,7 +258,7 @@ class ProfilingPlugin {
|
|
237
258
|
// We need to write out the CPU profile when we are all done.
|
238
259
|
compiler.hooks.done.tapAsync(
|
239
260
|
{
|
240
|
-
name:
|
261
|
+
name: PLUGIN_NAME,
|
241
262
|
stage: Infinity
|
242
263
|
},
|
243
264
|
(stats, callback) => {
|
@@ -312,18 +333,18 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
|
|
312
333
|
|
313
334
|
const interceptAllParserHooks = (moduleFactory, tracer) => {
|
314
335
|
const moduleTypes = [
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
336
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
337
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
338
|
+
JAVASCRIPT_MODULE_TYPE_ESM,
|
339
|
+
JSON_MODULE_TYPE,
|
340
|
+
WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
341
|
+
WEBASSEMBLY_MODULE_TYPE_SYNC
|
321
342
|
];
|
322
343
|
|
323
344
|
moduleTypes.forEach(moduleType => {
|
324
345
|
moduleFactory.hooks.parser
|
325
346
|
.for(moduleType)
|
326
|
-
.tap(
|
347
|
+
.tap(PLUGIN_NAME, (parser, parserOpts) => {
|
327
348
|
interceptAllHooksFor(parser, tracer, "Parser");
|
328
349
|
});
|
329
350
|
});
|
@@ -347,7 +368,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
|
|
347
368
|
const { name, type, fn } = tapInfo;
|
348
369
|
const newFn =
|
349
370
|
// Don't tap our own hooks to ensure stream can close cleanly
|
350
|
-
name ===
|
371
|
+
name === PLUGIN_NAME
|
351
372
|
? fn
|
352
373
|
: makeNewProfiledTapFn(hookName, tracer, {
|
353
374
|
name,
|
@@ -418,7 +439,7 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
|
|
418
439
|
const id = ++tracer.counter;
|
419
440
|
// Do not instrument ourself due to the CPU
|
420
441
|
// profile needing to be the last event in the trace.
|
421
|
-
if (name ===
|
442
|
+
if (name === PLUGIN_NAME) {
|
422
443
|
return fn(...args);
|
423
444
|
}
|
424
445
|
|
@@ -12,12 +12,15 @@ const NullDependency = require("./NullDependency");
|
|
12
12
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
13
13
|
/** @typedef {import("../Dependency")} Dependency */
|
14
14
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
15
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
16
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
17
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
15
18
|
|
16
19
|
/** @type {Record<string, { definition: string, content: string, requests: string[] }>} */
|
17
20
|
const DEFINITIONS = {
|
18
21
|
f: {
|
19
22
|
definition: "var __WEBPACK_AMD_DEFINE_RESULT__;",
|
20
|
-
content: `!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports,
|
23
|
+
content: `!(__WEBPACK_AMD_DEFINE_RESULT__ = (#).call(exports, ${RuntimeGlobals.require}, exports, module),
|
21
24
|
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`,
|
22
25
|
requests: [
|
23
26
|
RuntimeGlobals.require,
|
@@ -35,7 +38,7 @@ const DEFINITIONS = {
|
|
35
38
|
"var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;",
|
36
39
|
content: `!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#),
|
37
40
|
__WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
|
38
|
-
(__WEBPACK_AMD_DEFINE_FACTORY__.call(exports,
|
41
|
+
(__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, ${RuntimeGlobals.require}, exports, module)) :
|
39
42
|
__WEBPACK_AMD_DEFINE_FACTORY__),
|
40
43
|
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`,
|
41
44
|
requests: [
|
@@ -67,8 +70,7 @@ const DEFINITIONS = {
|
|
67
70
|
},
|
68
71
|
lf: {
|
69
72
|
definition: "var XXX, XXXmodule;",
|
70
|
-
content:
|
71
|
-
"!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = (#).call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))",
|
73
|
+
content: `!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = (#).call(XXXmodule.exports, ${RuntimeGlobals.require}, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))`,
|
72
74
|
requests: [RuntimeGlobals.require, RuntimeGlobals.module]
|
73
75
|
},
|
74
76
|
lo: {
|
@@ -78,8 +80,7 @@ const DEFINITIONS = {
|
|
78
80
|
},
|
79
81
|
lof: {
|
80
82
|
definition: "var XXX, XXXfactory, XXXmodule;",
|
81
|
-
content:
|
82
|
-
"!(XXXfactory = (#), (typeof XXXfactory === 'function' ? ((XXXmodule = { id: YYY, exports: {}, loaded: false }), (XXX = XXXfactory.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule)), (XXXmodule.loaded = true), XXX === undefined && (XXX = XXXmodule.exports)) : XXX = XXXfactory))",
|
83
|
+
content: `!(XXXfactory = (#), (typeof XXXfactory === 'function' ? ((XXXmodule = { id: YYY, exports: {}, loaded: false }), (XXX = XXXfactory.call(XXXmodule.exports, ${RuntimeGlobals.require}, XXXmodule.exports, XXXmodule)), (XXXmodule.loaded = true), XXX === undefined && (XXX = XXXmodule.exports)) : XXX = XXXfactory))`,
|
83
84
|
requests: [RuntimeGlobals.require, RuntimeGlobals.module]
|
84
85
|
},
|
85
86
|
laf: {
|
@@ -105,6 +106,13 @@ const DEFINITIONS = {
|
|
105
106
|
};
|
106
107
|
|
107
108
|
class AMDDefineDependency extends NullDependency {
|
109
|
+
/**
|
110
|
+
* @param {Range} range range
|
111
|
+
* @param {Range} arrayRange array range
|
112
|
+
* @param {Range} functionRange function range
|
113
|
+
* @param {Range} objectRange object range
|
114
|
+
* @param {boolean} namedModule true, when define is called with a name
|
115
|
+
*/
|
108
116
|
constructor(range, arrayRange, functionRange, objectRange, namedModule) {
|
109
117
|
super();
|
110
118
|
this.range = range;
|
@@ -119,6 +127,9 @@ class AMDDefineDependency extends NullDependency {
|
|
119
127
|
return "amd define";
|
120
128
|
}
|
121
129
|
|
130
|
+
/**
|
131
|
+
* @param {ObjectSerializerContext} context context
|
132
|
+
*/
|
122
133
|
serialize(context) {
|
123
134
|
const { write } = context;
|
124
135
|
write(this.range);
|
@@ -130,6 +141,9 @@ class AMDDefineDependency extends NullDependency {
|
|
130
141
|
super.serialize(context);
|
131
142
|
}
|
132
143
|
|
144
|
+
/**
|
145
|
+
* @param {ObjectDeserializerContext} context context
|
146
|
+
*/
|
133
147
|
deserialize(context) {
|
134
148
|
const { read } = context;
|
135
149
|
this.range = read();
|
@@ -166,6 +180,10 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
|
|
166
180
|
this.replace(dep, source, definition, content);
|
167
181
|
}
|
168
182
|
|
183
|
+
/**
|
184
|
+
* @param {AMDDefineDependency} dependency dependency
|
185
|
+
* @returns {string} variable name
|
186
|
+
*/
|
169
187
|
localModuleVar(dependency) {
|
170
188
|
return (
|
171
189
|
dependency.localModule &&
|
@@ -174,6 +192,10 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
|
|
174
192
|
);
|
175
193
|
}
|
176
194
|
|
195
|
+
/**
|
196
|
+
* @param {AMDDefineDependency} dependency dependency
|
197
|
+
* @returns {string} branch
|
198
|
+
*/
|
177
199
|
branch(dependency) {
|
178
200
|
const localModuleVar = this.localModuleVar(dependency) ? "l" : "";
|
179
201
|
const arrayRange = dependency.arrayRange ? "a" : "";
|
@@ -182,6 +204,12 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
|
|
182
204
|
return localModuleVar + arrayRange + objectRange + functionRange;
|
183
205
|
}
|
184
206
|
|
207
|
+
/**
|
208
|
+
* @param {AMDDefineDependency} dependency dependency
|
209
|
+
* @param {ReplaceSource} source source
|
210
|
+
* @param {string} definition definition
|
211
|
+
* @param {string} text text
|
212
|
+
*/
|
185
213
|
replace(dependency, source, definition, text) {
|
186
214
|
const localModuleVar = this.localModuleVar(dependency);
|
187
215
|
if (localModuleVar) {
|
@@ -202,18 +230,34 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate extends (
|
|
202
230
|
|
203
231
|
let current = dependency.range[0];
|
204
232
|
if (dependency.arrayRange) {
|
205
|
-
source.replace(
|
233
|
+
source.replace(
|
234
|
+
current,
|
235
|
+
dependency.arrayRange[0] - 1,
|
236
|
+
/** @type {string} */ (texts.shift())
|
237
|
+
);
|
206
238
|
current = dependency.arrayRange[1];
|
207
239
|
}
|
208
240
|
|
209
241
|
if (dependency.objectRange) {
|
210
|
-
source.replace(
|
242
|
+
source.replace(
|
243
|
+
current,
|
244
|
+
dependency.objectRange[0] - 1,
|
245
|
+
/** @type {string} */ (texts.shift())
|
246
|
+
);
|
211
247
|
current = dependency.objectRange[1];
|
212
248
|
} else if (dependency.functionRange) {
|
213
|
-
source.replace(
|
249
|
+
source.replace(
|
250
|
+
current,
|
251
|
+
dependency.functionRange[0] - 1,
|
252
|
+
/** @type {string} */ (texts.shift())
|
253
|
+
);
|
214
254
|
current = dependency.functionRange[1];
|
215
255
|
}
|
216
|
-
source.replace(
|
256
|
+
source.replace(
|
257
|
+
current,
|
258
|
+
dependency.range[1] - 1,
|
259
|
+
/** @type {string} */ (texts.shift())
|
260
|
+
);
|
217
261
|
if (texts.length > 0) throw new Error("Implementation error");
|
218
262
|
}
|
219
263
|
};
|
@@ -16,6 +16,13 @@ const DynamicExports = require("./DynamicExports");
|
|
16
16
|
const LocalModuleDependency = require("./LocalModuleDependency");
|
17
17
|
const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
|
18
18
|
|
19
|
+
/** @typedef {import("estree").CallExpression} CallExpression */
|
20
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @param {CallExpression} expr expression
|
24
|
+
* @returns {boolean} true if it's a bound function expression
|
25
|
+
*/
|
19
26
|
const isBoundFunctionExpression = expr => {
|
20
27
|
if (expr.type !== "CallExpression") return false;
|
21
28
|
if (expr.callee.type !== "MemberExpression") return false;
|
@@ -43,6 +50,10 @@ class AMDDefineDependencyParserPlugin {
|
|
43
50
|
this.options = options;
|
44
51
|
}
|
45
52
|
|
53
|
+
/**
|
54
|
+
* @param {JavascriptParser} parser the parser
|
55
|
+
* @returns {void}
|
56
|
+
*/
|
46
57
|
apply(parser) {
|
47
58
|
parser.hooks.call
|
48
59
|
.for("define")
|
@@ -73,7 +84,7 @@ class AMDDefineDependencyParserPlugin {
|
|
73
84
|
let localModule;
|
74
85
|
if (request === "require") {
|
75
86
|
identifiers[idx] = request;
|
76
|
-
dep =
|
87
|
+
dep = RuntimeGlobals.require;
|
77
88
|
} else if (["exports", "module"].includes(request)) {
|
78
89
|
identifiers[idx] = request;
|
79
90
|
dep = request;
|
@@ -109,7 +120,7 @@ class AMDDefineDependencyParserPlugin {
|
|
109
120
|
} else if (param.isString()) {
|
110
121
|
let dep, localModule;
|
111
122
|
if (param.string === "require") {
|
112
|
-
dep = new ConstDependency(
|
123
|
+
dep = new ConstDependency(RuntimeGlobals.require, param.range, [
|
113
124
|
RuntimeGlobals.require
|
114
125
|
]);
|
115
126
|
} else if (param.string === "exports") {
|
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const {
|
9
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
10
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC
|
11
|
+
} = require("../ModuleTypeConstants");
|
8
12
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
13
|
const {
|
10
14
|
approve,
|
@@ -28,8 +32,12 @@ const ConstDependency = require("./ConstDependency");
|
|
28
32
|
const LocalModuleDependency = require("./LocalModuleDependency");
|
29
33
|
const UnsupportedDependency = require("./UnsupportedDependency");
|
30
34
|
|
35
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
31
36
|
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
32
37
|
/** @typedef {import("../Compiler")} Compiler */
|
38
|
+
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
39
|
+
|
40
|
+
const PLUGIN_NAME = "AMDPlugin";
|
33
41
|
|
34
42
|
class AMDPlugin {
|
35
43
|
/**
|
@@ -47,7 +55,7 @@ class AMDPlugin {
|
|
47
55
|
apply(compiler) {
|
48
56
|
const amdOptions = this.amdOptions;
|
49
57
|
compiler.hooks.compilation.tap(
|
50
|
-
|
58
|
+
PLUGIN_NAME,
|
51
59
|
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
52
60
|
compilation.dependencyTemplates.set(
|
53
61
|
AMDRequireDependency,
|
@@ -94,31 +102,36 @@ class AMDPlugin {
|
|
94
102
|
|
95
103
|
compilation.hooks.runtimeRequirementInModule
|
96
104
|
.for(RuntimeGlobals.amdDefine)
|
97
|
-
.tap(
|
105
|
+
.tap(PLUGIN_NAME, (module, set) => {
|
98
106
|
set.add(RuntimeGlobals.require);
|
99
107
|
});
|
100
108
|
|
101
109
|
compilation.hooks.runtimeRequirementInModule
|
102
110
|
.for(RuntimeGlobals.amdOptions)
|
103
|
-
.tap(
|
111
|
+
.tap(PLUGIN_NAME, (module, set) => {
|
104
112
|
set.add(RuntimeGlobals.requireScope);
|
105
113
|
});
|
106
114
|
|
107
115
|
compilation.hooks.runtimeRequirementInTree
|
108
116
|
.for(RuntimeGlobals.amdDefine)
|
109
|
-
.tap(
|
117
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
110
118
|
compilation.addRuntimeModule(chunk, new AMDDefineRuntimeModule());
|
111
119
|
});
|
112
120
|
|
113
121
|
compilation.hooks.runtimeRequirementInTree
|
114
122
|
.for(RuntimeGlobals.amdOptions)
|
115
|
-
.tap(
|
123
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
116
124
|
compilation.addRuntimeModule(
|
117
125
|
chunk,
|
118
126
|
new AMDOptionsRuntimeModule(amdOptions)
|
119
127
|
);
|
120
128
|
});
|
121
129
|
|
130
|
+
/**
|
131
|
+
* @param {Parser} parser parser parser
|
132
|
+
* @param {JavascriptParserOptions} parserOptions parserOptions
|
133
|
+
* @returns {void}
|
134
|
+
*/
|
122
135
|
const handler = (parser, parserOptions) => {
|
123
136
|
if (parserOptions.amd !== undefined && !parserOptions.amd) return;
|
124
137
|
|
@@ -126,7 +139,7 @@ class AMDPlugin {
|
|
126
139
|
parser.hooks.expression
|
127
140
|
.for(optionExpr)
|
128
141
|
.tap(
|
129
|
-
|
142
|
+
PLUGIN_NAME,
|
130
143
|
toConstantDependency(parser, RuntimeGlobals.amdOptions, [
|
131
144
|
RuntimeGlobals.amdOptions
|
132
145
|
])
|
@@ -134,16 +147,16 @@ class AMDPlugin {
|
|
134
147
|
parser.hooks.evaluateIdentifier
|
135
148
|
.for(optionExpr)
|
136
149
|
.tap(
|
137
|
-
|
150
|
+
PLUGIN_NAME,
|
138
151
|
evaluateToIdentifier(optionExpr, rootName, getMembers, true)
|
139
152
|
);
|
140
153
|
parser.hooks.evaluateTypeof
|
141
154
|
.for(optionExpr)
|
142
|
-
.tap(
|
155
|
+
.tap(PLUGIN_NAME, evaluateToString("object"));
|
143
156
|
parser.hooks.typeof
|
144
157
|
.for(optionExpr)
|
145
158
|
.tap(
|
146
|
-
|
159
|
+
PLUGIN_NAME,
|
147
160
|
toConstantDependency(parser, JSON.stringify("object"))
|
148
161
|
);
|
149
162
|
};
|
@@ -161,7 +174,7 @@ class AMDPlugin {
|
|
161
174
|
() => []
|
162
175
|
);
|
163
176
|
|
164
|
-
parser.hooks.expression.for("define").tap(
|
177
|
+
parser.hooks.expression.for("define").tap(PLUGIN_NAME, expr => {
|
165
178
|
const dep = new ConstDependency(
|
166
179
|
RuntimeGlobals.amdDefine,
|
167
180
|
expr.range,
|
@@ -174,14 +187,14 @@ class AMDPlugin {
|
|
174
187
|
parser.hooks.typeof
|
175
188
|
.for("define")
|
176
189
|
.tap(
|
177
|
-
|
190
|
+
PLUGIN_NAME,
|
178
191
|
toConstantDependency(parser, JSON.stringify("function"))
|
179
192
|
);
|
180
193
|
parser.hooks.evaluateTypeof
|
181
194
|
.for("define")
|
182
|
-
.tap(
|
183
|
-
parser.hooks.canRename.for("define").tap(
|
184
|
-
parser.hooks.rename.for("define").tap(
|
195
|
+
.tap(PLUGIN_NAME, evaluateToString("function"));
|
196
|
+
parser.hooks.canRename.for("define").tap(PLUGIN_NAME, approve);
|
197
|
+
parser.hooks.rename.for("define").tap(PLUGIN_NAME, expr => {
|
185
198
|
const dep = new ConstDependency(
|
186
199
|
RuntimeGlobals.amdDefine,
|
187
200
|
expr.range,
|
@@ -194,20 +207,20 @@ class AMDPlugin {
|
|
194
207
|
parser.hooks.typeof
|
195
208
|
.for("require")
|
196
209
|
.tap(
|
197
|
-
|
210
|
+
PLUGIN_NAME,
|
198
211
|
toConstantDependency(parser, JSON.stringify("function"))
|
199
212
|
);
|
200
213
|
parser.hooks.evaluateTypeof
|
201
214
|
.for("require")
|
202
|
-
.tap(
|
215
|
+
.tap(PLUGIN_NAME, evaluateToString("function"));
|
203
216
|
};
|
204
217
|
|
205
218
|
normalModuleFactory.hooks.parser
|
206
|
-
.for(
|
207
|
-
.tap(
|
219
|
+
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
220
|
+
.tap(PLUGIN_NAME, handler);
|
208
221
|
normalModuleFactory.hooks.parser
|
209
|
-
.for(
|
210
|
-
.tap(
|
222
|
+
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
223
|
+
.tap(PLUGIN_NAME, handler);
|
211
224
|
}
|
212
225
|
);
|
213
226
|
}
|
@@ -12,8 +12,15 @@ const NullDependency = require("./NullDependency");
|
|
12
12
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
13
13
|
/** @typedef {import("../Dependency")} Dependency */
|
14
14
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
15
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
16
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
17
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
15
18
|
|
16
19
|
class AMDRequireArrayDependency extends NullDependency {
|
20
|
+
/**
|
21
|
+
* @param {TODO} depsArray deps array
|
22
|
+
* @param {Range} range range
|
23
|
+
*/
|
17
24
|
constructor(depsArray, range) {
|
18
25
|
super();
|
19
26
|
|
@@ -29,6 +36,9 @@ class AMDRequireArrayDependency extends NullDependency {
|
|
29
36
|
return "amd";
|
30
37
|
}
|
31
38
|
|
39
|
+
/**
|
40
|
+
* @param {ObjectSerializerContext} context context
|
41
|
+
*/
|
32
42
|
serialize(context) {
|
33
43
|
const { write } = context;
|
34
44
|
|
@@ -38,6 +48,9 @@ class AMDRequireArrayDependency extends NullDependency {
|
|
38
48
|
super.serialize(context);
|
39
49
|
}
|
40
50
|
|
51
|
+
/**
|
52
|
+
* @param {ObjectDeserializerContext} context context
|
53
|
+
*/
|
41
54
|
deserialize(context) {
|
42
55
|
const { read } = context;
|
43
56
|
|
@@ -8,7 +8,16 @@
|
|
8
8
|
const makeSerializable = require("../util/makeSerializable");
|
9
9
|
const ContextDependency = require("./ContextDependency");
|
10
10
|
|
11
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
12
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
13
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
14
|
+
|
11
15
|
class AMDRequireContextDependency extends ContextDependency {
|
16
|
+
/**
|
17
|
+
* @param {TODO} options options
|
18
|
+
* @param {Range} range range
|
19
|
+
* @param {Range} valueRange value range
|
20
|
+
*/
|
12
21
|
constructor(options, range, valueRange) {
|
13
22
|
super(options);
|
14
23
|
|
@@ -24,6 +33,9 @@ class AMDRequireContextDependency extends ContextDependency {
|
|
24
33
|
return "amd";
|
25
34
|
}
|
26
35
|
|
36
|
+
/**
|
37
|
+
* @param {ObjectSerializerContext} context context
|
38
|
+
*/
|
27
39
|
serialize(context) {
|
28
40
|
const { write } = context;
|
29
41
|
|
@@ -33,6 +45,9 @@ class AMDRequireContextDependency extends ContextDependency {
|
|
33
45
|
super.serialize(context);
|
34
46
|
}
|
35
47
|
|
48
|
+
/**
|
49
|
+
* @param {ObjectDeserializerContext} context context
|
50
|
+
*/
|
36
51
|
deserialize(context) {
|
37
52
|
const { read } = context;
|
38
53
|
|
@@ -8,7 +8,13 @@
|
|
8
8
|
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
|
11
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
12
|
+
|
11
13
|
class AMDRequireDependenciesBlock extends AsyncDependenciesBlock {
|
14
|
+
/**
|
15
|
+
* @param {DependencyLocation} loc location info
|
16
|
+
* @param {string=} request request
|
17
|
+
*/
|
12
18
|
constructor(loc, request) {
|
13
19
|
super(null, loc, request);
|
14
20
|
}
|
@@ -19,6 +19,8 @@ const { getLocalModule } = require("./LocalModulesHelpers");
|
|
19
19
|
const UnsupportedDependency = require("./UnsupportedDependency");
|
20
20
|
const getFunctionExpression = require("./getFunctionExpression");
|
21
21
|
|
22
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
23
|
+
|
22
24
|
class AMDRequireDependenciesBlockParserPlugin {
|
23
25
|
constructor(options) {
|
24
26
|
this.options = options;
|
@@ -50,6 +52,10 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
50
52
|
return bindThis;
|
51
53
|
}
|
52
54
|
|
55
|
+
/**
|
56
|
+
* @param {JavascriptParser} parser the parser
|
57
|
+
* @returns {void}
|
58
|
+
*/
|
53
59
|
apply(parser) {
|
54
60
|
parser.hooks.call
|
55
61
|
.for("require")
|
@@ -73,7 +79,7 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
73
79
|
for (const request of param.array) {
|
74
80
|
let dep, localModule;
|
75
81
|
if (request === "require") {
|
76
|
-
dep =
|
82
|
+
dep = RuntimeGlobals.require;
|
77
83
|
} else if (["exports", "module"].includes(request)) {
|
78
84
|
dep = request;
|
79
85
|
} else if ((localModule = getLocalModule(parser.state, request))) {
|
@@ -108,7 +114,7 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
108
114
|
} else if (param.isString()) {
|
109
115
|
let dep, localModule;
|
110
116
|
if (param.string === "require") {
|
111
|
-
dep = new ConstDependency(
|
117
|
+
dep = new ConstDependency(RuntimeGlobals.require, param.string, [
|
112
118
|
RuntimeGlobals.require
|
113
119
|
]);
|
114
120
|
} else if (param.string === "module") {
|
@@ -13,8 +13,17 @@ const NullDependency = require("./NullDependency");
|
|
13
13
|
/** @typedef {import("../AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
14
14
|
/** @typedef {import("../Dependency")} Dependency */
|
15
15
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
16
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
17
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
18
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
16
19
|
|
17
20
|
class AMDRequireDependency extends NullDependency {
|
21
|
+
/**
|
22
|
+
* @param {Range} outerRange outer range
|
23
|
+
* @param {Range} arrayRange array range
|
24
|
+
* @param {Range} functionRange function range
|
25
|
+
* @param {Range} errorCallbackRange error callback range
|
26
|
+
*/
|
18
27
|
constructor(outerRange, arrayRange, functionRange, errorCallbackRange) {
|
19
28
|
super();
|
20
29
|
|
@@ -30,6 +39,9 @@ class AMDRequireDependency extends NullDependency {
|
|
30
39
|
return "amd";
|
31
40
|
}
|
32
41
|
|
42
|
+
/**
|
43
|
+
* @param {ObjectSerializerContext} context context
|
44
|
+
*/
|
33
45
|
serialize(context) {
|
34
46
|
const { write } = context;
|
35
47
|
|
@@ -43,6 +55,9 @@ class AMDRequireDependency extends NullDependency {
|
|
43
55
|
super.serialize(context);
|
44
56
|
}
|
45
57
|
|
58
|
+
/**
|
59
|
+
* @param {ObjectDeserializerContext} context context
|
60
|
+
*/
|
46
61
|
deserialize(context) {
|
47
62
|
const { read } = context;
|
48
63
|
|
@@ -103,7 +118,7 @@ AMDRequireDependency.Template = class AMDRequireDependencyTemplate extends (
|
|
103
118
|
// has function range but no array range
|
104
119
|
if (dep.functionRange && !dep.arrayRange) {
|
105
120
|
const startBlock = `${promise}.then((`;
|
106
|
-
const endBlock = `).bind(exports,
|
121
|
+
const endBlock = `).bind(exports, ${RuntimeGlobals.require}, exports, module))['catch'](${RuntimeGlobals.uncaughtErrorHandler})`;
|
107
122
|
runtimeRequirements.add(RuntimeGlobals.uncaughtErrorHandler);
|
108
123
|
|
109
124
|
source.replace(dep.outerRange[0], dep.functionRange[0] - 1, startBlock);
|
@@ -9,7 +9,13 @@ const makeSerializable = require("../util/makeSerializable");
|
|
9
9
|
const ModuleDependency = require("./ModuleDependency");
|
10
10
|
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
|
11
11
|
|
12
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
13
|
+
|
12
14
|
class AMDRequireItemDependency extends ModuleDependency {
|
15
|
+
/**
|
16
|
+
* @param {string} request the request string
|
17
|
+
* @param {Range} range location in source code
|
18
|
+
*/
|
13
19
|
constructor(request, range) {
|
14
20
|
super(request);
|
15
21
|
|
@@ -14,7 +14,7 @@ class AMDDefineRuntimeModule extends RuntimeModule {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
/**
|
17
|
-
* @returns {string} runtime code
|
17
|
+
* @returns {string | null} runtime code
|
18
18
|
*/
|
19
19
|
generate() {
|
20
20
|
return Template.asString([
|
@@ -35,7 +35,7 @@ class AMDOptionsRuntimeModule extends RuntimeModule {
|
|
35
35
|
}
|
36
36
|
|
37
37
|
/**
|
38
|
-
* @returns {string} runtime code
|
38
|
+
* @returns {string | null} runtime code
|
39
39
|
*/
|
40
40
|
generate() {
|
41
41
|
return Template.asString([
|