@depup/webpack 5.105.4-depup.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +38 -0
- package/bin/webpack.js +196 -0
- package/hot/dev-server.js +90 -0
- package/hot/emitter-event-target.js +7 -0
- package/hot/emitter.js +2 -0
- package/hot/lazy-compilation-node.js +66 -0
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +93 -0
- package/hot/load-http.js +7 -0
- package/hot/log-apply-result.js +49 -0
- package/hot/log.js +78 -0
- package/hot/only-dev-server.js +118 -0
- package/hot/poll.js +41 -0
- package/hot/signal.js +66 -0
- package/lib/APIPlugin.js +392 -0
- package/lib/AbstractMethodError.js +56 -0
- package/lib/AsyncDependenciesBlock.js +128 -0
- package/lib/AsyncDependencyToInitialChunkError.js +34 -0
- package/lib/AutomaticPrefetchPlugin.js +66 -0
- package/lib/BannerPlugin.js +138 -0
- package/lib/Cache.js +168 -0
- package/lib/CacheFacade.js +349 -0
- package/lib/CaseSensitiveModulesWarning.js +72 -0
- package/lib/Chunk.js +899 -0
- package/lib/ChunkGraph.js +1968 -0
- package/lib/ChunkGroup.js +615 -0
- package/lib/ChunkRenderError.js +38 -0
- package/lib/ChunkTemplate.js +181 -0
- package/lib/CleanPlugin.js +495 -0
- package/lib/CodeGenerationError.js +35 -0
- package/lib/CodeGenerationResults.js +167 -0
- package/lib/CommentCompilationWarning.js +33 -0
- package/lib/CompatibilityPlugin.js +240 -0
- package/lib/Compilation.js +5876 -0
- package/lib/Compiler.js +1413 -0
- package/lib/ConcatenationScope.js +181 -0
- package/lib/ConcurrentCompilationError.js +18 -0
- package/lib/ConditionalInitFragment.js +120 -0
- package/lib/ConstPlugin.js +567 -0
- package/lib/ContextExclusionPlugin.js +33 -0
- package/lib/ContextModule.js +1411 -0
- package/lib/ContextModuleFactory.js +514 -0
- package/lib/ContextReplacementPlugin.js +227 -0
- package/lib/CssModule.js +179 -0
- package/lib/DefinePlugin.js +878 -0
- package/lib/DelegatedModule.js +279 -0
- package/lib/DelegatedModuleFactoryPlugin.js +116 -0
- package/lib/DelegatedPlugin.js +49 -0
- package/lib/DependenciesBlock.js +120 -0
- package/lib/Dependency.js +390 -0
- package/lib/DependencyTemplate.js +71 -0
- package/lib/DependencyTemplates.js +67 -0
- package/lib/DllEntryPlugin.js +76 -0
- package/lib/DllModule.js +175 -0
- package/lib/DllModuleFactory.js +38 -0
- package/lib/DllPlugin.js +73 -0
- package/lib/DllReferencePlugin.js +189 -0
- package/lib/DotenvPlugin.js +468 -0
- package/lib/DynamicEntryPlugin.js +93 -0
- package/lib/EntryOptionPlugin.js +98 -0
- package/lib/EntryPlugin.js +72 -0
- package/lib/Entrypoint.js +120 -0
- package/lib/EnvironmentNotSupportAsyncWarning.js +51 -0
- package/lib/EnvironmentPlugin.js +74 -0
- package/lib/ErrorHelpers.js +100 -0
- package/lib/EvalDevToolModulePlugin.js +135 -0
- package/lib/EvalSourceMapDevToolPlugin.js +252 -0
- package/lib/ExportsInfo.js +1663 -0
- package/lib/ExportsInfoApiPlugin.js +87 -0
- package/lib/ExternalModule.js +1169 -0
- package/lib/ExternalModuleFactoryPlugin.js +370 -0
- package/lib/ExternalsPlugin.js +93 -0
- package/lib/FalseIIFEUmdWarning.js +20 -0
- package/lib/FileSystemInfo.js +4131 -0
- package/lib/FlagAllModulesAsUsedPlugin.js +55 -0
- package/lib/FlagDependencyExportsPlugin.js +437 -0
- package/lib/FlagDependencyUsagePlugin.js +348 -0
- package/lib/FlagEntryExportAsUsedPlugin.js +56 -0
- package/lib/Generator.js +188 -0
- package/lib/GraphHelpers.js +46 -0
- package/lib/HarmonyLinkingError.js +17 -0
- package/lib/HookWebpackError.js +121 -0
- package/lib/HotModuleReplacementPlugin.js +930 -0
- package/lib/HotUpdateChunk.js +16 -0
- package/lib/IgnoreErrorModuleFactory.js +39 -0
- package/lib/IgnorePlugin.js +105 -0
- package/lib/IgnoreWarningsPlugin.js +41 -0
- package/lib/InitFragment.js +204 -0
- package/lib/InvalidDependenciesModuleWarning.js +44 -0
- package/lib/JavascriptMetaInfoPlugin.js +78 -0
- package/lib/LibManifestPlugin.js +144 -0
- package/lib/LibraryTemplatePlugin.js +48 -0
- package/lib/LoaderOptionsPlugin.js +81 -0
- package/lib/LoaderTargetPlugin.js +39 -0
- package/lib/MainTemplate.js +371 -0
- package/lib/ManifestPlugin.js +242 -0
- package/lib/Module.js +1319 -0
- package/lib/ModuleBuildError.js +83 -0
- package/lib/ModuleDependencyError.js +44 -0
- package/lib/ModuleDependencyWarning.js +49 -0
- package/lib/ModuleError.js +69 -0
- package/lib/ModuleFactory.js +57 -0
- package/lib/ModuleFilenameHelpers.js +388 -0
- package/lib/ModuleGraph.js +1024 -0
- package/lib/ModuleGraphConnection.js +199 -0
- package/lib/ModuleHashingError.js +31 -0
- package/lib/ModuleInfoHeaderPlugin.js +318 -0
- package/lib/ModuleNotFoundError.js +90 -0
- package/lib/ModuleParseError.js +125 -0
- package/lib/ModuleProfile.js +108 -0
- package/lib/ModuleRestoreError.js +46 -0
- package/lib/ModuleSourceTypeConstants.js +179 -0
- package/lib/ModuleStoreError.js +45 -0
- package/lib/ModuleTemplate.js +173 -0
- package/lib/ModuleTypeConstants.js +190 -0
- package/lib/ModuleWarning.js +68 -0
- package/lib/MultiCompiler.js +678 -0
- package/lib/MultiStats.js +213 -0
- package/lib/MultiWatching.js +77 -0
- package/lib/NoEmitOnErrorsPlugin.js +30 -0
- package/lib/NoModeWarning.js +23 -0
- package/lib/NodeStuffInWebError.js +35 -0
- package/lib/NodeStuffPlugin.js +587 -0
- package/lib/NormalModule.js +1798 -0
- package/lib/NormalModuleFactory.js +1455 -0
- package/lib/NormalModuleReplacementPlugin.js +75 -0
- package/lib/NullFactory.js +24 -0
- package/lib/OptimizationStages.js +10 -0
- package/lib/OptionsApply.js +24 -0
- package/lib/Parser.js +40 -0
- package/lib/PlatformPlugin.js +41 -0
- package/lib/PrefetchPlugin.js +56 -0
- package/lib/ProgressPlugin.js +712 -0
- package/lib/ProvidePlugin.js +121 -0
- package/lib/RawModule.js +180 -0
- package/lib/RecordIdsPlugin.js +216 -0
- package/lib/RequestShortener.js +36 -0
- package/lib/RequireJsStuffPlugin.js +84 -0
- package/lib/ResolverFactory.js +156 -0
- package/lib/RuntimeGlobals.js +450 -0
- package/lib/RuntimeModule.js +242 -0
- package/lib/RuntimePlugin.js +547 -0
- package/lib/RuntimeTemplate.js +1288 -0
- package/lib/SelfModuleFactory.js +33 -0
- package/lib/SingleEntryPlugin.js +8 -0
- package/lib/SizeFormatHelpers.js +25 -0
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +52 -0
- package/lib/SourceMapDevToolPlugin.js +646 -0
- package/lib/Stats.js +89 -0
- package/lib/Template.js +427 -0
- package/lib/TemplatedPathPlugin.js +400 -0
- package/lib/UnhandledSchemeError.js +34 -0
- package/lib/UnsupportedFeatureWarning.js +35 -0
- package/lib/UseStrictPlugin.js +81 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +64 -0
- package/lib/WarnDeprecatedOptionPlugin.js +60 -0
- package/lib/WarnNoModeSetPlugin.js +27 -0
- package/lib/WatchIgnorePlugin.js +155 -0
- package/lib/Watching.js +531 -0
- package/lib/WebpackError.js +81 -0
- package/lib/WebpackIsIncludedPlugin.js +93 -0
- package/lib/WebpackOptionsApply.js +941 -0
- package/lib/WebpackOptionsDefaulter.js +26 -0
- package/lib/asset/AssetBytesGenerator.js +172 -0
- package/lib/asset/AssetBytesParser.js +37 -0
- package/lib/asset/AssetGenerator.js +816 -0
- package/lib/asset/AssetModulesPlugin.js +358 -0
- package/lib/asset/AssetParser.js +73 -0
- package/lib/asset/AssetSourceGenerator.js +171 -0
- package/lib/asset/AssetSourceParser.js +37 -0
- package/lib/asset/RawDataUrlModule.js +179 -0
- package/lib/async-modules/AsyncModuleHelpers.js +52 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +90 -0
- package/lib/async-modules/InferAsyncModulesPlugin.js +54 -0
- package/lib/buildChunkGraph.js +1392 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +32 -0
- package/lib/cache/AddManagedPathsPlugin.js +40 -0
- package/lib/cache/IdleFileCachePlugin.js +242 -0
- package/lib/cache/MemoryCachePlugin.js +57 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +142 -0
- package/lib/cache/PackFileCacheStrategy.js +1600 -0
- package/lib/cache/ResolverCachePlugin.js +450 -0
- package/lib/cache/getLazyHashedEtag.js +91 -0
- package/lib/cache/mergeEtags.js +71 -0
- package/lib/cli.js +859 -0
- package/lib/config/browserslistTargetHandler.js +388 -0
- package/lib/config/defaults.js +2086 -0
- package/lib/config/normalization.js +681 -0
- package/lib/config/target.js +389 -0
- package/lib/container/ContainerEntryDependency.js +50 -0
- package/lib/container/ContainerEntryModule.js +303 -0
- package/lib/container/ContainerEntryModuleFactory.js +27 -0
- package/lib/container/ContainerExposedDependency.js +62 -0
- package/lib/container/ContainerPlugin.js +118 -0
- package/lib/container/ContainerReferencePlugin.js +139 -0
- package/lib/container/FallbackDependency.js +66 -0
- package/lib/container/FallbackItemDependency.js +34 -0
- package/lib/container/FallbackModule.js +193 -0
- package/lib/container/FallbackModuleFactory.js +27 -0
- package/lib/container/HoistContainerReferencesPlugin.js +256 -0
- package/lib/container/ModuleFederationPlugin.js +131 -0
- package/lib/container/RemoteModule.js +225 -0
- package/lib/container/RemoteRuntimeModule.js +144 -0
- package/lib/container/RemoteToExternalDependency.js +33 -0
- package/lib/container/options.js +105 -0
- package/lib/css/CssGenerator.js +587 -0
- package/lib/css/CssLoadingRuntimeModule.js +513 -0
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +939 -0
- package/lib/css/CssParser.js +2621 -0
- package/lib/css/walkCssTokens.js +1740 -0
- package/lib/debug/ProfilingPlugin.js +589 -0
- package/lib/dependencies/AMDDefineDependency.js +267 -0
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +504 -0
- package/lib/dependencies/AMDPlugin.js +243 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +124 -0
- package/lib/dependencies/AMDRequireContextDependency.js +69 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +28 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +425 -0
- package/lib/dependencies/AMDRequireDependency.js +189 -0
- package/lib/dependencies/AMDRequireItemDependency.js +41 -0
- package/lib/dependencies/AMDRuntimeModules.js +50 -0
- package/lib/dependencies/CachedConstDependency.js +135 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +65 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +416 -0
- package/lib/dependencies/CommonJsExportsDependency.js +184 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +425 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +162 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +611 -0
- package/lib/dependencies/CommonJsPlugin.js +316 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +73 -0
- package/lib/dependencies/CommonJsRequireDependency.js +42 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +156 -0
- package/lib/dependencies/ConstDependency.js +118 -0
- package/lib/dependencies/ContextDependency.js +183 -0
- package/lib/dependencies/ContextDependencyHelpers.js +277 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +63 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +62 -0
- package/lib/dependencies/ContextElementDependency.js +147 -0
- package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +75 -0
- package/lib/dependencies/CriticalDependencyWarning.js +29 -0
- package/lib/dependencies/CssIcssExportDependency.js +539 -0
- package/lib/dependencies/CssIcssImportDependency.js +183 -0
- package/lib/dependencies/CssIcssSymbolDependency.js +131 -0
- package/lib/dependencies/CssImportDependency.js +120 -0
- package/lib/dependencies/CssUrlDependency.js +189 -0
- package/lib/dependencies/DelegatedSourceDependency.js +33 -0
- package/lib/dependencies/DllEntryDependency.js +61 -0
- package/lib/dependencies/DynamicExports.js +73 -0
- package/lib/dependencies/EntryDependency.js +30 -0
- package/lib/dependencies/ExportsInfoDependency.js +161 -0
- package/lib/dependencies/ExternalModuleDependency.js +109 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +137 -0
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +237 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +37 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +91 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +103 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +165 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +254 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +211 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +78 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +1494 -0
- package/lib/dependencies/HarmonyExportInitFragment.js +191 -0
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +127 -0
- package/lib/dependencies/HarmonyExports.js +46 -0
- package/lib/dependencies/HarmonyImportDependency.js +459 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +576 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +91 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +514 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +158 -0
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +39 -0
- package/lib/dependencies/ImportContextDependency.js +81 -0
- package/lib/dependencies/ImportDependency.js +158 -0
- package/lib/dependencies/ImportEagerDependency.js +76 -0
- package/lib/dependencies/ImportMetaContextDependency.js +42 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +312 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +41 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +42 -0
- package/lib/dependencies/ImportMetaPlugin.js +447 -0
- package/lib/dependencies/ImportParserPlugin.js +602 -0
- package/lib/dependencies/ImportPhase.js +125 -0
- package/lib/dependencies/ImportPlugin.js +98 -0
- package/lib/dependencies/ImportWeakDependency.js +74 -0
- package/lib/dependencies/JsonExportsDependency.js +137 -0
- package/lib/dependencies/LoaderDependency.js +38 -0
- package/lib/dependencies/LoaderImportDependency.js +39 -0
- package/lib/dependencies/LoaderPlugin.js +294 -0
- package/lib/dependencies/LocalModule.js +60 -0
- package/lib/dependencies/LocalModuleDependency.js +84 -0
- package/lib/dependencies/LocalModulesHelpers.js +68 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +136 -0
- package/lib/dependencies/ModuleDependency.js +100 -0
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +35 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +39 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +41 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +42 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/NullDependency.js +42 -0
- package/lib/dependencies/PrefetchDependency.js +27 -0
- package/lib/dependencies/ProvidedDependency.js +156 -0
- package/lib/dependencies/PureExpressionDependency.js +161 -0
- package/lib/dependencies/RequireContextDependency.js +38 -0
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +69 -0
- package/lib/dependencies/RequireContextPlugin.js +167 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +29 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +145 -0
- package/lib/dependencies/RequireEnsureDependency.js +115 -0
- package/lib/dependencies/RequireEnsureItemDependency.js +36 -0
- package/lib/dependencies/RequireEnsurePlugin.js +86 -0
- package/lib/dependencies/RequireHeaderDependency.js +70 -0
- package/lib/dependencies/RequireIncludeDependency.js +79 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +100 -0
- package/lib/dependencies/RequireIncludePlugin.js +63 -0
- package/lib/dependencies/RequireResolveContextDependency.js +67 -0
- package/lib/dependencies/RequireResolveDependency.js +58 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +81 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +85 -0
- package/lib/dependencies/StaticExportsDependency.js +72 -0
- package/lib/dependencies/SystemPlugin.js +168 -0
- package/lib/dependencies/SystemRuntimeModule.js +35 -0
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLDependency.js +165 -0
- package/lib/dependencies/URLPlugin.js +67 -0
- package/lib/dependencies/UnsupportedDependency.js +82 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +93 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +108 -0
- package/lib/dependencies/WebpackIsIncludedDependency.js +84 -0
- package/lib/dependencies/WorkerDependency.js +141 -0
- package/lib/dependencies/WorkerPlugin.js +565 -0
- package/lib/dependencies/getFunctionExpression.js +66 -0
- package/lib/dependencies/processExportInfo.js +67 -0
- package/lib/electron/ElectronTargetPlugin.js +71 -0
- package/lib/errors/BuildCycleError.js +30 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +30 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +273 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +143 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +426 -0
- package/lib/formatLocation.js +67 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +419 -0
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +42 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +471 -0
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +473 -0
- package/lib/hmr/lazyCompilationBackend.js +167 -0
- package/lib/ids/ChunkModuleIdRangePlugin.js +94 -0
- package/lib/ids/DeterministicChunkIdsPlugin.js +73 -0
- package/lib/ids/DeterministicModuleIdsPlugin.js +98 -0
- package/lib/ids/HashedModuleIdsPlugin.js +85 -0
- package/lib/ids/IdHelpers.js +492 -0
- package/lib/ids/NamedChunkIdsPlugin.js +92 -0
- package/lib/ids/NamedModuleIdsPlugin.js +68 -0
- package/lib/ids/NaturalChunkIdsPlugin.js +35 -0
- package/lib/ids/NaturalModuleIdsPlugin.js +40 -0
- package/lib/ids/OccurrenceChunkIdsPlugin.js +86 -0
- package/lib/ids/OccurrenceModuleIdsPlugin.js +168 -0
- package/lib/ids/SyncModuleIdsPlugin.js +161 -0
- package/lib/index.js +681 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +153 -0
- package/lib/javascript/BasicEvaluatedExpression.js +603 -0
- package/lib/javascript/ChunkFormatHelpers.js +70 -0
- package/lib/javascript/ChunkHelpers.js +45 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +148 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +127 -0
- package/lib/javascript/JavascriptGenerator.js +277 -0
- package/lib/javascript/JavascriptModulesPlugin.js +1905 -0
- package/lib/javascript/JavascriptParser.js +5476 -0
- package/lib/javascript/JavascriptParserHelpers.js +129 -0
- package/lib/javascript/StartupHelpers.js +178 -0
- package/lib/json/JsonData.js +74 -0
- package/lib/json/JsonGenerator.js +234 -0
- package/lib/json/JsonModulesPlugin.js +66 -0
- package/lib/json/JsonParser.js +93 -0
- package/lib/library/AbstractLibraryPlugin.js +339 -0
- package/lib/library/AmdLibraryPlugin.js +181 -0
- package/lib/library/AssignLibraryPlugin.js +445 -0
- package/lib/library/EnableLibraryPlugin.js +306 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +116 -0
- package/lib/library/JsonpLibraryPlugin.js +92 -0
- package/lib/library/ModuleLibraryPlugin.js +438 -0
- package/lib/library/SystemLibraryPlugin.js +256 -0
- package/lib/library/UmdLibraryPlugin.js +355 -0
- package/lib/logging/Logger.js +223 -0
- package/lib/logging/createConsoleLogger.js +217 -0
- package/lib/logging/runtime.js +45 -0
- package/lib/logging/truncateArgs.js +83 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +120 -0
- package/lib/node/NodeEnvironmentPlugin.js +73 -0
- package/lib/node/NodeSourcePlugin.js +19 -0
- package/lib/node/NodeTargetPlugin.js +102 -0
- package/lib/node/NodeTemplatePlugin.js +42 -0
- package/lib/node/NodeWatchFileSystem.js +198 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +286 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +123 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +127 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +239 -0
- package/lib/node/nodeConsole.js +185 -0
- package/lib/optimize/AggressiveMergingPlugin.js +98 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +352 -0
- package/lib/optimize/ConcatenatedModule.js +2290 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +88 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +137 -0
- package/lib/optimize/InnerGraph.js +368 -0
- package/lib/optimize/InnerGraphPlugin.js +455 -0
- package/lib/optimize/LimitChunkCountPlugin.js +302 -0
- package/lib/optimize/MangleExportsPlugin.js +194 -0
- package/lib/optimize/MergeDuplicateChunksPlugin.js +138 -0
- package/lib/optimize/MinChunkSizePlugin.js +121 -0
- package/lib/optimize/MinMaxSizeWarning.js +35 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +971 -0
- package/lib/optimize/RealContentHashPlugin.js +488 -0
- package/lib/optimize/RemoveEmptyChunksPlugin.js +60 -0
- package/lib/optimize/RemoveParentModulesPlugin.js +216 -0
- package/lib/optimize/RuntimeChunkPlugin.js +52 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +417 -0
- package/lib/optimize/SplitChunksPlugin.js +1836 -0
- package/lib/performance/AssetsOverSizeLimitWarning.js +37 -0
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +40 -0
- package/lib/performance/NoAsyncChunksWarning.js +21 -0
- package/lib/performance/SizeLimitsPlugin.js +183 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +46 -0
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +95 -0
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +56 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +52 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +46 -0
- package/lib/rules/BasicEffectRulePlugin.js +56 -0
- package/lib/rules/BasicMatcherRulePlugin.js +68 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +79 -0
- package/lib/rules/RuleSetCompiler.js +447 -0
- package/lib/rules/UseEffectRulePlugin.js +236 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +199 -0
- package/lib/runtime/AutoPublicPathRuntimeModule.js +90 -0
- package/lib/runtime/BaseUriRuntimeModule.js +35 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +28 -0
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +40 -0
- package/lib/runtime/CompatRuntimeModule.js +83 -0
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +69 -0
- package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +38 -0
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +42 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +69 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +299 -0
- package/lib/runtime/GetFullHashRuntimeModule.js +31 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +49 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +99 -0
- package/lib/runtime/GlobalRuntimeModule.js +47 -0
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +35 -0
- package/lib/runtime/HelperRuntimeModule.js +18 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +174 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +232 -0
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +39 -0
- package/lib/runtime/NonceRuntimeModule.js +24 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +78 -0
- package/lib/runtime/PublicPathRuntimeModule.js +38 -0
- package/lib/runtime/RelativeUrlRuntimeModule.js +44 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +33 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +88 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +77 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +54 -0
- package/lib/runtime/SystemContextRuntimeModule.js +23 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +72 -0
- package/lib/schemes/DataUriPlugin.js +47 -0
- package/lib/schemes/FileUriPlugin.js +54 -0
- package/lib/schemes/HttpUriPlugin.js +1410 -0
- package/lib/schemes/VirtualUrlPlugin.js +248 -0
- package/lib/serialization/AggregateErrorSerializer.js +41 -0
- package/lib/serialization/ArraySerializer.js +38 -0
- package/lib/serialization/BinaryMiddleware.js +1164 -0
- package/lib/serialization/DateObjectSerializer.js +28 -0
- package/lib/serialization/ErrorObjectSerializer.js +49 -0
- package/lib/serialization/FileMiddleware.js +766 -0
- package/lib/serialization/MapObjectSerializer.js +48 -0
- package/lib/serialization/NullPrototypeObjectSerializer.js +53 -0
- package/lib/serialization/ObjectMiddleware.js +877 -0
- package/lib/serialization/PlainObjectSerializer.js +119 -0
- package/lib/serialization/RegExpObjectSerializer.js +29 -0
- package/lib/serialization/Serializer.js +82 -0
- package/lib/serialization/SerializerMiddleware.js +226 -0
- package/lib/serialization/SetObjectSerializer.js +40 -0
- package/lib/serialization/SingleItemMiddleware.js +36 -0
- package/lib/serialization/types.js +13 -0
- package/lib/sharing/ConsumeSharedFallbackDependency.js +33 -0
- package/lib/sharing/ConsumeSharedModule.js +344 -0
- package/lib/sharing/ConsumeSharedPlugin.js +380 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +358 -0
- package/lib/sharing/ProvideForSharedDependency.js +33 -0
- package/lib/sharing/ProvideSharedDependency.js +80 -0
- package/lib/sharing/ProvideSharedModule.js +196 -0
- package/lib/sharing/ProvideSharedModuleFactory.js +37 -0
- package/lib/sharing/ProvideSharedPlugin.js +248 -0
- package/lib/sharing/SharePlugin.js +91 -0
- package/lib/sharing/ShareRuntimeModule.js +152 -0
- package/lib/sharing/resolveMatchedConfigs.js +106 -0
- package/lib/sharing/utils.js +421 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +2791 -0
- package/lib/stats/DefaultStatsPresetPlugin.js +417 -0
- package/lib/stats/DefaultStatsPrinterPlugin.js +1860 -0
- package/lib/stats/StatsFactory.js +406 -0
- package/lib/stats/StatsPrinter.js +300 -0
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/AppendOnlyStackedSet.js +78 -0
- package/lib/util/ArrayHelpers.js +46 -0
- package/lib/util/ArrayQueue.js +104 -0
- package/lib/util/AsyncQueue.js +411 -0
- package/lib/util/Hash.js +68 -0
- package/lib/util/IterableHelpers.js +46 -0
- package/lib/util/LazyBucketSortedSet.js +272 -0
- package/lib/util/LazySet.js +236 -0
- package/lib/util/MapHelpers.js +34 -0
- package/lib/util/ParallelismFactorCalculator.js +70 -0
- package/lib/util/Queue.js +52 -0
- package/lib/util/Semaphore.js +51 -0
- package/lib/util/SetHelpers.js +94 -0
- package/lib/util/SortableSet.js +176 -0
- package/lib/util/StackedCacheMap.js +140 -0
- package/lib/util/StackedMap.js +164 -0
- package/lib/util/StringXor.js +103 -0
- package/lib/util/TupleQueue.js +70 -0
- package/lib/util/TupleSet.js +185 -0
- package/lib/util/URLAbsoluteSpecifier.js +86 -0
- package/lib/util/WeakTupleMap.js +227 -0
- package/lib/util/binarySearchBounds.js +136 -0
- package/lib/util/chainedImports.js +99 -0
- package/lib/util/cleverMerge.js +676 -0
- package/lib/util/comparators.js +645 -0
- package/lib/util/compileBooleanMatcher.js +313 -0
- package/lib/util/concatenate.js +232 -0
- package/lib/util/conventions.js +126 -0
- package/lib/util/create-schema-validation.js +41 -0
- package/lib/util/createHash.js +91 -0
- package/lib/util/dataURL.js +39 -0
- package/lib/util/deprecation.js +350 -0
- package/lib/util/deterministicGrouping.js +561 -0
- package/lib/util/extractSourceMap.js +318 -0
- package/lib/util/extractUrlAndGlobal.js +18 -0
- package/lib/util/findGraphRoots.js +211 -0
- package/lib/util/fs.js +675 -0
- package/lib/util/generateDebugId.js +33 -0
- package/lib/util/hash/BatchedHash.js +115 -0
- package/lib/util/hash/BulkUpdateHash.js +145 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +217 -0
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +232 -0
- package/lib/util/hash/xxhash64.js +20 -0
- package/lib/util/identifier.js +471 -0
- package/lib/util/internalSerializables.js +222 -0
- package/lib/util/magicComment.js +25 -0
- package/lib/util/makeSerializable.js +60 -0
- package/lib/util/memoize.js +36 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/numberHash.js +95 -0
- package/lib/util/objectToMap.js +15 -0
- package/lib/util/processAsyncTree.js +68 -0
- package/lib/util/propertyAccess.js +30 -0
- package/lib/util/propertyName.js +76 -0
- package/lib/util/registerExternalSerializer.js +334 -0
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +717 -0
- package/lib/util/semver.js +604 -0
- package/lib/util/serialization.js +153 -0
- package/lib/util/smartGrouping.js +221 -0
- package/lib/util/source.js +62 -0
- package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
- package/lib/validateSchema.js +177 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +146 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +154 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +74 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +212 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +209 -0
- package/lib/wasm-async/AsyncWebAssemblyParser.js +80 -0
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +107 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +20 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +422 -0
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +91 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +535 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +111 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +236 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +151 -0
- package/lib/wasm-sync/WebAssemblyParser.js +201 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +66 -0
- package/lib/web/FetchCompileAsyncWasmPlugin.js +70 -0
- package/lib/web/FetchCompileWasmPlugin.js +86 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +101 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +455 -0
- package/lib/web/JsonpTemplatePlugin.js +37 -0
- package/lib/webpack.js +227 -0
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +110 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +231 -0
- package/lib/webworker/WebWorkerTemplatePlugin.js +26 -0
- package/module.d.ts +238 -0
- package/package.json +258 -0
- package/schemas/WebpackOptions.check.d.ts +7 -0
- package/schemas/WebpackOptions.check.js +6 -0
- package/schemas/WebpackOptions.json +6179 -0
- package/schemas/_container.json +155 -0
- package/schemas/_sharing.json +118 -0
- package/schemas/plugins/BannerPlugin.check.d.ts +7 -0
- package/schemas/plugins/BannerPlugin.check.js +6 -0
- package/schemas/plugins/BannerPlugin.json +115 -0
- package/schemas/plugins/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/DllPlugin.check.js +6 -0
- package/schemas/plugins/DllPlugin.json +36 -0
- package/schemas/plugins/DllReferencePlugin.check.d.ts +7 -0
- package/schemas/plugins/DllReferencePlugin.check.js +6 -0
- package/schemas/plugins/DllReferencePlugin.json +206 -0
- package/schemas/plugins/IgnorePlugin.check.d.ts +7 -0
- package/schemas/plugins/IgnorePlugin.check.js +6 -0
- package/schemas/plugins/IgnorePlugin.json +34 -0
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +7 -0
- package/schemas/plugins/LoaderOptionsPlugin.check.js +6 -0
- package/schemas/plugins/LoaderOptionsPlugin.json +27 -0
- package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/ProgressPlugin.check.d.ts +7 -0
- package/schemas/plugins/ProgressPlugin.check.js +6 -0
- package/schemas/plugins/ProgressPlugin.json +65 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +7 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +6 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +168 -0
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +7 -0
- package/schemas/plugins/WatchIgnorePlugin.check.js +6 -0
- package/schemas/plugins/WatchIgnorePlugin.json +25 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +6 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.json +3 -0
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +6 -0
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.json +3 -0
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +7 -0
- package/schemas/plugins/asset/AssetParserOptions.check.js +6 -0
- package/schemas/plugins/asset/AssetParserOptions.json +3 -0
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +6 -0
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.json +3 -0
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +7 -0
- package/schemas/plugins/container/ContainerPlugin.check.js +6 -0
- package/schemas/plugins/container/ContainerPlugin.json +294 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +7 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +6 -0
- package/schemas/plugins/container/ContainerReferencePlugin.json +132 -0
- package/schemas/plugins/container/ExternalsType.check.d.ts +7 -0
- package/schemas/plugins/container/ExternalsType.check.js +6 -0
- package/schemas/plugins/container/ExternalsType.json +3 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +7 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +6 -0
- package/schemas/plugins/container/ModuleFederationPlugin.json +525 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +7 -0
- package/schemas/plugins/debug/ProfilingPlugin.check.js +6 -0
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.json +57 -0
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +6 -0
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.json +11 -0
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.json +11 -0
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +6 -0
- package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +7 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +6 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +23 -0
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +7 -0
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +6 -0
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +21 -0
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +7 -0
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +6 -0
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.json +11 -0
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +7 -0
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +6 -0
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +20 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
- package/schemas/plugins/schemes/HttpUriPlugin.json +74 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +7 -0
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +6 -0
- package/schemas/plugins/sharing/ConsumeSharedPlugin.json +120 -0
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +7 -0
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +6 -0
- package/schemas/plugins/sharing/ProvideSharedPlugin.json +94 -0
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +7 -0
- package/schemas/plugins/sharing/SharePlugin.check.js +6 -0
- package/schemas/plugins/sharing/SharePlugin.json +133 -0
- package/types.d.ts +20217 -0
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
// Simulations show these probabilities for a single change
|
|
9
|
+
// 93.1% that one group is invalidated
|
|
10
|
+
// 4.8% that two groups are invalidated
|
|
11
|
+
// 1.1% that 3 groups are invalidated
|
|
12
|
+
// 0.1% that 4 or more groups are invalidated
|
|
13
|
+
//
|
|
14
|
+
// And these for removing/adding 10 lexically adjacent files
|
|
15
|
+
// 64.5% that one group is invalidated
|
|
16
|
+
// 24.8% that two groups are invalidated
|
|
17
|
+
// 7.8% that 3 groups are invalidated
|
|
18
|
+
// 2.7% that 4 or more groups are invalidated
|
|
19
|
+
//
|
|
20
|
+
// And these for removing/adding 3 random files
|
|
21
|
+
// 0% that one group is invalidated
|
|
22
|
+
// 3.7% that two groups are invalidated
|
|
23
|
+
// 80.8% that 3 groups are invalidated
|
|
24
|
+
// 12.3% that 4 groups are invalidated
|
|
25
|
+
// 3.2% that 5 or more groups are invalidated
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} a key
|
|
29
|
+
* @param {string} b key
|
|
30
|
+
* @returns {number} the similarity as number
|
|
31
|
+
*/
|
|
32
|
+
const similarity = (a, b) => {
|
|
33
|
+
const l = Math.min(a.length, b.length);
|
|
34
|
+
let dist = 0;
|
|
35
|
+
for (let i = 0; i < l; i++) {
|
|
36
|
+
const ca = a.charCodeAt(i);
|
|
37
|
+
const cb = b.charCodeAt(i);
|
|
38
|
+
dist += Math.max(0, 10 - Math.abs(ca - cb));
|
|
39
|
+
}
|
|
40
|
+
return dist;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} a key
|
|
45
|
+
* @param {string} b key
|
|
46
|
+
* @param {Set<string>} usedNames set of already used names
|
|
47
|
+
* @returns {string} the common part and a single char for the difference
|
|
48
|
+
*/
|
|
49
|
+
const getName = (a, b, usedNames) => {
|
|
50
|
+
const l = Math.min(a.length, b.length);
|
|
51
|
+
let i = 0;
|
|
52
|
+
while (i < l) {
|
|
53
|
+
if (a.charCodeAt(i) !== b.charCodeAt(i)) {
|
|
54
|
+
i++;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
i++;
|
|
58
|
+
}
|
|
59
|
+
while (i < l) {
|
|
60
|
+
const name = a.slice(0, i);
|
|
61
|
+
const lowerName = name.toLowerCase();
|
|
62
|
+
if (!usedNames.has(lowerName)) {
|
|
63
|
+
usedNames.add(lowerName);
|
|
64
|
+
return name;
|
|
65
|
+
}
|
|
66
|
+
i++;
|
|
67
|
+
}
|
|
68
|
+
// names always contain a hash, so this is always unique
|
|
69
|
+
// we don't need to check usedNames nor add it
|
|
70
|
+
return a;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/** @typedef {Record<string, number>} Sizes */
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {Sizes} total total size
|
|
77
|
+
* @param {Sizes} size single size
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
80
|
+
const addSizeTo = (total, size) => {
|
|
81
|
+
for (const key of Object.keys(size)) {
|
|
82
|
+
total[key] = (total[key] || 0) + size[key];
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {Sizes} total total size
|
|
88
|
+
* @param {Sizes} size single size
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
const subtractSizeFrom = (total, size) => {
|
|
92
|
+
for (const key of Object.keys(size)) {
|
|
93
|
+
total[key] -= size[key];
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @template T
|
|
99
|
+
* @param {Iterable<Node<T>>} nodes some nodes
|
|
100
|
+
* @returns {Sizes} total size
|
|
101
|
+
*/
|
|
102
|
+
const sumSize = (nodes) => {
|
|
103
|
+
/** @type {Sizes} */
|
|
104
|
+
const sum = Object.create(null);
|
|
105
|
+
for (const node of nodes) {
|
|
106
|
+
addSizeTo(sum, node.size);
|
|
107
|
+
}
|
|
108
|
+
return sum;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {Sizes} size size
|
|
113
|
+
* @param {Sizes} maxSize minimum size
|
|
114
|
+
* @returns {boolean} true, when size is too big
|
|
115
|
+
*/
|
|
116
|
+
const isTooBig = (size, maxSize) => {
|
|
117
|
+
for (const key of Object.keys(size)) {
|
|
118
|
+
const s = size[key];
|
|
119
|
+
if (s === 0) continue;
|
|
120
|
+
const maxSizeValue = maxSize[key];
|
|
121
|
+
if (typeof maxSizeValue === "number" && s > maxSizeValue) return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @param {Sizes} size size
|
|
128
|
+
* @param {Sizes} minSize minimum size
|
|
129
|
+
* @returns {boolean} true, when size is too small
|
|
130
|
+
*/
|
|
131
|
+
const isTooSmall = (size, minSize) => {
|
|
132
|
+
for (const key of Object.keys(size)) {
|
|
133
|
+
const s = size[key];
|
|
134
|
+
if (s === 0) continue;
|
|
135
|
+
const minSizeValue = minSize[key];
|
|
136
|
+
if (typeof minSizeValue === "number" && s < minSizeValue) return true;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/** @typedef {Set<string>} Types */
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @param {Sizes} size size
|
|
145
|
+
* @param {Sizes} minSize minimum size
|
|
146
|
+
* @returns {Types} set of types that are too small
|
|
147
|
+
*/
|
|
148
|
+
const getTooSmallTypes = (size, minSize) => {
|
|
149
|
+
/** @type {Types} */
|
|
150
|
+
const types = new Set();
|
|
151
|
+
for (const key of Object.keys(size)) {
|
|
152
|
+
const s = size[key];
|
|
153
|
+
if (s === 0) continue;
|
|
154
|
+
const minSizeValue = minSize[key];
|
|
155
|
+
if (typeof minSizeValue === "number" && s < minSizeValue) types.add(key);
|
|
156
|
+
}
|
|
157
|
+
return types;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @template {object} T
|
|
162
|
+
* @param {T} size size
|
|
163
|
+
* @param {Types} types types
|
|
164
|
+
* @returns {number} number of matching size types
|
|
165
|
+
*/
|
|
166
|
+
const getNumberOfMatchingSizeTypes = (size, types) => {
|
|
167
|
+
let i = 0;
|
|
168
|
+
for (const key of Object.keys(size)) {
|
|
169
|
+
if (size[/** @type {keyof T} */ (key)] !== 0 && types.has(key)) i++;
|
|
170
|
+
}
|
|
171
|
+
return i;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {Sizes} size size
|
|
176
|
+
* @param {Types} types types
|
|
177
|
+
* @returns {number} selective size sum
|
|
178
|
+
*/
|
|
179
|
+
const selectiveSizeSum = (size, types) => {
|
|
180
|
+
let sum = 0;
|
|
181
|
+
for (const key of Object.keys(size)) {
|
|
182
|
+
if (size[key] !== 0 && types.has(key)) sum += size[key];
|
|
183
|
+
}
|
|
184
|
+
return sum;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @template T
|
|
189
|
+
*/
|
|
190
|
+
class Node {
|
|
191
|
+
/**
|
|
192
|
+
* @param {T} item item
|
|
193
|
+
* @param {string} key key
|
|
194
|
+
* @param {Sizes} size size
|
|
195
|
+
*/
|
|
196
|
+
constructor(item, key, size) {
|
|
197
|
+
this.item = item;
|
|
198
|
+
this.key = key;
|
|
199
|
+
this.size = size;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** @typedef {number[]} Similarities */
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @template T
|
|
207
|
+
*/
|
|
208
|
+
class Group {
|
|
209
|
+
/**
|
|
210
|
+
* @param {Node<T>[]} nodes nodes
|
|
211
|
+
* @param {Similarities | null} similarities similarities between the nodes (length = nodes.length - 1)
|
|
212
|
+
* @param {Sizes=} size size of the group
|
|
213
|
+
*/
|
|
214
|
+
constructor(nodes, similarities, size) {
|
|
215
|
+
this.nodes = nodes;
|
|
216
|
+
this.similarities = similarities;
|
|
217
|
+
this.size = size || sumSize(nodes);
|
|
218
|
+
/** @type {string | undefined} */
|
|
219
|
+
this.key = undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* @param {(node: Node<T>) => boolean} filter filter function
|
|
224
|
+
* @returns {Node<T>[] | undefined} removed nodes
|
|
225
|
+
*/
|
|
226
|
+
popNodes(filter) {
|
|
227
|
+
/** @type {Node<T>[]} */
|
|
228
|
+
const newNodes = [];
|
|
229
|
+
/** @type {Similarities} */
|
|
230
|
+
const newSimilarities = [];
|
|
231
|
+
/** @type {Node<T>[]} */
|
|
232
|
+
const resultNodes = [];
|
|
233
|
+
/** @type {undefined | Node<T>} */
|
|
234
|
+
let lastNode;
|
|
235
|
+
for (let i = 0; i < this.nodes.length; i++) {
|
|
236
|
+
const node = this.nodes[i];
|
|
237
|
+
if (filter(node)) {
|
|
238
|
+
resultNodes.push(node);
|
|
239
|
+
} else {
|
|
240
|
+
if (newNodes.length > 0) {
|
|
241
|
+
newSimilarities.push(
|
|
242
|
+
lastNode === this.nodes[i - 1]
|
|
243
|
+
? /** @type {Similarities} */ (this.similarities)[i - 1]
|
|
244
|
+
: similarity(/** @type {Node<T>} */ (lastNode).key, node.key)
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
newNodes.push(node);
|
|
248
|
+
lastNode = node;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (resultNodes.length === this.nodes.length) return;
|
|
252
|
+
this.nodes = newNodes;
|
|
253
|
+
this.similarities = newSimilarities;
|
|
254
|
+
this.size = sumSize(newNodes);
|
|
255
|
+
return resultNodes;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* @template T
|
|
261
|
+
* @param {Iterable<Node<T>>} nodes nodes
|
|
262
|
+
* @returns {Similarities} similarities
|
|
263
|
+
*/
|
|
264
|
+
const getSimilarities = (nodes) => {
|
|
265
|
+
// calculate similarities between lexically adjacent nodes
|
|
266
|
+
/** @type {Similarities} */
|
|
267
|
+
const similarities = [];
|
|
268
|
+
/** @type {undefined | Node<T>} */
|
|
269
|
+
let last;
|
|
270
|
+
for (const node of nodes) {
|
|
271
|
+
if (last !== undefined) {
|
|
272
|
+
similarities.push(similarity(last.key, node.key));
|
|
273
|
+
}
|
|
274
|
+
last = node;
|
|
275
|
+
}
|
|
276
|
+
return similarities;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @template T
|
|
281
|
+
* @typedef {object} GroupedItems<T>
|
|
282
|
+
* @property {string} key
|
|
283
|
+
* @property {T[]} items
|
|
284
|
+
* @property {Sizes} size
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @template T
|
|
289
|
+
* @typedef {object} Options
|
|
290
|
+
* @property {Sizes} maxSize maximum size of a group
|
|
291
|
+
* @property {Sizes} minSize minimum size of a group (preferred over maximum size)
|
|
292
|
+
* @property {Iterable<T>} items a list of items
|
|
293
|
+
* @property {(item: T) => Sizes} getSize function to get size of an item
|
|
294
|
+
* @property {(item: T) => string} getKey function to get the key of an item
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @template T
|
|
299
|
+
* @param {Options<T>} options options object
|
|
300
|
+
* @returns {GroupedItems<T>[]} grouped items
|
|
301
|
+
*/
|
|
302
|
+
module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
303
|
+
/** @type {Group<T>[]} */
|
|
304
|
+
const result = [];
|
|
305
|
+
|
|
306
|
+
const nodes = Array.from(
|
|
307
|
+
items,
|
|
308
|
+
(item) => new Node(item, getKey(item), getSize(item))
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
/** @type {Node<T>[]} */
|
|
312
|
+
const initialNodes = [];
|
|
313
|
+
|
|
314
|
+
// lexically ordering of keys
|
|
315
|
+
nodes.sort((a, b) => {
|
|
316
|
+
if (a.key < b.key) return -1;
|
|
317
|
+
if (a.key > b.key) return 1;
|
|
318
|
+
return 0;
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// return nodes bigger than maxSize directly as group
|
|
322
|
+
// But make sure that minSize is not violated
|
|
323
|
+
for (const node of nodes) {
|
|
324
|
+
if (isTooBig(node.size, maxSize) && !isTooSmall(node.size, minSize)) {
|
|
325
|
+
result.push(new Group([node], []));
|
|
326
|
+
} else {
|
|
327
|
+
initialNodes.push(node);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (initialNodes.length > 0) {
|
|
332
|
+
const initialGroup = new Group(initialNodes, getSimilarities(initialNodes));
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @param {Group<T>} group group
|
|
336
|
+
* @param {Sizes} consideredSize size of the group to consider
|
|
337
|
+
* @returns {boolean} true, if the group was modified
|
|
338
|
+
*/
|
|
339
|
+
const removeProblematicNodes = (group, consideredSize = group.size) => {
|
|
340
|
+
const problemTypes = getTooSmallTypes(consideredSize, minSize);
|
|
341
|
+
if (problemTypes.size > 0) {
|
|
342
|
+
// We hit an edge case where the working set is already smaller than minSize
|
|
343
|
+
// We merge problematic nodes with the smallest result node to keep minSize intact
|
|
344
|
+
const problemNodes = group.popNodes(
|
|
345
|
+
(n) => getNumberOfMatchingSizeTypes(n.size, problemTypes) > 0
|
|
346
|
+
);
|
|
347
|
+
if (problemNodes === undefined) return false;
|
|
348
|
+
// Only merge it with result nodes that have the problematic size type
|
|
349
|
+
const possibleResultGroups = result.filter(
|
|
350
|
+
(n) => getNumberOfMatchingSizeTypes(n.size, problemTypes) > 0
|
|
351
|
+
);
|
|
352
|
+
if (possibleResultGroups.length > 0) {
|
|
353
|
+
const bestGroup = possibleResultGroups.reduce((min, group) => {
|
|
354
|
+
const minMatches = getNumberOfMatchingSizeTypes(min, problemTypes);
|
|
355
|
+
const groupMatches = getNumberOfMatchingSizeTypes(
|
|
356
|
+
group,
|
|
357
|
+
problemTypes
|
|
358
|
+
);
|
|
359
|
+
if (minMatches !== groupMatches) {
|
|
360
|
+
return minMatches < groupMatches ? group : min;
|
|
361
|
+
}
|
|
362
|
+
if (
|
|
363
|
+
selectiveSizeSum(min.size, problemTypes) >
|
|
364
|
+
selectiveSizeSum(group.size, problemTypes)
|
|
365
|
+
) {
|
|
366
|
+
return group;
|
|
367
|
+
}
|
|
368
|
+
return min;
|
|
369
|
+
});
|
|
370
|
+
for (const node of problemNodes) bestGroup.nodes.push(node);
|
|
371
|
+
bestGroup.nodes.sort((a, b) => {
|
|
372
|
+
if (a.key < b.key) return -1;
|
|
373
|
+
if (a.key > b.key) return 1;
|
|
374
|
+
return 0;
|
|
375
|
+
});
|
|
376
|
+
} else {
|
|
377
|
+
// There are no other nodes with the same size types
|
|
378
|
+
// We create a new group and have to accept that it's smaller than minSize
|
|
379
|
+
result.push(new Group(problemNodes, null));
|
|
380
|
+
}
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
return false;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
if (initialGroup.nodes.length > 0) {
|
|
387
|
+
const queue = [initialGroup];
|
|
388
|
+
|
|
389
|
+
while (queue.length) {
|
|
390
|
+
const group = /** @type {Group<T>} */ (queue.pop());
|
|
391
|
+
// only groups bigger than maxSize need to be splitted
|
|
392
|
+
if (!isTooBig(group.size, maxSize)) {
|
|
393
|
+
result.push(group);
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
// If the group is already too small
|
|
397
|
+
// we try to work only with the unproblematic nodes
|
|
398
|
+
if (removeProblematicNodes(group)) {
|
|
399
|
+
// This changed something, so we try this group again
|
|
400
|
+
queue.push(group);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// find unsplittable area from left and right
|
|
405
|
+
// going minSize from left and right
|
|
406
|
+
// at least one node need to be included otherwise we get stuck
|
|
407
|
+
let left = 1;
|
|
408
|
+
/** @type {Sizes} */
|
|
409
|
+
const leftSize = Object.create(null);
|
|
410
|
+
addSizeTo(leftSize, group.nodes[0].size);
|
|
411
|
+
while (left < group.nodes.length && isTooSmall(leftSize, minSize)) {
|
|
412
|
+
addSizeTo(leftSize, group.nodes[left].size);
|
|
413
|
+
left++;
|
|
414
|
+
}
|
|
415
|
+
let right = group.nodes.length - 2;
|
|
416
|
+
/** @type {Sizes} */
|
|
417
|
+
const rightSize = Object.create(null);
|
|
418
|
+
addSizeTo(rightSize, group.nodes[group.nodes.length - 1].size);
|
|
419
|
+
while (right >= 0 && isTooSmall(rightSize, minSize)) {
|
|
420
|
+
addSizeTo(rightSize, group.nodes[right].size);
|
|
421
|
+
right--;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// left v v right
|
|
425
|
+
// [ O O O ] O O O [ O O O ]
|
|
426
|
+
// ^^^^^^^^^ leftSize
|
|
427
|
+
// rightSize ^^^^^^^^^
|
|
428
|
+
// leftSize > minSize
|
|
429
|
+
// rightSize > minSize
|
|
430
|
+
|
|
431
|
+
// Perfect split: [ O O O ] [ O O O ]
|
|
432
|
+
// right === left - 1
|
|
433
|
+
|
|
434
|
+
if (left - 1 > right) {
|
|
435
|
+
// We try to remove some problematic nodes to "fix" that
|
|
436
|
+
/** @type {Sizes} */
|
|
437
|
+
let prevSize;
|
|
438
|
+
if (right < group.nodes.length - left) {
|
|
439
|
+
subtractSizeFrom(rightSize, group.nodes[right + 1].size);
|
|
440
|
+
prevSize = rightSize;
|
|
441
|
+
} else {
|
|
442
|
+
subtractSizeFrom(leftSize, group.nodes[left - 1].size);
|
|
443
|
+
prevSize = leftSize;
|
|
444
|
+
}
|
|
445
|
+
if (removeProblematicNodes(group, prevSize)) {
|
|
446
|
+
// This changed something, so we try this group again
|
|
447
|
+
queue.push(group);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
// can't split group while holding minSize
|
|
451
|
+
// because minSize is preferred of maxSize we return
|
|
452
|
+
// the problematic nodes as result here even while it's too big
|
|
453
|
+
// To avoid this make sure maxSize > minSize * 3
|
|
454
|
+
result.push(group);
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (left <= right) {
|
|
458
|
+
// when there is a area between left and right
|
|
459
|
+
// we look for best split point
|
|
460
|
+
// we split at the minimum similarity
|
|
461
|
+
// here key space is separated the most
|
|
462
|
+
// But we also need to make sure to not create too small groups
|
|
463
|
+
let best = -1;
|
|
464
|
+
let bestSimilarity = Infinity;
|
|
465
|
+
let pos = left;
|
|
466
|
+
const rightSize = sumSize(group.nodes.slice(pos));
|
|
467
|
+
|
|
468
|
+
// pos v v right
|
|
469
|
+
// [ O O O ] O O O [ O O O ]
|
|
470
|
+
// ^^^^^^^^^ leftSize
|
|
471
|
+
// rightSize ^^^^^^^^^^^^^^^
|
|
472
|
+
|
|
473
|
+
while (pos <= right + 1) {
|
|
474
|
+
const similarity =
|
|
475
|
+
/** @type {Similarities} */
|
|
476
|
+
(group.similarities)[pos - 1];
|
|
477
|
+
if (
|
|
478
|
+
similarity < bestSimilarity &&
|
|
479
|
+
!isTooSmall(leftSize, minSize) &&
|
|
480
|
+
!isTooSmall(rightSize, minSize)
|
|
481
|
+
) {
|
|
482
|
+
best = pos;
|
|
483
|
+
bestSimilarity = similarity;
|
|
484
|
+
}
|
|
485
|
+
addSizeTo(leftSize, group.nodes[pos].size);
|
|
486
|
+
subtractSizeFrom(rightSize, group.nodes[pos].size);
|
|
487
|
+
pos++;
|
|
488
|
+
}
|
|
489
|
+
if (best < 0) {
|
|
490
|
+
// This can't happen
|
|
491
|
+
// but if that assumption is wrong
|
|
492
|
+
// fallback to a big group
|
|
493
|
+
result.push(group);
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
left = best;
|
|
497
|
+
right = best - 1;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// create two new groups for left and right area
|
|
501
|
+
// and queue them up
|
|
502
|
+
/** @type {Node<T>[]} */
|
|
503
|
+
const rightNodes = [group.nodes[right + 1]];
|
|
504
|
+
/** @type {Similarities} */
|
|
505
|
+
const rightSimilarities = [];
|
|
506
|
+
for (let i = right + 2; i < group.nodes.length; i++) {
|
|
507
|
+
rightSimilarities.push(
|
|
508
|
+
/** @type {Similarities} */ (group.similarities)[i - 1]
|
|
509
|
+
);
|
|
510
|
+
rightNodes.push(group.nodes[i]);
|
|
511
|
+
}
|
|
512
|
+
queue.push(new Group(rightNodes, rightSimilarities));
|
|
513
|
+
|
|
514
|
+
/** @type {Node<T>[]} */
|
|
515
|
+
const leftNodes = [group.nodes[0]];
|
|
516
|
+
/** @type {Similarities} */
|
|
517
|
+
const leftSimilarities = [];
|
|
518
|
+
for (let i = 1; i < left; i++) {
|
|
519
|
+
leftSimilarities.push(
|
|
520
|
+
/** @type {Similarities} */ (group.similarities)[i - 1]
|
|
521
|
+
);
|
|
522
|
+
leftNodes.push(group.nodes[i]);
|
|
523
|
+
}
|
|
524
|
+
queue.push(new Group(leftNodes, leftSimilarities));
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// lexically ordering
|
|
530
|
+
result.sort((a, b) => {
|
|
531
|
+
if (a.nodes[0].key < b.nodes[0].key) return -1;
|
|
532
|
+
if (a.nodes[0].key > b.nodes[0].key) return 1;
|
|
533
|
+
return 0;
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
// give every group a name
|
|
537
|
+
/** @type {Set<string>} */
|
|
538
|
+
const usedNames = new Set();
|
|
539
|
+
for (let i = 0; i < result.length; i++) {
|
|
540
|
+
const group = result[i];
|
|
541
|
+
if (group.nodes.length === 1) {
|
|
542
|
+
group.key = group.nodes[0].key;
|
|
543
|
+
} else {
|
|
544
|
+
const first = group.nodes[0];
|
|
545
|
+
const last = group.nodes[group.nodes.length - 1];
|
|
546
|
+
const name = getName(first.key, last.key, usedNames);
|
|
547
|
+
group.key = name;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// return the results
|
|
552
|
+
return result.map(
|
|
553
|
+
(group) =>
|
|
554
|
+
/** @type {GroupedItems<T>} */
|
|
555
|
+
({
|
|
556
|
+
key: group.key,
|
|
557
|
+
items: group.nodes.map((node) => node.item),
|
|
558
|
+
size: group.size
|
|
559
|
+
})
|
|
560
|
+
);
|
|
561
|
+
};
|