webpack 5.90.3 → 5.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -5
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +14 -6
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +8 -2
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +52 -25
- package/lib/ChunkGroup.js +23 -17
- package/lib/CleanPlugin.js +8 -6
- package/lib/Compilation.js +295 -120
- package/lib/Compiler.js +223 -87
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +95 -41
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +18 -6
- package/lib/Dependency.js +12 -10
- package/lib/DependencyTemplate.js +17 -7
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +7 -3
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +23 -8
- package/lib/ExternalModule.js +160 -35
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +69 -42
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +4 -4
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +17 -9
- package/lib/Module.js +41 -14
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +30 -17
- package/lib/ModuleGraph.js +60 -31
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +62 -9
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +13 -13
- package/lib/NormalModuleFactory.js +18 -9
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +6 -4
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +124 -52
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +11 -4
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +48 -7
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +120 -67
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +51 -18
- package/lib/cache/ResolverCachePlugin.js +22 -14
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +108 -34
- package/lib/config/normalization.js +3 -1
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +68 -25
- package/lib/css/CssGenerator.js +34 -6
- package/lib/css/CssLoadingRuntimeModule.js +217 -98
- package/lib/css/CssModulesPlugin.js +238 -107
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +28 -3
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
- package/lib/dependencies/CssUrlDependency.js +10 -7
- package/lib/dependencies/ExportsInfoDependency.js +5 -4
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +15 -5
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +64 -47
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +204 -71
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +13 -9
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -121
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +8 -3
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
- package/lib/optimize/SplitChunksPlugin.js +10 -10
- package/lib/performance/SizeLimitsPlugin.js +13 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +4 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +8 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +19 -0
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +13 -6
- package/lib/sharing/resolveMatchedConfigs.js +3 -3
- package/lib/sharing/utils.js +13 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +26 -13
- package/lib/util/comparators.js +37 -15
- package/lib/util/conventions.js +129 -0
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +383 -69
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
- package/lib/webpack.js +19 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +40 -39
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +97 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1826 -639
package/lib/util/comparators.js
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
const { compareRuntime } = require("./runtime");
|
9
9
|
|
10
10
|
/** @typedef {import("../Chunk")} Chunk */
|
11
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
11
12
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
12
13
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
13
14
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
@@ -46,7 +47,10 @@ const createCachedParameterizedComparator = fn => {
|
|
46
47
|
* @returns {-1|0|1} compare result
|
47
48
|
*/
|
48
49
|
exports.compareChunksById = (a, b) => {
|
49
|
-
return compareIds(
|
50
|
+
return compareIds(
|
51
|
+
/** @type {ChunkId} */ (a.id),
|
52
|
+
/** @type {ChunkId} */ (b.id)
|
53
|
+
);
|
50
54
|
};
|
51
55
|
|
52
56
|
/**
|
@@ -166,8 +170,8 @@ exports.compareStringsNumeric = compareStringsNumeric;
|
|
166
170
|
*/
|
167
171
|
const compareModulesByPostOrderIndexOrIdentifier = (moduleGraph, a, b) => {
|
168
172
|
const cmp = compareNumbers(
|
169
|
-
moduleGraph.getPostOrderIndex(a),
|
170
|
-
moduleGraph.getPostOrderIndex(b)
|
173
|
+
/** @type {number} */ (moduleGraph.getPostOrderIndex(a)),
|
174
|
+
/** @type {number} */ (moduleGraph.getPostOrderIndex(b))
|
171
175
|
);
|
172
176
|
if (cmp !== 0) return cmp;
|
173
177
|
return compareIds(a.identifier(), b.identifier());
|
@@ -186,8 +190,8 @@ exports.compareModulesByPostOrderIndexOrIdentifier =
|
|
186
190
|
*/
|
187
191
|
const compareModulesByPreOrderIndexOrIdentifier = (moduleGraph, a, b) => {
|
188
192
|
const cmp = compareNumbers(
|
189
|
-
moduleGraph.getPreOrderIndex(a),
|
190
|
-
moduleGraph.getPreOrderIndex(b)
|
193
|
+
/** @type {number} */ (moduleGraph.getPreOrderIndex(a)),
|
194
|
+
/** @type {number} */ (moduleGraph.getPreOrderIndex(b))
|
191
195
|
);
|
192
196
|
if (cmp !== 0) return cmp;
|
193
197
|
return compareIds(a.identifier(), b.identifier());
|
@@ -261,7 +265,9 @@ exports.compareStrings = compareStrings;
|
|
261
265
|
* @returns {-1|0|1} compare result
|
262
266
|
*/
|
263
267
|
const compareChunkGroupsByIndex = (a, b) => {
|
264
|
-
return a.index <
|
268
|
+
return /** @type {number} */ (a.index) < /** @type {number} */ (b.index)
|
269
|
+
? -1
|
270
|
+
: 1;
|
265
271
|
};
|
266
272
|
|
267
273
|
exports.compareChunkGroupsByIndex = compareChunkGroupsByIndex;
|
@@ -273,7 +279,10 @@ exports.compareChunkGroupsByIndex = compareChunkGroupsByIndex;
|
|
273
279
|
*/
|
274
280
|
class TwoKeyWeakMap {
|
275
281
|
constructor() {
|
276
|
-
/**
|
282
|
+
/**
|
283
|
+
* @private
|
284
|
+
* @type {WeakMap<any, WeakMap<any, T | undefined>>}
|
285
|
+
*/
|
277
286
|
this._map = new WeakMap();
|
278
287
|
}
|
279
288
|
|
@@ -340,7 +349,10 @@ const concatComparators = (c1, c2, ...cRest) => {
|
|
340
349
|
};
|
341
350
|
exports.concatComparators = concatComparators;
|
342
351
|
|
343
|
-
/**
|
352
|
+
/**
|
353
|
+
* @template A, B
|
354
|
+
* @typedef {(input: A) => B | undefined | null} Selector
|
355
|
+
*/
|
344
356
|
|
345
357
|
/** @type {TwoKeyWeakMap<Selector<any, any>, Comparator<any>, Comparator<any>>}} */
|
346
358
|
const compareSelectCache = new TwoKeyWeakMap();
|
@@ -399,7 +411,6 @@ const compareIterables = elementComparator => {
|
|
399
411
|
const result = (a, b) => {
|
400
412
|
const aI = a[Symbol.iterator]();
|
401
413
|
const bI = b[Symbol.iterator]();
|
402
|
-
// eslint-disable-next-line no-constant-condition
|
403
414
|
while (true) {
|
404
415
|
const aItem = aI.next();
|
405
416
|
const bItem = bI.next();
|
@@ -431,7 +442,11 @@ exports.keepOriginalOrder = iterable => {
|
|
431
442
|
for (const item of iterable) {
|
432
443
|
map.set(item, i++);
|
433
444
|
}
|
434
|
-
return (a, b) =>
|
445
|
+
return (a, b) =>
|
446
|
+
compareNumbers(
|
447
|
+
/** @type {number} */ (map.get(a)),
|
448
|
+
/** @type {number} */ (map.get(b))
|
449
|
+
);
|
435
450
|
};
|
436
451
|
|
437
452
|
/**
|
@@ -442,7 +457,10 @@ exports.compareChunksNatural = chunkGraph => {
|
|
442
457
|
const cmpFn = exports.compareModulesById(chunkGraph);
|
443
458
|
const cmpIterableFn = compareIterables(cmpFn);
|
444
459
|
return concatComparators(
|
445
|
-
compareSelect(
|
460
|
+
compareSelect(
|
461
|
+
chunk => /** @type {string|number} */ (chunk.name),
|
462
|
+
compareIds
|
463
|
+
),
|
446
464
|
compareSelect(chunk => chunk.runtime, compareRuntime),
|
447
465
|
compareSelect(
|
448
466
|
/**
|
@@ -475,8 +493,10 @@ exports.compareLocations = (a, b) => {
|
|
475
493
|
const bp = b.start;
|
476
494
|
if (ap.line < bp.line) return -1;
|
477
495
|
if (ap.line > bp.line) return 1;
|
478
|
-
if (ap.column < bp.column)
|
479
|
-
|
496
|
+
if (/** @type {number} */ (ap.column) < /** @type {number} */ (bp.column))
|
497
|
+
return -1;
|
498
|
+
if (/** @type {number} */ (ap.column) > /** @type {number} */ (bp.column))
|
499
|
+
return 1;
|
480
500
|
} else return -1;
|
481
501
|
} else if ("start" in b) return 1;
|
482
502
|
if ("name" in a) {
|
@@ -487,8 +507,10 @@ exports.compareLocations = (a, b) => {
|
|
487
507
|
} else if ("name" in b) return 1;
|
488
508
|
if ("index" in a) {
|
489
509
|
if ("index" in b) {
|
490
|
-
if (a.index < b.index)
|
491
|
-
|
510
|
+
if (/** @type {number} */ (a.index) < /** @type {number} */ (b.index))
|
511
|
+
return -1;
|
512
|
+
if (/** @type {number} */ (a.index) > /** @type {number} */ (b.index))
|
513
|
+
return 1;
|
492
514
|
} else return -1;
|
493
515
|
} else if ("index" in b) return 1;
|
494
516
|
return 0;
|
@@ -0,0 +1,129 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Gengkun He @ahabhgk
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @param {string} input input
|
12
|
+
* @param {CssGeneratorExportsConvention | undefined} convention convention
|
13
|
+
* @returns {Set<string>} results
|
14
|
+
*/
|
15
|
+
exports.cssExportConvention = (input, convention) => {
|
16
|
+
const set = new Set();
|
17
|
+
if (typeof convention === "function") {
|
18
|
+
set.add(convention(input));
|
19
|
+
} else {
|
20
|
+
switch (convention) {
|
21
|
+
case "camel-case": {
|
22
|
+
set.add(input);
|
23
|
+
set.add(exports.camelCase(input));
|
24
|
+
break;
|
25
|
+
}
|
26
|
+
case "camel-case-only": {
|
27
|
+
set.add(exports.camelCase(input));
|
28
|
+
break;
|
29
|
+
}
|
30
|
+
case "dashes": {
|
31
|
+
set.add(input);
|
32
|
+
set.add(exports.dashesCamelCase(input));
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
case "dashes-only": {
|
36
|
+
set.add(exports.dashesCamelCase(input));
|
37
|
+
break;
|
38
|
+
}
|
39
|
+
case "as-is": {
|
40
|
+
set.add(input);
|
41
|
+
break;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
return set;
|
46
|
+
};
|
47
|
+
|
48
|
+
// Copy from css-loader
|
49
|
+
/**
|
50
|
+
* @param {string} input input
|
51
|
+
* @returns {string} result
|
52
|
+
*/
|
53
|
+
exports.dashesCamelCase = input => {
|
54
|
+
return input.replace(/-+(\w)/g, (match, firstLetter) =>
|
55
|
+
firstLetter.toUpperCase()
|
56
|
+
);
|
57
|
+
};
|
58
|
+
|
59
|
+
// Copy from css-loader
|
60
|
+
/**
|
61
|
+
* @param {string} input input
|
62
|
+
* @returns {string} result
|
63
|
+
*/
|
64
|
+
exports.camelCase = input => {
|
65
|
+
let result = input.trim();
|
66
|
+
|
67
|
+
if (result.length === 0) {
|
68
|
+
return "";
|
69
|
+
}
|
70
|
+
|
71
|
+
if (result.length === 1) {
|
72
|
+
return result.toLowerCase();
|
73
|
+
}
|
74
|
+
|
75
|
+
const hasUpperCase = result !== result.toLowerCase();
|
76
|
+
|
77
|
+
if (hasUpperCase) {
|
78
|
+
result = preserveCamelCase(result);
|
79
|
+
}
|
80
|
+
|
81
|
+
return result
|
82
|
+
.replace(/^[_.\- ]+/, "")
|
83
|
+
.toLowerCase()
|
84
|
+
.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toUpperCase())
|
85
|
+
.replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toUpperCase());
|
86
|
+
};
|
87
|
+
|
88
|
+
// Copy from css-loader
|
89
|
+
/**
|
90
|
+
* @param {string} string string
|
91
|
+
* @returns {string} result
|
92
|
+
*/
|
93
|
+
const preserveCamelCase = string => {
|
94
|
+
let result = string;
|
95
|
+
let isLastCharLower = false;
|
96
|
+
let isLastCharUpper = false;
|
97
|
+
let isLastLastCharUpper = false;
|
98
|
+
|
99
|
+
for (let i = 0; i < result.length; i++) {
|
100
|
+
const character = result[i];
|
101
|
+
|
102
|
+
if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
|
103
|
+
result = `${result.slice(0, i)}-${result.slice(i)}`;
|
104
|
+
isLastCharLower = false;
|
105
|
+
isLastLastCharUpper = isLastCharUpper;
|
106
|
+
isLastCharUpper = true;
|
107
|
+
i += 1;
|
108
|
+
} else if (
|
109
|
+
isLastCharUpper &&
|
110
|
+
isLastLastCharUpper &&
|
111
|
+
/[\p{Ll}]/u.test(character)
|
112
|
+
) {
|
113
|
+
result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`;
|
114
|
+
isLastLastCharUpper = isLastCharUpper;
|
115
|
+
isLastCharUpper = false;
|
116
|
+
isLastCharLower = true;
|
117
|
+
} else {
|
118
|
+
isLastCharLower =
|
119
|
+
character.toLowerCase() === character &&
|
120
|
+
character.toUpperCase() !== character;
|
121
|
+
isLastLastCharUpper = isLastCharUpper;
|
122
|
+
isLastCharUpper =
|
123
|
+
character.toUpperCase() === character &&
|
124
|
+
character.toLowerCase() !== character;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
return result;
|
129
|
+
};
|
package/lib/util/createHash.js
CHANGED
@@ -11,7 +11,7 @@ const BULK_SIZE = 2000;
|
|
11
11
|
|
12
12
|
// We are using an object instead of a Map as this will stay static during the runtime
|
13
13
|
// so access to it can be optimized by v8
|
14
|
-
/** @type {
|
14
|
+
/** @type {{[key: string]: Map<string, string>}} */
|
15
15
|
const digestCaches = {};
|
16
16
|
|
17
17
|
/** @typedef {function(): Hash} HashFactory */
|
@@ -143,7 +143,7 @@ let BatchedHash = undefined;
|
|
143
143
|
|
144
144
|
/**
|
145
145
|
* Creates a hash by name or function
|
146
|
-
* @param {string | typeof Hash
|
146
|
+
* @param {string | typeof Hash} algorithm the algorithm name or a constructor creating a hash
|
147
147
|
* @returns {Hash} the hash
|
148
148
|
*/
|
149
149
|
module.exports = algorithm => {
|
@@ -184,9 +184,7 @@ module.exports = algorithm => {
|
|
184
184
|
if (crypto === undefined) crypto = require("crypto");
|
185
185
|
return new BulkUpdateDecorator(
|
186
186
|
() =>
|
187
|
-
/** @type {typeof import("crypto")} */ (crypto).createHash(
|
188
|
-
/** @type {string} */ (algorithm)
|
189
|
-
),
|
187
|
+
/** @type {typeof import("crypto")} */ (crypto).createHash(algorithm),
|
190
188
|
algorithm
|
191
189
|
);
|
192
190
|
}
|
package/lib/util/deprecation.js
CHANGED
@@ -11,7 +11,7 @@ const util = require("util");
|
|
11
11
|
const deprecationCache = new Map();
|
12
12
|
|
13
13
|
/**
|
14
|
-
* @typedef {
|
14
|
+
* @typedef {object} FakeHookMarker
|
15
15
|
* @property {true} _fakeHook it's a fake hook
|
16
16
|
*/
|
17
17
|
|
@@ -187,11 +187,11 @@ exports.createArrayToSetDeprecationSet = name => {
|
|
187
187
|
|
188
188
|
/**
|
189
189
|
* @template T
|
190
|
-
* @param {
|
190
|
+
* @param {object} obj object
|
191
191
|
* @param {string} name property name
|
192
192
|
* @param {string} code deprecation code
|
193
193
|
* @param {string} note additional note
|
194
|
-
* @returns {
|
194
|
+
* @returns {object} frozen object with deprecation when modifying
|
195
195
|
*/
|
196
196
|
exports.soonFrozenObjectDeprecation = (obj, name, code, note = "") => {
|
197
197
|
const message = `${name} will be frozen in future, all modifications are deprecated.${
|
@@ -272,7 +272,7 @@ const getSimilarities = nodes => {
|
|
272
272
|
|
273
273
|
/**
|
274
274
|
* @template T
|
275
|
-
* @typedef {
|
275
|
+
* @typedef {object} GroupedItems<T>
|
276
276
|
* @property {string} key
|
277
277
|
* @property {T[]} items
|
278
278
|
* @property {Record<string, number>} size
|
@@ -280,7 +280,7 @@ const getSimilarities = nodes => {
|
|
280
280
|
|
281
281
|
/**
|
282
282
|
* @template T
|
283
|
-
* @typedef {
|
283
|
+
* @typedef {object} Options
|
284
284
|
* @property {Record<string, number>} maxSize maximum size of a group
|
285
285
|
* @property {Record<string, number>} minSize minimum size of a group (preferred over maximum size)
|
286
286
|
* @property {Iterable<T>} items a list of items
|