webpack 5.76.1 → 5.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +4 -0
- 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 +12 -8
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +79 -44
- 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/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 +20 -3
- package/lib/ExportsInfoApiPlugin.js +30 -14
- package/lib/ExternalModule.js +30 -9
- package/lib/FileSystemInfo.js +9 -1
- 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/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/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/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
- package/lib/cache/PackFileCacheStrategy.js +42 -15
- 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 +15 -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 +194 -194
- 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 +6 -4
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +8 -4
- package/lib/library/SystemLibraryPlugin.js +1 -0
- package/lib/library/UmdLibraryPlugin.js +4 -0
- 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 +6 -0
- package/lib/util/StringXor.js +51 -0
- 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 +14 -1
- package/lib/util/semver.js +1 -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 +132 -5
- 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 +1608 -667
@@ -7,16 +7,20 @@
|
|
7
7
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
|
10
|
+
/** @typedef {import("../Chunk")} Chunk */
|
11
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
12
|
+
|
10
13
|
class RuntimeIdRuntimeModule extends RuntimeModule {
|
11
14
|
constructor() {
|
12
15
|
super("runtimeId");
|
13
16
|
}
|
14
17
|
|
15
18
|
/**
|
16
|
-
* @returns {string} runtime code
|
19
|
+
* @returns {string | null} runtime code
|
17
20
|
*/
|
18
21
|
generate() {
|
19
|
-
const
|
22
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
23
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
20
24
|
const runtime = chunk.runtime;
|
21
25
|
if (typeof runtime !== "string")
|
22
26
|
throw new Error("RuntimeIdRuntimeModule must be in a single runtime");
|
@@ -8,9 +8,20 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const StartupChunkDependenciesRuntimeModule = require("./StartupChunkDependenciesRuntimeModule");
|
9
9
|
const StartupEntrypointRuntimeModule = require("./StartupEntrypointRuntimeModule");
|
10
10
|
|
11
|
+
/** @typedef {import("../../declarations/WebpackOptions").ChunkLoadingType} ChunkLoadingType */
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
11
13
|
/** @typedef {import("../Compiler")} Compiler */
|
12
14
|
|
15
|
+
/**
|
16
|
+
* @typedef {Object} Options
|
17
|
+
* @property {ChunkLoadingType} chunkLoading
|
18
|
+
* @property {boolean=} asyncChunkLoading
|
19
|
+
*/
|
20
|
+
|
13
21
|
class StartupChunkDependenciesPlugin {
|
22
|
+
/**
|
23
|
+
* @param {Options} options options
|
24
|
+
*/
|
14
25
|
constructor(options) {
|
15
26
|
this.chunkLoading = options.chunkLoading;
|
16
27
|
this.asyncChunkLoading =
|
@@ -29,6 +40,10 @@ class StartupChunkDependenciesPlugin {
|
|
29
40
|
"StartupChunkDependenciesPlugin",
|
30
41
|
compilation => {
|
31
42
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
43
|
+
/**
|
44
|
+
* @param {Chunk} chunk chunk to check
|
45
|
+
* @returns {boolean} true, when the plugin is enabled for the chunk
|
46
|
+
*/
|
32
47
|
const isEnabledForChunk = chunk => {
|
33
48
|
const options = chunk.getEntryOptions();
|
34
49
|
const chunkLoading =
|
@@ -9,23 +9,32 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
10
10
|
const Template = require("../Template");
|
11
11
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
14
|
+
/** @typedef {import("../Compilation")} Compilation */
|
15
|
+
|
12
16
|
class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
|
17
|
+
/**
|
18
|
+
* @param {boolean} asyncChunkLoading use async chunk loading
|
19
|
+
*/
|
13
20
|
constructor(asyncChunkLoading) {
|
14
21
|
super("startup chunk dependencies", RuntimeModule.STAGE_TRIGGER);
|
15
22
|
this.asyncChunkLoading = asyncChunkLoading;
|
16
23
|
}
|
17
24
|
|
18
25
|
/**
|
19
|
-
* @returns {string} runtime code
|
26
|
+
* @returns {string | null} runtime code
|
20
27
|
*/
|
21
28
|
generate() {
|
22
|
-
const
|
23
|
-
const
|
29
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
30
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
24
31
|
const chunkIds = Array.from(
|
25
32
|
chunkGraph.getChunkEntryDependentChunksIterable(chunk)
|
26
33
|
).map(chunk => {
|
27
34
|
return chunk.id;
|
28
35
|
});
|
36
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
37
|
+
const { runtimeTemplate } = compilation;
|
29
38
|
return Template.asString([
|
30
39
|
`var next = ${RuntimeGlobals.startup};`,
|
31
40
|
`${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction(
|
@@ -45,7 +54,7 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
|
|
45
54
|
// using map is shorter for 3 or more chunks
|
46
55
|
`return Promise.all(${JSON.stringify(chunkIds)}.map(${
|
47
56
|
RuntimeGlobals.ensureChunk
|
48
|
-
},
|
57
|
+
}, ${RuntimeGlobals.require})).then(next);`
|
49
58
|
]
|
50
59
|
: [
|
51
60
|
// calling ensureChunk directly is shorter for 0 - 2 chunks
|
@@ -7,19 +7,23 @@
|
|
7
7
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
|
10
|
+
/** @typedef {import("../Compilation")} Compilation */
|
10
11
|
/** @typedef {import("../MainTemplate")} MainTemplate */
|
11
12
|
|
12
13
|
class StartupEntrypointRuntimeModule extends RuntimeModule {
|
14
|
+
/**
|
15
|
+
* @param {boolean} asyncChunkLoading use async chunk loading
|
16
|
+
*/
|
13
17
|
constructor(asyncChunkLoading) {
|
14
18
|
super("startup entrypoint");
|
15
19
|
this.asyncChunkLoading = asyncChunkLoading;
|
16
20
|
}
|
17
21
|
|
18
22
|
/**
|
19
|
-
* @returns {string} runtime code
|
23
|
+
* @returns {string | null} runtime code
|
20
24
|
*/
|
21
25
|
generate() {
|
22
|
-
const
|
26
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
23
27
|
const { runtimeTemplate } = compilation;
|
24
28
|
return `${
|
25
29
|
RuntimeGlobals.startupEntrypoint
|
@@ -27,19 +31,19 @@ class StartupEntrypointRuntimeModule extends RuntimeModule {
|
|
27
31
|
"// arguments: chunkIds, moduleId are deprecated",
|
28
32
|
"var moduleId = chunkIds;",
|
29
33
|
`if(!fn) chunkIds = result, fn = ${runtimeTemplate.returningFunction(
|
30
|
-
|
34
|
+
`${RuntimeGlobals.require}(${RuntimeGlobals.entryModuleId} = moduleId)`
|
31
35
|
)};`,
|
32
36
|
...(this.asyncChunkLoading
|
33
37
|
? [
|
34
|
-
`return Promise.all(chunkIds.map(${
|
35
|
-
RuntimeGlobals.
|
36
|
-
}
|
38
|
+
`return Promise.all(chunkIds.map(${RuntimeGlobals.ensureChunk}, ${
|
39
|
+
RuntimeGlobals.require
|
40
|
+
})).then(${runtimeTemplate.basicFunction("", [
|
37
41
|
"var r = fn();",
|
38
42
|
"return r === undefined ? result : r;"
|
39
43
|
])})`
|
40
44
|
]
|
41
45
|
: [
|
42
|
-
`chunkIds.map(${RuntimeGlobals.ensureChunk},
|
46
|
+
`chunkIds.map(${RuntimeGlobals.ensureChunk}, ${RuntimeGlobals.require})`,
|
43
47
|
"var r = fn();",
|
44
48
|
"return r === undefined ? result : r;"
|
45
49
|
])
|
@@ -13,15 +13,28 @@ const NormalModule = require("../NormalModule");
|
|
13
13
|
// http://www.ietf.org/rfc/rfc2397.txt
|
14
14
|
const URIRegEx = /^data:([^;,]+)?((?:;[^;,]+)*?)(?:;(base64))?,(.*)$/i;
|
15
15
|
|
16
|
+
/**
|
17
|
+
* @param {string} uri data URI
|
18
|
+
* @returns {Buffer|null} decoded data
|
19
|
+
*/
|
16
20
|
const decodeDataURI = uri => {
|
17
21
|
const match = URIRegEx.exec(uri);
|
18
22
|
if (!match) return null;
|
19
23
|
|
20
24
|
const isBase64 = match[3];
|
21
25
|
const body = match[4];
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
|
27
|
+
if (isBase64) {
|
28
|
+
return Buffer.from(body, "base64");
|
29
|
+
}
|
30
|
+
|
31
|
+
// CSS allows to use `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" style="stroke: rgb(223,224,225); stroke-width: 2px; fill: none; stroke-dasharray: 6px 3px" /></svg>`
|
32
|
+
// so we return original body if we can't `decodeURIComponent`
|
33
|
+
try {
|
34
|
+
return Buffer.from(decodeURIComponent(body), "ascii");
|
35
|
+
} catch (_) {
|
36
|
+
return Buffer.from(body, "ascii");
|
37
|
+
}
|
25
38
|
};
|
26
39
|
|
27
40
|
class DataUriPlugin {
|
@@ -71,11 +71,19 @@ const validate = createSchemaValidation(
|
|
71
71
|
}
|
72
72
|
);
|
73
73
|
|
74
|
+
/**
|
75
|
+
* @param {string} str path
|
76
|
+
* @returns {string} safe path
|
77
|
+
*/
|
74
78
|
const toSafePath = str =>
|
75
79
|
str
|
76
80
|
.replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, "")
|
77
81
|
.replace(/[^a-zA-Z0-9._-]+/g, "_");
|
78
82
|
|
83
|
+
/**
|
84
|
+
* @param {Buffer} content content
|
85
|
+
* @returns {string} integrity
|
86
|
+
*/
|
79
87
|
const computeIntegrity = content => {
|
80
88
|
const hash = createHash("sha512");
|
81
89
|
hash.update(content);
|
@@ -83,6 +91,11 @@ const computeIntegrity = content => {
|
|
83
91
|
return integrity;
|
84
92
|
};
|
85
93
|
|
94
|
+
/**
|
95
|
+
* @param {Buffer} content content
|
96
|
+
* @param {string} integrity integrity
|
97
|
+
* @returns {boolean} true, if integrity matches
|
98
|
+
*/
|
86
99
|
const verifyIntegrity = (content, integrity) => {
|
87
100
|
if (integrity === "ignore") return true;
|
88
101
|
return computeIntegrity(content) === integrity;
|
@@ -110,6 +123,11 @@ const parseKeyValuePairs = str => {
|
|
110
123
|
return result;
|
111
124
|
};
|
112
125
|
|
126
|
+
/**
|
127
|
+
* @param {string | undefined} cacheControl Cache-Control header
|
128
|
+
* @param {number} requestTime timestamp of request
|
129
|
+
* @returns {{storeCache: boolean, storeLock: boolean, validUntil: number}} Logic for storing in cache and lockfile cache
|
130
|
+
*/
|
113
131
|
const parseCacheControl = (cacheControl, requestTime) => {
|
114
132
|
// When false resource is not stored in cache
|
115
133
|
let storeCache = true;
|
@@ -147,6 +165,10 @@ const areLockfileEntriesEqual = (a, b) => {
|
|
147
165
|
);
|
148
166
|
};
|
149
167
|
|
168
|
+
/**
|
169
|
+
* @param {LockfileEntry} entry lockfile entry
|
170
|
+
* @returns {`resolved: ${string}, integrity: ${string}, contentType: ${*}`} stringified entry
|
171
|
+
*/
|
150
172
|
const entryToString = entry => {
|
151
173
|
return `resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
|
152
174
|
};
|
@@ -158,6 +180,10 @@ class Lockfile {
|
|
158
180
|
this.entries = new Map();
|
159
181
|
}
|
160
182
|
|
183
|
+
/**
|
184
|
+
* @param {string} content content of the lockfile
|
185
|
+
* @returns {Lockfile} lockfile
|
186
|
+
*/
|
161
187
|
static parse(content) {
|
162
188
|
// TODO handle merge conflicts
|
163
189
|
const data = JSON.parse(content);
|
@@ -180,6 +206,9 @@ class Lockfile {
|
|
180
206
|
return lockfile;
|
181
207
|
}
|
182
208
|
|
209
|
+
/**
|
210
|
+
* @returns {string} stringified lockfile
|
211
|
+
*/
|
183
212
|
toString() {
|
184
213
|
let str = "{\n";
|
185
214
|
const entries = Array.from(this.entries).sort(([a], [b]) =>
|
@@ -342,6 +371,7 @@ class HttpUriPlugin {
|
|
342
371
|
const fs = compilation.inputFileSystem;
|
343
372
|
const cache = compilation.getCache("webpack.HttpUriPlugin");
|
344
373
|
const logger = compilation.getLogger("webpack.HttpUriPlugin");
|
374
|
+
/** @type {string} */
|
345
375
|
const lockfileLocation =
|
346
376
|
this._lockfileLocation ||
|
347
377
|
join(
|
@@ -351,6 +381,7 @@ class HttpUriPlugin {
|
|
351
381
|
? `${toSafePath(compiler.name)}.webpack.lock`
|
352
382
|
: "webpack.lock"
|
353
383
|
);
|
384
|
+
/** @type {string | false} */
|
354
385
|
const cacheLocation =
|
355
386
|
this._cacheLocation !== undefined
|
356
387
|
? this._cacheLocation
|
@@ -364,6 +395,7 @@ class HttpUriPlugin {
|
|
364
395
|
|
365
396
|
let warnedAboutEol = false;
|
366
397
|
|
398
|
+
/** @type {Map<string, string>} */
|
367
399
|
const cacheKeyCache = new Map();
|
368
400
|
/**
|
369
401
|
* @param {string} url the url
|
@@ -447,6 +479,12 @@ class HttpUriPlugin {
|
|
447
479
|
|
448
480
|
/** @type {Map<string, LockfileEntry | "ignore" | "no-cache"> | undefined} */
|
449
481
|
let lockfileUpdates = undefined;
|
482
|
+
|
483
|
+
/**
|
484
|
+
* @param {Lockfile} lockfile lockfile instance
|
485
|
+
* @param {string} url url to store
|
486
|
+
* @param {LockfileEntry | "ignore" | "no-cache"} entry lockfile entry
|
487
|
+
*/
|
450
488
|
const storeLockEntry = (lockfile, url, entry) => {
|
451
489
|
const oldEntry = lockfile.entries.get(url);
|
452
490
|
if (lockfileUpdates === undefined) lockfileUpdates = new Map();
|
@@ -4,16 +4,32 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class ArraySerializer {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
/**
|
12
|
+
* @template T
|
13
|
+
* @param {T[]} array array
|
14
|
+
* @param {ObjectSerializerContext} context context
|
15
|
+
*/
|
16
|
+
serialize(array, context) {
|
17
|
+
context.write(array.length);
|
18
|
+
for (const item of array) context.write(item);
|
11
19
|
}
|
12
|
-
|
13
|
-
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @template T
|
23
|
+
* @param {ObjectDeserializerContext} context context
|
24
|
+
* @returns {T[]} array
|
25
|
+
*/
|
26
|
+
deserialize(context) {
|
27
|
+
/** @type {number} */
|
28
|
+
const length = context.read();
|
29
|
+
/** @type {T[]} */
|
14
30
|
const array = [];
|
15
31
|
for (let i = 0; i < length; i++) {
|
16
|
-
array.push(read());
|
32
|
+
array.push(context.read());
|
17
33
|
}
|
18
34
|
return array;
|
19
35
|
}
|
@@ -21,6 +21,9 @@ Section -> NullsSection |
|
|
21
21
|
I32NumbersSection |
|
22
22
|
I8NumbersSection |
|
23
23
|
ShortStringSection |
|
24
|
+
BigIntSection |
|
25
|
+
I32BigIntSection |
|
26
|
+
I8BigIntSection
|
24
27
|
StringSection |
|
25
28
|
BufferSection |
|
26
29
|
NopSection
|
@@ -39,6 +42,9 @@ ShortStringSection -> ShortStringSectionHeaderByte ascii-byte*
|
|
39
42
|
StringSection -> StringSectionHeaderByte i32:length utf8-byte*
|
40
43
|
BufferSection -> BufferSectionHeaderByte i32:length byte*
|
41
44
|
NopSection --> NopSectionHeaderByte
|
45
|
+
BigIntSection -> BigIntSectionHeaderByte i32:length ascii-byte*
|
46
|
+
I32BigIntSection -> I32BigIntSectionHeaderByte i32
|
47
|
+
I8BigIntSection -> I8BigIntSectionHeaderByte i8
|
42
48
|
|
43
49
|
ShortStringSectionHeaderByte -> 0b1nnn_nnnn (n:length)
|
44
50
|
|
@@ -58,6 +64,9 @@ BooleansCountAndBitsByte ->
|
|
58
64
|
StringSectionHeaderByte -> 0b0000_1110
|
59
65
|
BufferSectionHeaderByte -> 0b0000_1111
|
60
66
|
NopSectionHeaderByte -> 0b0000_1011
|
67
|
+
BigIntSectionHeaderByte -> 0b0001_1010
|
68
|
+
I32BigIntSectionHeaderByte -> 0b0001_1100
|
69
|
+
I8BigIntSectionHeaderByte -> 0b0001_1011
|
61
70
|
FalseHeaderByte -> 0b0000_1100
|
62
71
|
TrueHeaderByte -> 0b0000_1101
|
63
72
|
|
@@ -78,6 +87,9 @@ const NULL_AND_I8_HEADER = 0x15;
|
|
78
87
|
const NULL_AND_I32_HEADER = 0x16;
|
79
88
|
const NULL_AND_TRUE_HEADER = 0x17;
|
80
89
|
const NULL_AND_FALSE_HEADER = 0x18;
|
90
|
+
const BIGINT_HEADER = 0x1a;
|
91
|
+
const BIGINT_I8_HEADER = 0x1b;
|
92
|
+
const BIGINT_I32_HEADER = 0x1c;
|
81
93
|
const STRING_HEADER = 0x1e;
|
82
94
|
const BUFFER_HEADER = 0x1f;
|
83
95
|
const I8_HEADER = 0x60;
|
@@ -86,7 +98,7 @@ const F64_HEADER = 0x20;
|
|
86
98
|
const SHORT_STRING_HEADER = 0x80;
|
87
99
|
|
88
100
|
/** Uplift high-order bits */
|
89
|
-
const NUMBERS_HEADER_MASK = 0xe0;
|
101
|
+
const NUMBERS_HEADER_MASK = 0xe0; // 0b1010_0000
|
90
102
|
const NUMBERS_COUNT_MASK = 0x1f; // 0b0001_1111
|
91
103
|
const SHORT_STRING_LENGTH_MASK = 0x7f; // 0b0111_1111
|
92
104
|
|
@@ -101,6 +113,10 @@ const MEASURE_END_OPERATION = Symbol("MEASURE_END_OPERATION");
|
|
101
113
|
/** @typedef {typeof MEASURE_START_OPERATION} MEASURE_START_OPERATION_TYPE */
|
102
114
|
/** @typedef {typeof MEASURE_END_OPERATION} MEASURE_END_OPERATION_TYPE */
|
103
115
|
|
116
|
+
/**
|
117
|
+
* @param {number} n number
|
118
|
+
* @returns {0 | 1 | 2} type of number for serialization
|
119
|
+
*/
|
104
120
|
const identifyNumber = n => {
|
105
121
|
if (n === (n | 0)) {
|
106
122
|
if (n <= 127 && n >= -128) return 0;
|
@@ -109,6 +125,16 @@ const identifyNumber = n => {
|
|
109
125
|
return 2;
|
110
126
|
};
|
111
127
|
|
128
|
+
/**
|
129
|
+
* @param {bigint} n bigint
|
130
|
+
* @returns {0 | 1 | 2} type of bigint for serialization
|
131
|
+
*/
|
132
|
+
const identifyBigInt = n => {
|
133
|
+
if (n <= BigInt(127) && n >= BigInt(-128)) return 0;
|
134
|
+
if (n <= BigInt(2147483647) && n >= BigInt(-2147483648)) return 1;
|
135
|
+
return 2;
|
136
|
+
};
|
137
|
+
|
112
138
|
/**
|
113
139
|
* @typedef {PrimitiveSerializableType[]} DeserializedType
|
114
140
|
* @typedef {BufferSerializableType[]} SerializedType
|
@@ -203,17 +229,27 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
203
229
|
currentPosition = 0;
|
204
230
|
}
|
205
231
|
};
|
232
|
+
/**
|
233
|
+
* @param {number} byte byte
|
234
|
+
*/
|
206
235
|
const writeU8 = byte => {
|
207
236
|
currentBuffer.writeUInt8(byte, currentPosition++);
|
208
237
|
};
|
238
|
+
/**
|
239
|
+
* @param {number} ui32 ui32
|
240
|
+
*/
|
209
241
|
const writeU32 = ui32 => {
|
210
242
|
currentBuffer.writeUInt32LE(ui32, currentPosition);
|
211
243
|
currentPosition += 4;
|
212
244
|
};
|
245
|
+
/** @type {number[]} */
|
213
246
|
const measureStack = [];
|
214
247
|
const measureStart = () => {
|
215
248
|
measureStack.push(buffers.length, currentPosition);
|
216
249
|
};
|
250
|
+
/**
|
251
|
+
* @returns {number} size
|
252
|
+
*/
|
217
253
|
const measureEnd = () => {
|
218
254
|
const oldPos = measureStack.pop();
|
219
255
|
const buffersIndex = measureStack.pop();
|
@@ -258,6 +294,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
258
294
|
break;
|
259
295
|
}
|
260
296
|
}
|
297
|
+
/** @type {number[]} */
|
261
298
|
const lengths = [];
|
262
299
|
for (const item of serializedData) {
|
263
300
|
let last;
|
@@ -316,6 +353,62 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
316
353
|
}
|
317
354
|
break;
|
318
355
|
}
|
356
|
+
case "bigint": {
|
357
|
+
const type = identifyBigInt(thing);
|
358
|
+
if (type === 0 && thing >= 0 && thing <= BigInt(10)) {
|
359
|
+
// shortcut for very small bigints
|
360
|
+
allocate(HEADER_SIZE + I8_SIZE);
|
361
|
+
writeU8(BIGINT_I8_HEADER);
|
362
|
+
writeU8(Number(thing));
|
363
|
+
break;
|
364
|
+
}
|
365
|
+
|
366
|
+
switch (type) {
|
367
|
+
case 0: {
|
368
|
+
let n = 1;
|
369
|
+
allocate(HEADER_SIZE + I8_SIZE * n);
|
370
|
+
writeU8(BIGINT_I8_HEADER | (n - 1));
|
371
|
+
while (n > 0) {
|
372
|
+
currentBuffer.writeInt8(
|
373
|
+
Number(/** @type {bigint} */ (data[i])),
|
374
|
+
currentPosition
|
375
|
+
);
|
376
|
+
currentPosition += I8_SIZE;
|
377
|
+
n--;
|
378
|
+
i++;
|
379
|
+
}
|
380
|
+
i--;
|
381
|
+
break;
|
382
|
+
}
|
383
|
+
case 1: {
|
384
|
+
let n = 1;
|
385
|
+
allocate(HEADER_SIZE + I32_SIZE * n);
|
386
|
+
writeU8(BIGINT_I32_HEADER | (n - 1));
|
387
|
+
while (n > 0) {
|
388
|
+
currentBuffer.writeInt32LE(
|
389
|
+
Number(/** @type {bigint} */ (data[i])),
|
390
|
+
currentPosition
|
391
|
+
);
|
392
|
+
currentPosition += I32_SIZE;
|
393
|
+
n--;
|
394
|
+
i++;
|
395
|
+
}
|
396
|
+
i--;
|
397
|
+
break;
|
398
|
+
}
|
399
|
+
default: {
|
400
|
+
const value = thing.toString();
|
401
|
+
const len = Buffer.byteLength(value);
|
402
|
+
allocate(len + HEADER_SIZE + I32_SIZE);
|
403
|
+
writeU8(BIGINT_HEADER);
|
404
|
+
writeU32(len);
|
405
|
+
currentBuffer.write(value, currentPosition);
|
406
|
+
currentPosition += len;
|
407
|
+
break;
|
408
|
+
}
|
409
|
+
}
|
410
|
+
break;
|
411
|
+
}
|
319
412
|
case "number": {
|
320
413
|
const type = identifyNumber(thing);
|
321
414
|
if (type === 0 && thing >= 0 && thing <= 10) {
|
@@ -640,6 +733,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
640
733
|
checkOverflow();
|
641
734
|
return res;
|
642
735
|
};
|
736
|
+
/**
|
737
|
+
* @returns {number} U8
|
738
|
+
*/
|
643
739
|
const readU8 = () => {
|
644
740
|
ensureBuffer();
|
645
741
|
/**
|
@@ -653,6 +749,9 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
653
749
|
checkOverflow();
|
654
750
|
return byte;
|
655
751
|
};
|
752
|
+
/**
|
753
|
+
* @returns {number} U32
|
754
|
+
*/
|
656
755
|
const readU32 = () => {
|
657
756
|
return read(I32_SIZE).readUInt32LE(0);
|
658
757
|
};
|
@@ -826,6 +925,70 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
826
925
|
result.push(read(1).readInt8(0));
|
827
926
|
}
|
828
927
|
};
|
928
|
+
case BIGINT_I8_HEADER: {
|
929
|
+
const len = 1;
|
930
|
+
return () => {
|
931
|
+
const need = I8_SIZE * len;
|
932
|
+
|
933
|
+
if (isInCurrentBuffer(need)) {
|
934
|
+
for (let i = 0; i < len; i++) {
|
935
|
+
const value =
|
936
|
+
/** @type {Buffer} */
|
937
|
+
(currentBuffer).readInt8(currentPosition);
|
938
|
+
result.push(BigInt(value));
|
939
|
+
currentPosition += I8_SIZE;
|
940
|
+
}
|
941
|
+
checkOverflow();
|
942
|
+
} else {
|
943
|
+
const buf = read(need);
|
944
|
+
for (let i = 0; i < len; i++) {
|
945
|
+
const value = buf.readInt8(i * I8_SIZE);
|
946
|
+
result.push(BigInt(value));
|
947
|
+
}
|
948
|
+
}
|
949
|
+
};
|
950
|
+
}
|
951
|
+
case BIGINT_I32_HEADER: {
|
952
|
+
const len = 1;
|
953
|
+
return () => {
|
954
|
+
const need = I32_SIZE * len;
|
955
|
+
if (isInCurrentBuffer(need)) {
|
956
|
+
for (let i = 0; i < len; i++) {
|
957
|
+
const value = /** @type {Buffer} */ (currentBuffer).readInt32LE(
|
958
|
+
currentPosition
|
959
|
+
);
|
960
|
+
result.push(BigInt(value));
|
961
|
+
currentPosition += I32_SIZE;
|
962
|
+
}
|
963
|
+
checkOverflow();
|
964
|
+
} else {
|
965
|
+
const buf = read(need);
|
966
|
+
for (let i = 0; i < len; i++) {
|
967
|
+
const value = buf.readInt32LE(i * I32_SIZE);
|
968
|
+
result.push(BigInt(value));
|
969
|
+
}
|
970
|
+
}
|
971
|
+
};
|
972
|
+
}
|
973
|
+
case BIGINT_HEADER: {
|
974
|
+
return () => {
|
975
|
+
const len = readU32();
|
976
|
+
if (isInCurrentBuffer(len) && currentPosition + len < 0x7fffffff) {
|
977
|
+
const value = currentBuffer.toString(
|
978
|
+
undefined,
|
979
|
+
currentPosition,
|
980
|
+
currentPosition + len
|
981
|
+
);
|
982
|
+
|
983
|
+
result.push(BigInt(value));
|
984
|
+
currentPosition += len;
|
985
|
+
checkOverflow();
|
986
|
+
} else {
|
987
|
+
const value = read(len).toString();
|
988
|
+
result.push(BigInt(value));
|
989
|
+
}
|
990
|
+
};
|
991
|
+
}
|
829
992
|
default:
|
830
993
|
if (header <= 10) {
|
831
994
|
return () => result.push(header);
|
@@ -4,12 +4,23 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class DateObjectSerializer {
|
8
|
-
|
9
|
-
|
11
|
+
/**
|
12
|
+
* @param {Date} obj date
|
13
|
+
* @param {ObjectSerializerContext} context context
|
14
|
+
*/
|
15
|
+
serialize(obj, context) {
|
16
|
+
context.write(obj.getTime());
|
10
17
|
}
|
11
|
-
|
12
|
-
|
18
|
+
/**
|
19
|
+
* @param {ObjectDeserializerContext} context context
|
20
|
+
* @returns {Date} date
|
21
|
+
*/
|
22
|
+
deserialize(context) {
|
23
|
+
return new Date(context.read());
|
13
24
|
}
|
14
25
|
}
|
15
26
|
|
@@ -4,21 +4,36 @@
|
|
4
4
|
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
8
|
+
/** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
9
|
+
|
7
10
|
class ErrorObjectSerializer {
|
11
|
+
/**
|
12
|
+
* @param {ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor} Type error type
|
13
|
+
*/
|
8
14
|
constructor(Type) {
|
9
15
|
this.Type = Type;
|
10
16
|
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
/**
|
18
|
+
* @param {Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError} obj error
|
19
|
+
* @param {ObjectSerializerContext} context context
|
20
|
+
*/
|
21
|
+
serialize(obj, context) {
|
22
|
+
context.write(obj.message);
|
23
|
+
context.write(obj.stack);
|
24
|
+
context.write(/** @type {Error & { cause: "unknown" }} */ (obj).cause);
|
15
25
|
}
|
16
|
-
|
17
|
-
|
26
|
+
/**
|
27
|
+
* @param {ObjectDeserializerContext} context context
|
28
|
+
* @returns {Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError} error
|
29
|
+
*/
|
30
|
+
deserialize(context) {
|
18
31
|
const err = new this.Type();
|
19
32
|
|
20
|
-
err.message = read();
|
21
|
-
err.stack = read();
|
33
|
+
err.message = context.read();
|
34
|
+
err.stack = context.read();
|
35
|
+
/** @type {Error & { cause: "unknown" }} */
|
36
|
+
(err).cause = context.read();
|
22
37
|
|
23
38
|
return err;
|
24
39
|
}
|