webpack 5.104.1 → 5.105.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +17 -2
- package/lib/AsyncDependencyToInitialChunkError.js +3 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +5 -1
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +9 -5
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +9 -2
- package/lib/CleanPlugin.js +4 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +284 -236
- package/lib/Compiler.js +4 -3
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +248 -111
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +15 -8
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +8 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +17 -13
- package/lib/ExportsInfo.js +8 -4
- package/lib/ExternalModule.js +16 -0
- package/lib/ExternalModuleFactoryPlugin.js +9 -2
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/IgnoreWarningsPlugin.js +5 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +8 -1
- package/lib/Module.js +7 -4
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +4 -1
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -1
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +28 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +10 -0
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolPlugin.js +30 -23
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +3 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +61 -41
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +18 -3
- package/lib/asset/AssetModulesPlugin.js +33 -2
- package/lib/asset/AssetParser.js +4 -0
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryDependency.js +3 -0
- package/lib/container/ContainerEntryModule.js +7 -0
- package/lib/container/ContainerExposedDependency.js +1 -0
- package/lib/container/FallbackDependency.js +1 -0
- package/lib/container/FallbackItemDependency.js +1 -0
- package/lib/container/FallbackModule.js +4 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/ModuleFederationPlugin.js +1 -1
- package/lib/container/RemoteModule.js +24 -0
- package/lib/css/CssGenerator.js +31 -4
- package/lib/css/CssModulesPlugin.js +26 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +7 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependency.js +1 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +269 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +7 -12
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +3 -8
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/NamedChunkIdsPlugin.js +7 -5
- package/lib/ids/NamedModuleIdsPlugin.js +1 -0
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
- package/lib/ids/SyncModuleIdsPlugin.js +30 -20
- package/lib/index.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +29 -8
- package/lib/javascript/JavascriptParser.js +47 -14
- package/lib/json/JsonGenerator.js +1 -0
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/Logger.js +9 -5
- package/lib/logging/createConsoleLogger.js +4 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
- package/lib/node/NodeEnvironmentPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +10 -1
- package/lib/node/NodeTemplatePlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +6 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
- package/lib/optimize/ConcatenatedModule.js +33 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/LimitChunkCountPlugin.js +3 -2
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
- package/lib/optimize/RealContentHashPlugin.js +37 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/RuntimeChunkPlugin.js +3 -5
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +23 -5
- package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/performance/SizeLimitsPlugin.js +6 -6
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +6 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
- package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +39 -20
- package/lib/schemes/VirtualUrlPlugin.js +28 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +60 -0
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +5 -3
- package/lib/util/AppendOnlyStackedSet.js +57 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +4 -0
- package/lib/util/hash/BulkUpdateHash.js +8 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +18 -2
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +16 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
- package/package.json +33 -36
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +121 -55
- package/schemas/plugins/BannerPlugin.json +2 -2
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ManifestPlugin.json +3 -3
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +440 -137
|
@@ -64,6 +64,11 @@ const compileSearch = (funcName, predicate, reversed, extraArgs, earlyOut) => {
|
|
|
64
64
|
return code.join("");
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* @template T
|
|
69
|
+
* @typedef {(items: T[], start: number, compareFn?: number | ((item: T, needle: number) => number), l?: number, h?: number) => number} Search
|
|
70
|
+
*/
|
|
71
|
+
|
|
67
72
|
/**
|
|
68
73
|
* This helper functions generate code for two binary search functions:
|
|
69
74
|
* A(): Performs a binary search on an array using the comparison operator specified.
|
|
@@ -74,7 +79,7 @@ const compileSearch = (funcName, predicate, reversed, extraArgs, earlyOut) => {
|
|
|
74
79
|
* @param {boolean} reversed Whether the search should be reversed.
|
|
75
80
|
* @param {SearchPredicateSuffix} suffix The suffix to be used in the function name.
|
|
76
81
|
* @param {boolean=} earlyOut Whether the search should return as soon as a match is found.
|
|
77
|
-
* @returns {
|
|
82
|
+
* @returns {Search<T>} The compiled binary search function.
|
|
78
83
|
*/
|
|
79
84
|
const compileBoundsSearch = (predicate, reversed, suffix, earlyOut) => {
|
|
80
85
|
const arg1 = compileSearch("A", `x${predicate}y`, reversed, ["y"], earlyOut);
|
|
@@ -106,6 +111,14 @@ return dispatchBinarySearch";
|
|
|
106
111
|
return result();
|
|
107
112
|
};
|
|
108
113
|
|
|
114
|
+
const fns = {
|
|
115
|
+
ge: compileBoundsSearch(">=", false, "GE"),
|
|
116
|
+
gt: compileBoundsSearch(">", false, "GT"),
|
|
117
|
+
lt: compileBoundsSearch("<", true, "LT"),
|
|
118
|
+
le: compileBoundsSearch("<=", true, "LE"),
|
|
119
|
+
eq: compileBoundsSearch("-", true, "EQ", true)
|
|
120
|
+
};
|
|
121
|
+
|
|
109
122
|
/**
|
|
110
123
|
* These functions are used to perform binary searches on arrays.
|
|
111
124
|
* @example
|
|
@@ -120,10 +133,4 @@ return dispatchBinarySearch";
|
|
|
120
133
|
* const index2 = le(arr, 5); // index2 === 4
|
|
121
134
|
* ```
|
|
122
135
|
*/
|
|
123
|
-
module.exports =
|
|
124
|
-
ge: compileBoundsSearch(">=", false, "GE"),
|
|
125
|
-
gt: compileBoundsSearch(">", false, "GT"),
|
|
126
|
-
lt: compileBoundsSearch("<", true, "LT"),
|
|
127
|
-
le: compileBoundsSearch("<=", true, "LE"),
|
|
128
|
-
eq: compileBoundsSearch("-", true, "EQ", true)
|
|
129
|
-
};
|
|
136
|
+
module.exports = fns;
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* @param {IdRanges | undefined} ranges cumulative range of ids for each of allIds
|
|
24
24
|
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
25
25
|
* @param {Dependency} dependency dependency
|
|
26
|
-
* @returns {{trimmedIds: string[], trimmedRange: Range}} computed trimmed ids and cumulative range of those ids
|
|
26
|
+
* @returns {{ trimmedIds: string[], trimmedRange: Range }} computed trimmed ids and cumulative range of those ids
|
|
27
27
|
*/
|
|
28
28
|
module.exports.getTrimmedIdsAndRange = (
|
|
29
29
|
untrimmedIds,
|
package/lib/util/cleverMerge.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
/** @type {WeakMap<EXPECTED_OBJECT, WeakMap<EXPECTED_OBJECT, EXPECTED_OBJECT>>} */
|
|
9
9
|
const mergeCache = new WeakMap();
|
|
10
|
-
/** @
|
|
10
|
+
/** @typedef {Map<string, Map<string | number | boolean, EXPECTED_OBJECT>>} InnerPropertyCache */
|
|
11
|
+
/** @type {WeakMap<EXPECTED_OBJECT, InnerPropertyCache>} */
|
|
11
12
|
const setPropertyCache = new WeakMap();
|
|
12
13
|
const DELETE = Symbol("DELETE");
|
|
13
14
|
const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
|
|
@@ -406,6 +407,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
406
407
|
} else {
|
|
407
408
|
// = first.base + (first.byProperty + second.byProperty)
|
|
408
409
|
// need to merge first and second byValues
|
|
410
|
+
/** @type {Map<string, T & O>} */
|
|
409
411
|
const newByValues = new Map(firstEntry.byValues);
|
|
410
412
|
for (const [key, value] of /** @type {ByValues} */ (
|
|
411
413
|
secondEntry.byValues
|
|
@@ -444,7 +446,9 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
444
446
|
byValues: secondEntry.byValues
|
|
445
447
|
};
|
|
446
448
|
}
|
|
449
|
+
/** @type {O[keyof O] | T[keyof T] | (T[keyof T] & O[keyof O]) | (T[keyof T] | undefined)[] | (O[keyof O] | undefined)[] | (O[keyof O] | T[keyof T] | undefined)[] | undefined} */
|
|
447
450
|
let newBase;
|
|
451
|
+
/** @type {Map<string, (T & O) | O[keyof O] | (O[keyof O] | undefined)[] | ((T & O) | undefined)[] | (T & O & O[keyof O]) | ((T & O) | O[keyof O] | undefined)[] | undefined>} */
|
|
448
452
|
const intermediateByValues = new Map(firstEntry.byValues);
|
|
449
453
|
for (const [key, value] of intermediateByValues) {
|
|
450
454
|
intermediateByValues.set(
|
|
@@ -485,6 +489,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
485
489
|
`${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported`
|
|
486
490
|
);
|
|
487
491
|
}
|
|
492
|
+
/** @type {Map<string, (T & O) | O[keyof O] | (O[keyof O] | undefined)[] | (T & O & O[keyof O]) | ((T & O) | undefined)[] | ((T & O) | O[keyof O] | undefined)[] | undefined>} */
|
|
488
493
|
const newByValues = new Map(intermediateByValues);
|
|
489
494
|
for (const [key, value] of /** @type {ByValues} */ (
|
|
490
495
|
secondEntry.byValues
|
package/lib/util/comparators.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const { getFullModuleName } = require("../ids/IdHelpers");
|
|
8
9
|
const { compareRuntime } = require("./runtime");
|
|
9
10
|
|
|
10
11
|
/** @typedef {import("../Chunk")} Chunk */
|
|
@@ -13,6 +14,7 @@ const { compareRuntime } = require("./runtime");
|
|
|
13
14
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
14
15
|
/** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
|
|
15
16
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
|
17
|
+
/** @typedef {import("../Compiler")} Compiler */
|
|
16
18
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
|
17
19
|
/** @typedef {import("../Dependency")} Dependency */
|
|
18
20
|
/** @typedef {import("../dependencies/HarmonyImportSideEffectDependency")} HarmonyImportSideEffectDependency */
|
|
@@ -316,6 +318,19 @@ const compareModulesByIdOrIdentifier = (chunkGraph, a, b) => {
|
|
|
316
318
|
return compareIds(a.identifier(), b.identifier());
|
|
317
319
|
};
|
|
318
320
|
|
|
321
|
+
/**
|
|
322
|
+
* Compare modules by their full name. This differs from comparing by identifier in that the values have been normalized to be relative to the compiler context.
|
|
323
|
+
* @param {{ context: string, root: object }} compiler the compiler, used for context and cache
|
|
324
|
+
* @param {Module} a module
|
|
325
|
+
* @param {Module} b module
|
|
326
|
+
* @returns {-1 | 0 | 1} compare result
|
|
327
|
+
*/
|
|
328
|
+
const compareModulesByFullName = (compiler, a, b) => {
|
|
329
|
+
const aName = getFullModuleName(a, compiler.context, compiler.root);
|
|
330
|
+
const bName = getFullModuleName(b, compiler.context, compiler.root);
|
|
331
|
+
return compareIds(aName, bName);
|
|
332
|
+
};
|
|
333
|
+
|
|
319
334
|
/**
|
|
320
335
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
321
336
|
* @param {Chunk} a chunk
|
|
@@ -519,7 +534,7 @@ const sortWithSourceOrder = (
|
|
|
519
534
|
dependencySourceOrderMap,
|
|
520
535
|
onDependencyReSort
|
|
521
536
|
) => {
|
|
522
|
-
/** @type {{dep: Dependency, main: number, sub: number}[]} */
|
|
537
|
+
/** @type {{ dep: Dependency, main: number, sub: number }[]} */
|
|
523
538
|
const withSourceOrder = [];
|
|
524
539
|
/** @type {number[]} */
|
|
525
540
|
const positions = [];
|
|
@@ -590,6 +605,11 @@ module.exports.compareIterables = compareIterables;
|
|
|
590
605
|
|
|
591
606
|
module.exports.compareLocations = compareLocations;
|
|
592
607
|
|
|
608
|
+
/** @type {ParameterizedComparator<Compiler, Module>} */
|
|
609
|
+
module.exports.compareModulesByFullName = createCachedParameterizedComparator(
|
|
610
|
+
compareModulesByFullName
|
|
611
|
+
);
|
|
612
|
+
|
|
593
613
|
/** @type {ParameterizedComparator<ChunkGraph, Module>} */
|
|
594
614
|
module.exports.compareModulesById =
|
|
595
615
|
createCachedParameterizedComparator(compareModulesById);
|
|
@@ -252,10 +252,10 @@ const itemsToRegexp = (itemsArr) => {
|
|
|
252
252
|
|
|
253
253
|
// special case for 2 items with common suffix
|
|
254
254
|
if (finishedItems.length === 0 && items.size === 2) {
|
|
255
|
-
/** @type {
|
|
255
|
+
/** @type {SetIterator<string>} */
|
|
256
256
|
const it = items[Symbol.iterator]();
|
|
257
|
-
const a = it.next().value;
|
|
258
|
-
const b = it.next().value;
|
|
257
|
+
const a = /** @type {string} */ (it.next().value);
|
|
258
|
+
const b = /** @type {string} */ (it.next().value);
|
|
259
259
|
if (a.length > 0 && b.length > 0 && a.slice(-1) === b.slice(-1)) {
|
|
260
260
|
return `${itemsToRegexp([a.slice(0, -1), b.slice(0, -1)])}${quoteMeta(
|
|
261
261
|
a.slice(-1)
|
package/lib/util/concatenate.js
CHANGED
|
@@ -110,7 +110,7 @@ function findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
|
|
|
110
110
|
|
|
111
111
|
// Remove uncool stuff
|
|
112
112
|
extraInfo = extraInfo.replace(
|
|
113
|
-
/\.+\/|(
|
|
113
|
+
/\.+\/|(?:\/index)?\.[a-zA-Z0-9]{1,4}(?:$|\s|\?)|\s*\+\s*\d+\s*modules/g,
|
|
114
114
|
""
|
|
115
115
|
);
|
|
116
116
|
|
|
@@ -199,9 +199,10 @@ const RESERVED_NAMES = new Set(
|
|
|
199
199
|
);
|
|
200
200
|
|
|
201
201
|
/** @typedef {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} ScopeInfo */
|
|
202
|
+
/** @typedef {Map<string, ScopeInfo>} UsedNamesInScopeInfo */
|
|
202
203
|
|
|
203
204
|
/**
|
|
204
|
-
* @param {
|
|
205
|
+
* @param {UsedNamesInScopeInfo} usedNamesInScopeInfo used names in scope info
|
|
205
206
|
* @param {string} module module identifier
|
|
206
207
|
* @param {string} id export id
|
|
207
208
|
* @returns {ScopeInfo} info
|
package/lib/util/conventions.js
CHANGED
|
@@ -20,7 +20,7 @@ const preserveCamelCase = (string) => {
|
|
|
20
20
|
for (let i = 0; i < result.length; i++) {
|
|
21
21
|
const character = result[i];
|
|
22
22
|
|
|
23
|
-
if (isLastCharLower &&
|
|
23
|
+
if (isLastCharLower && /\p{Lu}/u.test(character)) {
|
|
24
24
|
result = `${result.slice(0, i)}-${result.slice(i)}`;
|
|
25
25
|
isLastCharLower = false;
|
|
26
26
|
isLastLastCharUpper = isLastCharUpper;
|
|
@@ -29,7 +29,7 @@ const preserveCamelCase = (string) => {
|
|
|
29
29
|
} else if (
|
|
30
30
|
isLastCharUpper &&
|
|
31
31
|
isLastLastCharUpper &&
|
|
32
|
-
|
|
32
|
+
/\p{Ll}/u.test(character)
|
|
33
33
|
) {
|
|
34
34
|
result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`;
|
|
35
35
|
isLastLastCharUpper = isLastCharUpper;
|
|
@@ -84,6 +84,7 @@ module.exports.camelCase = (input) => {
|
|
|
84
84
|
* @returns {string[]} results
|
|
85
85
|
*/
|
|
86
86
|
module.exports.cssExportConvention = (input, convention) => {
|
|
87
|
+
/** @type {Set<string>} */
|
|
87
88
|
const set = new Set();
|
|
88
89
|
if (typeof convention === "function") {
|
|
89
90
|
set.add(convention(input));
|
|
@@ -100,6 +100,7 @@ const subtractSizeFrom = (total, size) => {
|
|
|
100
100
|
* @returns {Sizes} total size
|
|
101
101
|
*/
|
|
102
102
|
const sumSize = (nodes) => {
|
|
103
|
+
/** @type {Sizes} */
|
|
103
104
|
const sum = Object.create(null);
|
|
104
105
|
for (const node of nodes) {
|
|
105
106
|
addSizeTo(sum, node.size);
|
|
@@ -145,7 +146,7 @@ const isTooSmall = (size, minSize) => {
|
|
|
145
146
|
* @returns {Types} set of types that are too small
|
|
146
147
|
*/
|
|
147
148
|
const getTooSmallTypes = (size, minSize) => {
|
|
148
|
-
/** @
|
|
149
|
+
/** @type {Types} */
|
|
149
150
|
const types = new Set();
|
|
150
151
|
for (const key of Object.keys(size)) {
|
|
151
152
|
const s = size[key];
|
|
@@ -223,9 +224,13 @@ class Group {
|
|
|
223
224
|
* @returns {Node<T>[] | undefined} removed nodes
|
|
224
225
|
*/
|
|
225
226
|
popNodes(filter) {
|
|
227
|
+
/** @type {Node<T>[]} */
|
|
226
228
|
const newNodes = [];
|
|
229
|
+
/** @type {Similarities} */
|
|
227
230
|
const newSimilarities = [];
|
|
231
|
+
/** @type {Node<T>[]} */
|
|
228
232
|
const resultNodes = [];
|
|
233
|
+
/** @type {undefined | Node<T>} */
|
|
229
234
|
let lastNode;
|
|
230
235
|
for (let i = 0; i < this.nodes.length; i++) {
|
|
231
236
|
const node = this.nodes[i];
|
|
@@ -260,6 +265,7 @@ const getSimilarities = (nodes) => {
|
|
|
260
265
|
// calculate similarities between lexically adjacent nodes
|
|
261
266
|
/** @type {Similarities} */
|
|
262
267
|
const similarities = [];
|
|
268
|
+
/** @type {undefined | Node<T>} */
|
|
263
269
|
let last;
|
|
264
270
|
for (const node of nodes) {
|
|
265
271
|
if (last !== undefined) {
|
|
@@ -399,6 +405,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
399
405
|
// going minSize from left and right
|
|
400
406
|
// at least one node need to be included otherwise we get stuck
|
|
401
407
|
let left = 1;
|
|
408
|
+
/** @type {Sizes} */
|
|
402
409
|
const leftSize = Object.create(null);
|
|
403
410
|
addSizeTo(leftSize, group.nodes[0].size);
|
|
404
411
|
while (left < group.nodes.length && isTooSmall(leftSize, minSize)) {
|
|
@@ -406,6 +413,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
406
413
|
left++;
|
|
407
414
|
}
|
|
408
415
|
let right = group.nodes.length - 2;
|
|
416
|
+
/** @type {Sizes} */
|
|
409
417
|
const rightSize = Object.create(null);
|
|
410
418
|
addSizeTo(rightSize, group.nodes[group.nodes.length - 1].size);
|
|
411
419
|
while (right >= 0 && isTooSmall(rightSize, minSize)) {
|
|
@@ -425,6 +433,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
425
433
|
|
|
426
434
|
if (left - 1 > right) {
|
|
427
435
|
// We try to remove some problematic nodes to "fix" that
|
|
436
|
+
/** @type {Sizes} */
|
|
428
437
|
let prevSize;
|
|
429
438
|
if (right < group.nodes.length - left) {
|
|
430
439
|
subtractSizeFrom(rightSize, group.nodes[right + 1].size);
|
|
@@ -490,6 +499,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
490
499
|
|
|
491
500
|
// create two new groups for left and right area
|
|
492
501
|
// and queue them up
|
|
502
|
+
/** @type {Node<T>[]} */
|
|
493
503
|
const rightNodes = [group.nodes[right + 1]];
|
|
494
504
|
/** @type {Similarities} */
|
|
495
505
|
const rightSimilarities = [];
|
|
@@ -501,6 +511,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
501
511
|
}
|
|
502
512
|
queue.push(new Group(rightNodes, rightSimilarities));
|
|
503
513
|
|
|
514
|
+
/** @type {Node<T>[]} */
|
|
504
515
|
const leftNodes = [group.nodes[0]];
|
|
505
516
|
/** @type {Similarities} */
|
|
506
517
|
const leftSimilarities = [];
|
|
@@ -523,6 +534,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
523
534
|
});
|
|
524
535
|
|
|
525
536
|
// give every group a name
|
|
537
|
+
/** @type {Set<string>} */
|
|
526
538
|
const usedNames = new Set();
|
|
527
539
|
for (let i = 0; i < result.length; i++) {
|
|
528
540
|
const group = result[i];
|
|
@@ -10,16 +10,10 @@ const urlUtils = require("url");
|
|
|
10
10
|
const { isAbsolute, join } = require("./fs");
|
|
11
11
|
|
|
12
12
|
/** @typedef {import("./fs").InputFileSystem} InputFileSystem */
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {(input: string | Buffer<ArrayBufferLike>, resourcePath: string, fs: InputFileSystem) => Promise<{source: string | Buffer<ArrayBufferLike>, sourceMap: string | RawSourceMap | undefined, fileDependencies: string[]}>} SourceMapExtractorFunction
|
|
16
|
-
*/
|
|
17
|
-
|
|
13
|
+
/** @typedef {string | Buffer<ArrayBufferLike>} StringOrBuffer */
|
|
14
|
+
/** @typedef {(input: StringOrBuffer, resourcePath: string, fs: InputFileSystem) => Promise<{ source: StringOrBuffer, sourceMap: string | RawSourceMap | undefined, fileDependencies: string[] }>} SourceMapExtractorFunction */
|
|
18
15
|
/** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {(resourcePath: string) => Promise<string | Buffer<ArrayBufferLike>>} ReadResource
|
|
22
|
-
*/
|
|
16
|
+
/** @typedef {(resourcePath: string) => Promise<StringOrBuffer>} ReadResource */
|
|
23
17
|
|
|
24
18
|
/**
|
|
25
19
|
* @typedef {object} SourceMappingURL
|
|
@@ -52,6 +46,7 @@ const sourceMappingURLRegex = new RegExp(
|
|
|
52
46
|
*/
|
|
53
47
|
function getSourceMappingURL(code) {
|
|
54
48
|
const lines = code.split(/^/m);
|
|
49
|
+
/** @type {RegExpMatchArray | null | undefined} */
|
|
55
50
|
let match;
|
|
56
51
|
|
|
57
52
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
@@ -104,13 +99,14 @@ function isURL(value) {
|
|
|
104
99
|
* @param {ReadResource} readResource read resource function
|
|
105
100
|
* @param {string[]} possibleRequests array of possible file paths
|
|
106
101
|
* @param {string} errorsAccumulator accumulated error messages
|
|
107
|
-
* @returns {Promise<{path: string, data?: string}>} source content promise
|
|
102
|
+
* @returns {Promise<{ path: string, data?: string }>} source content promise
|
|
108
103
|
*/
|
|
109
104
|
async function fetchPathsFromURL(
|
|
110
105
|
readResource,
|
|
111
106
|
possibleRequests,
|
|
112
107
|
errorsAccumulator = ""
|
|
113
108
|
) {
|
|
109
|
+
/** @type {StringOrBuffer} */
|
|
114
110
|
let result;
|
|
115
111
|
|
|
116
112
|
try {
|
|
@@ -146,7 +142,7 @@ async function fetchPathsFromURL(
|
|
|
146
142
|
* @param {string} url source URL
|
|
147
143
|
* @param {string=} sourceRoot source root directory
|
|
148
144
|
* @param {boolean=} skipReading whether to skip reading file content
|
|
149
|
-
* @returns {Promise<{sourceURL: string, sourceContent?:
|
|
145
|
+
* @returns {Promise<{ sourceURL: string, sourceContent?: StringOrBuffer }>} source content promise
|
|
150
146
|
*/
|
|
151
147
|
async function fetchFromURL(
|
|
152
148
|
readResource,
|
|
@@ -181,9 +177,11 @@ async function fetchFromURL(
|
|
|
181
177
|
if (isAbsolute(url)) {
|
|
182
178
|
let sourceURL = path.normalize(url);
|
|
183
179
|
|
|
180
|
+
/** @type {undefined | StringOrBuffer} */
|
|
184
181
|
let sourceContent;
|
|
185
182
|
|
|
186
183
|
if (!skipReading) {
|
|
184
|
+
/** @type {string[]} */
|
|
187
185
|
const possibleRequests = [sourceURL];
|
|
188
186
|
|
|
189
187
|
if (url.startsWith("/")) {
|
|
@@ -203,6 +201,7 @@ async function fetchFromURL(
|
|
|
203
201
|
|
|
204
202
|
// 4. Relative path
|
|
205
203
|
const sourceURL = getAbsolutePath(context, url, sourceRoot || "");
|
|
204
|
+
/** @type {undefined | StringOrBuffer} */
|
|
206
205
|
let sourceContent;
|
|
207
206
|
|
|
208
207
|
if (!skipReading) {
|
|
@@ -214,10 +213,10 @@ async function fetchFromURL(
|
|
|
214
213
|
|
|
215
214
|
/**
|
|
216
215
|
* Extract source map from code content
|
|
217
|
-
* @param {
|
|
216
|
+
* @param {StringOrBuffer} stringOrBuffer The input code content as string or buffer
|
|
218
217
|
* @param {string} resourcePath The path to the resource file
|
|
219
218
|
* @param {ReadResource} readResource The read resource function
|
|
220
|
-
* @returns {Promise<{source:
|
|
219
|
+
* @returns {Promise<{ source: StringOrBuffer, sourceMap: string | RawSourceMap | undefined }>} Promise resolving to extracted source map information
|
|
221
220
|
*/
|
|
222
221
|
async function extractSourceMap(stringOrBuffer, resourcePath, readResource) {
|
|
223
222
|
const input =
|
package/lib/util/fs.js
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
const path = require("path");
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("../../declarations/WebpackOptions").WatchOptions} WatchOptions */
|
|
11
|
-
/** @typedef {import("
|
|
11
|
+
/** @typedef {import("watchpack").Entry} Entry */
|
|
12
|
+
/** @typedef {import("watchpack").OnlySafeTimeEntry} OnlySafeTimeEntry */
|
|
13
|
+
/** @typedef {import("watchpack").ExistenceOnlyTimeEntry} ExistenceOnlyTimeEntry */
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @template T
|
|
@@ -83,7 +85,7 @@ const path = require("path");
|
|
|
83
85
|
/** @typedef {(err: NodeJS.ErrnoException | null, result?: number) => void} NumberCallback */
|
|
84
86
|
/** @typedef {(err: NodeJS.ErrnoException | Error | null, result?: JsonObject) => void} ReadJsonCallback */
|
|
85
87
|
|
|
86
|
-
/** @typedef {Map<string,
|
|
88
|
+
/** @typedef {Map<string, Entry | OnlySafeTimeEntry | ExistenceOnlyTimeEntry | null | "ignore">} TimeInfoEntries */
|
|
87
89
|
|
|
88
90
|
/** @typedef {Set<string>} Changes */
|
|
89
91
|
/** @typedef {Set<string>} Removals */
|
|
@@ -201,7 +203,7 @@ const path = require("path");
|
|
|
201
203
|
|
|
202
204
|
/**
|
|
203
205
|
* @typedef {{
|
|
204
|
-
* (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined
|
|
206
|
+
* (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | null): string[],
|
|
205
207
|
* (path: PathLike, options: { encoding: "buffer", withFileTypes?: false | undefined, recursive?: boolean | undefined } | "buffer"): Buffer[],
|
|
206
208
|
* (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[],
|
|
207
209
|
* (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[],
|
|
@@ -225,8 +227,8 @@ const path = require("path");
|
|
|
225
227
|
* (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined,
|
|
226
228
|
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats,
|
|
227
229
|
* (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats,
|
|
228
|
-
* (path: PathLike,
|
|
229
|
-
* (path: PathLike,
|
|
230
|
+
* (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
|
|
231
|
+
* (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
|
|
230
232
|
* }} StatSync
|
|
231
233
|
*/
|
|
232
234
|
|
|
@@ -246,8 +248,8 @@ const path = require("path");
|
|
|
246
248
|
* (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined,
|
|
247
249
|
* (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats,
|
|
248
250
|
* (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats,
|
|
249
|
-
* (path: PathLike,
|
|
250
|
-
* (path: PathLike,
|
|
251
|
+
* (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
|
|
252
|
+
* (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
|
|
251
253
|
* }} LStatSync
|
|
252
254
|
*/
|
|
253
255
|
|
|
@@ -256,7 +258,7 @@ const path = require("path");
|
|
|
256
258
|
* (path: PathLike, options: EncodingOption, callback: StringCallback): void,
|
|
257
259
|
* (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void,
|
|
258
260
|
* (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void,
|
|
259
|
-
* (path: PathLike, callback: StringCallback): void
|
|
261
|
+
* (path: PathLike, callback: StringCallback): void,
|
|
260
262
|
* }} RealPath
|
|
261
263
|
*/
|
|
262
264
|
|
|
@@ -324,21 +326,14 @@ const path = require("path");
|
|
|
324
326
|
/**
|
|
325
327
|
* @typedef {{
|
|
326
328
|
* (file: PathLike, options: MakeDirectoryOptions & { recursive: true }, callback: StringCallback): void,
|
|
327
|
-
* (file: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false | undefined
|
|
329
|
+
* (file: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false | undefined }) | null | undefined, callback: NoParamCallback): void,
|
|
328
330
|
* (file: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: StringCallback): void,
|
|
329
331
|
* (file: PathLike, callback: NoParamCallback): void,
|
|
330
332
|
* }} Mkdir
|
|
331
333
|
*/
|
|
332
334
|
|
|
333
335
|
/**
|
|
334
|
-
* @typedef {{
|
|
335
|
-
*/
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* @typedef {{
|
|
339
|
-
* (file: PathLike, callback: NoParamCallback): void,
|
|
340
|
-
* (file: PathLike, options: RmDirOptions, callback: NoParamCallback): void,
|
|
341
|
-
* }} Rmdir
|
|
336
|
+
* @typedef {{ (file: PathLike, callback: NoParamCallback): void }} Rmdir
|
|
342
337
|
*/
|
|
343
338
|
|
|
344
339
|
/**
|
|
@@ -405,7 +400,7 @@ const path = require("path");
|
|
|
405
400
|
*/
|
|
406
401
|
|
|
407
402
|
/**
|
|
408
|
-
* @typedef {FSImplementation & { write: (...args: EXPECTED_ANY[]) => EXPECTED_ANY
|
|
403
|
+
* @typedef {FSImplementation & { write: (...args: EXPECTED_ANY[]) => EXPECTED_ANY, close?: (...args: EXPECTED_ANY[]) => EXPECTED_ANY }} CreateWriteStreamFSImplementation
|
|
409
404
|
*/
|
|
410
405
|
|
|
411
406
|
/**
|
|
@@ -422,7 +417,7 @@ const path = require("path");
|
|
|
422
417
|
|
|
423
418
|
/**
|
|
424
419
|
* @typedef {{
|
|
425
|
-
* (file: PathLike, flags: OpenMode | undefined,
|
|
420
|
+
* (file: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: NumberCallback): void,
|
|
426
421
|
* (file: PathLike, flags: OpenMode | undefined, callback: NumberCallback): void,
|
|
427
422
|
* (file: PathLike, callback: NumberCallback): void,
|
|
428
423
|
* }} Open
|
|
@@ -613,6 +608,7 @@ const readJson = (fs, p, callback) => {
|
|
|
613
608
|
}
|
|
614
609
|
fs.readFile(p, (err, buf) => {
|
|
615
610
|
if (err) return callback(err);
|
|
611
|
+
/** @type {JsonObject} */
|
|
616
612
|
let data;
|
|
617
613
|
try {
|
|
618
614
|
data = JSON.parse(/** @type {Buffer} */ (buf).toString("utf8"));
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const Hash = require("../Hash");
|
|
9
9
|
const { digest, update } = require("./hash-digest");
|
|
10
|
+
/** @type {number} */
|
|
10
11
|
const MAX_SHORT_STRING = require("./wasm-hash").MAX_SHORT_STRING;
|
|
11
12
|
|
|
12
13
|
/** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
|
|
@@ -17,8 +18,11 @@ class BatchedHash extends Hash {
|
|
|
17
18
|
*/
|
|
18
19
|
constructor(hash) {
|
|
19
20
|
super();
|
|
21
|
+
/** @type {undefined | string} */
|
|
20
22
|
this.string = undefined;
|
|
23
|
+
/** @type {undefined | Encoding} */
|
|
21
24
|
this.encoding = undefined;
|
|
25
|
+
/** @type {Hash} */
|
|
22
26
|
this.hash = hash;
|
|
23
27
|
}
|
|
24
28
|
|
|
@@ -15,7 +15,7 @@ const BULK_SIZE = 3;
|
|
|
15
15
|
|
|
16
16
|
// We are using an object instead of a Map as this will stay static during the runtime
|
|
17
17
|
// so access to it can be optimized by v8
|
|
18
|
-
/** @type {{[key: string]: Map<string, string>}} */
|
|
18
|
+
/** @type {{ [key: string]: Map<string, string> }} */
|
|
19
19
|
const digestCaches = {};
|
|
20
20
|
|
|
21
21
|
class BulkUpdateHash extends Hash {
|
|
@@ -25,14 +25,20 @@ class BulkUpdateHash extends Hash {
|
|
|
25
25
|
*/
|
|
26
26
|
constructor(hashOrFactory, hashKey) {
|
|
27
27
|
super();
|
|
28
|
+
/** @type {undefined | string} */
|
|
28
29
|
this.hashKey = hashKey;
|
|
29
30
|
if (typeof hashOrFactory === "function") {
|
|
31
|
+
/** @type {undefined | HashFactory} */
|
|
30
32
|
this.hashFactory = hashOrFactory;
|
|
33
|
+
/** @type {undefined | Hash} */
|
|
31
34
|
this.hash = undefined;
|
|
32
35
|
} else {
|
|
36
|
+
/** @type {undefined | HashFactory} */
|
|
33
37
|
this.hashFactory = undefined;
|
|
38
|
+
/** @type {undefined | Hash} */
|
|
34
39
|
this.hash = hashOrFactory;
|
|
35
40
|
}
|
|
41
|
+
/** @type {string} */
|
|
36
42
|
this.buffer = "";
|
|
37
43
|
}
|
|
38
44
|
|
|
@@ -103,6 +109,7 @@ class BulkUpdateHash extends Hash {
|
|
|
103
109
|
* @returns {string | Buffer} digest
|
|
104
110
|
*/
|
|
105
111
|
digest(encoding) {
|
|
112
|
+
/** @type {undefined | Map<string, string | Buffer>} */
|
|
106
113
|
let digestCache;
|
|
107
114
|
const buffer = this.buffer;
|
|
108
115
|
if (this.hash === undefined) {
|
|
@@ -49,6 +49,7 @@ const encode = (buffer, base) => {
|
|
|
49
49
|
value = (value << EIGHT) | BigInt(buffer[i]);
|
|
50
50
|
}
|
|
51
51
|
// Convert to baseX string efficiently using array
|
|
52
|
+
/** @type {string[]} */
|
|
52
53
|
const digits = [];
|
|
53
54
|
if (value === ZERO) return ENCODE_TABLE[base][0];
|
|
54
55
|
while (value > ZERO) {
|
|
@@ -13,6 +13,14 @@ const Hash = require("../Hash");
|
|
|
13
13
|
// ~3 makes sure that it's always a block of 4 chars, so avoid partially encoded bytes for base64
|
|
14
14
|
const MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & ~3;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} WasmExports
|
|
18
|
+
* @property {WebAssembly.Memory} memory
|
|
19
|
+
* @property {() => void} init
|
|
20
|
+
* @property {(length: number) => void} update
|
|
21
|
+
* @property {(length: number) => void} final
|
|
22
|
+
*/
|
|
23
|
+
|
|
16
24
|
class WasmHash extends Hash {
|
|
17
25
|
/**
|
|
18
26
|
* @param {WebAssembly.Instance} instance wasm instance
|
|
@@ -23,13 +31,19 @@ class WasmHash extends Hash {
|
|
|
23
31
|
constructor(instance, instancesPool, chunkSize, digestSize) {
|
|
24
32
|
super();
|
|
25
33
|
|
|
26
|
-
const exports = /** @type {
|
|
34
|
+
const exports = /** @type {WasmExports} */ (instance.exports);
|
|
27
35
|
exports.init();
|
|
36
|
+
/** @type {WasmExports} */
|
|
28
37
|
this.exports = exports;
|
|
38
|
+
/** @type {Buffer} */
|
|
29
39
|
this.mem = Buffer.from(exports.memory.buffer, 0, 65536);
|
|
40
|
+
/** @type {number} */
|
|
30
41
|
this.buffered = 0;
|
|
42
|
+
/** @type {WebAssembly.Instance[]} */
|
|
31
43
|
this.instancesPool = instancesPool;
|
|
44
|
+
/** @type {number} */
|
|
32
45
|
this.chunkSize = chunkSize;
|
|
46
|
+
/** @type {number} */
|
|
33
47
|
this.digestSize = digestSize;
|
|
34
48
|
}
|
|
35
49
|
|
|
@@ -85,6 +99,7 @@ class WasmHash extends Hash {
|
|
|
85
99
|
*/
|
|
86
100
|
_updateWithShortString(data, encoding) {
|
|
87
101
|
const { exports, buffered, mem, chunkSize } = this;
|
|
102
|
+
/** @type {number} */
|
|
88
103
|
let endPos;
|
|
89
104
|
if (data.length < 70) {
|
|
90
105
|
// eslint-disable-next-line unicorn/text-encoding-identifier-case
|
|
@@ -212,5 +227,6 @@ const create = (wasmModule, instancesPool, chunkSize, digestSize) => {
|
|
|
212
227
|
);
|
|
213
228
|
};
|
|
214
229
|
|
|
230
|
+
create.MAX_SHORT_STRING = MAX_SHORT_STRING;
|
|
231
|
+
|
|
215
232
|
module.exports = create;
|
|
216
|
-
module.exports.MAX_SHORT_STRING = MAX_SHORT_STRING;
|
package/lib/util/identifier.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
const path = require("path");
|
|
8
8
|
|
|
9
|
-
const WINDOWS_ABS_PATH_REGEXP = /^[a-
|
|
9
|
+
const WINDOWS_ABS_PATH_REGEXP = /^[a-z]:[\\/]/i;
|
|
10
10
|
const SEGMENTS_SPLIT_REGEXP = /([|!])/;
|
|
11
11
|
const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
|
|
12
12
|
|
|
@@ -165,7 +165,8 @@ const makeCacheable = (realFn) => {
|
|
|
165
165
|
* @returns {MakeCacheableWithContextResult & { bindCache: BindCacheForContext, bindContextCache: BindContextCacheForContext }} cacheable function with context
|
|
166
166
|
*/
|
|
167
167
|
const makeCacheableWithContext = (fn) => {
|
|
168
|
-
/** @
|
|
168
|
+
/** @typedef {Map<string, Map<string, string>>} InnerCache */
|
|
169
|
+
/** @type {WeakMap<AssociatedObjectForCache, InnerCache>} */
|
|
169
170
|
const cache = new WeakMap();
|
|
170
171
|
|
|
171
172
|
/** @type {MakeCacheableWithContextResult & { bindCache: BindCacheForContext, bindContextCache: BindContextCacheForContext }} */
|
|
@@ -178,6 +179,7 @@ const makeCacheableWithContext = (fn) => {
|
|
|
178
179
|
cache.set(associatedObjectForCache, innerCache);
|
|
179
180
|
}
|
|
180
181
|
|
|
182
|
+
/** @type {undefined | string} */
|
|
181
183
|
let cachedResult;
|
|
182
184
|
let innerSubCache = innerCache.get(context);
|
|
183
185
|
if (innerSubCache === undefined) {
|
|
@@ -196,6 +198,7 @@ const makeCacheableWithContext = (fn) => {
|
|
|
196
198
|
|
|
197
199
|
/** @type {BindCacheForContext} */
|
|
198
200
|
cachedFn.bindCache = (associatedObjectForCache) => {
|
|
201
|
+
/** @type {undefined | InnerCache} */
|
|
199
202
|
let innerCache;
|
|
200
203
|
if (associatedObjectForCache) {
|
|
201
204
|
innerCache = cache.get(associatedObjectForCache);
|
|
@@ -213,6 +216,7 @@ const makeCacheableWithContext = (fn) => {
|
|
|
213
216
|
* @returns {string} the returned relative path
|
|
214
217
|
*/
|
|
215
218
|
const boundFn = (context, identifier) => {
|
|
219
|
+
/** @type {undefined | string} */
|
|
216
220
|
let cachedResult;
|
|
217
221
|
let innerSubCache = innerCache.get(context);
|
|
218
222
|
if (innerSubCache === undefined) {
|
|
@@ -234,6 +238,7 @@ const makeCacheableWithContext = (fn) => {
|
|
|
234
238
|
|
|
235
239
|
/** @type {BindContextCacheForContext} */
|
|
236
240
|
cachedFn.bindContextCache = (context, associatedObjectForCache) => {
|
|
241
|
+
/** @type {undefined | Map<string, string>} */
|
|
237
242
|
let innerSubCache;
|
|
238
243
|
if (associatedObjectForCache) {
|
|
239
244
|
let innerCache = cache.get(associatedObjectForCache);
|
package/lib/util/magicComment.js
CHANGED
|
@@ -16,7 +16,7 @@ module.exports.createMagicCommentContext = () =>
|
|
|
16
16
|
codeGeneration: { strings: false, wasm: false }
|
|
17
17
|
});
|
|
18
18
|
module.exports.webpackCommentRegExp = new RegExp(
|
|
19
|
-
/(^|\W)webpack[A-Z]
|
|
19
|
+
/(^|\W)webpack[A-Z][A-Za-z]+:/
|
|
20
20
|
);
|
|
21
21
|
|
|
22
22
|
// regexp to match at least one "magic comment"
|