webpack 5.106.2 → 5.107.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.
- package/README.md +2 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/Cache.js +3 -6
- package/lib/CompatibilityPlugin.js +8 -7
- package/lib/Compilation.js +34 -26
- package/lib/Compiler.js +4 -13
- package/lib/ContextModule.js +2 -2
- package/lib/DefinePlugin.js +2 -2
- package/lib/Dependency.js +22 -1
- package/lib/DependencyTemplate.js +2 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +8 -9
- package/lib/ExternalModule.js +76 -15
- package/lib/ExternalModuleFactoryPlugin.js +5 -0
- package/lib/FileSystemInfo.js +187 -72
- package/lib/Generator.js +3 -3
- package/lib/HotModuleReplacementPlugin.js +26 -8
- package/lib/IgnorePlugin.js +2 -1
- package/lib/Module.js +19 -18
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleSourceTypeConstants.js +31 -1
- package/lib/ModuleTypeConstants.js +12 -3
- package/lib/MultiCompiler.js +2 -2
- package/lib/NodeStuffPlugin.js +1 -1
- package/lib/NormalModule.js +13 -31
- package/lib/NormalModuleFactory.js +10 -2
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +129 -56
- package/lib/RuntimeGlobals.js +5 -5
- package/lib/RuntimeModule.js +9 -7
- package/lib/RuntimePlugin.js +11 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +16 -1
- package/lib/Watching.js +2 -3
- package/lib/WebpackError.js +3 -77
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +13 -1
- package/lib/asset/AssetBytesGenerator.js +6 -2
- package/lib/asset/AssetGenerator.js +22 -8
- package/lib/asset/AssetModulesPlugin.js +3 -1
- package/lib/asset/AssetSourceGenerator.js +6 -2
- package/lib/buildChunkGraph.js +4 -6
- package/lib/cache/PackFileCacheStrategy.js +4 -4
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +197 -10
- package/lib/config/normalization.js +3 -1
- package/lib/css/CssGenerator.js +320 -105
- package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
- package/lib/css/CssLoadingRuntimeModule.js +22 -4
- package/lib/{CssModule.js → css/CssModule.js} +15 -15
- package/lib/css/CssModulesPlugin.js +166 -86
- package/lib/css/CssParser.js +566 -269
- package/lib/css/walkCssTokens.js +148 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -3
- package/lib/dependencies/CommonJsRequireDependency.js +67 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +332 -67
- package/lib/dependencies/CssIcssImportDependency.js +49 -7
- package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
- package/lib/dependencies/CssImportDependency.js +8 -0
- package/lib/dependencies/CssUrlDependency.js +25 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
- package/lib/dependencies/HarmonyImportDependency.js +10 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
- package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
- package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
- package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
- package/lib/dependencies/HtmlScriptSrcDependency.js +318 -0
- package/lib/dependencies/HtmlSourceDependency.js +127 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/ImportPhase.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
- package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
- package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
- package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
- package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
- package/lib/{DllModule.js → dll/DllModule.js} +24 -24
- package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
- package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
- package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
- package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
- package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
- package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
- package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
- package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
- package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
- package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
- package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
- package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
- package/lib/errors/JSONParseError.js +114 -0
- package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
- package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
- package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
- package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
- package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
- package/lib/{ModuleNotFoundError.js → errors/ModuleNotFoundError.js} +2 -2
- package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
- package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
- package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
- package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
- package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
- package/lib/errors/NonErrorEmittedError.js +28 -0
- package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
- package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
- package/lib/errors/WebpackError.js +84 -0
- package/lib/html/HtmlGenerator.js +379 -0
- package/lib/html/HtmlModulesPlugin.js +433 -0
- package/lib/html/HtmlParser.js +1489 -0
- package/lib/html/walkHtmlTokens.js +2733 -0
- package/lib/ids/IdHelpers.js +2 -1
- package/lib/index.js +34 -15
- package/lib/javascript/JavascriptModulesPlugin.js +89 -8
- package/lib/javascript/JavascriptParser.js +197 -16
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/json/JsonParser.js +7 -16
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/EnableLibraryPlugin.js +1 -1
- package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
- package/lib/library/ModuleLibraryPlugin.js +74 -0
- package/lib/node/NodeEnvironmentPlugin.js +4 -2
- package/lib/node/nodeConsole.js +113 -64
- package/lib/optimize/ConcatenatedModule.js +51 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -1
- package/lib/optimize/MinMaxSizeWarning.js +4 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
- package/lib/optimize/RealContentHashPlugin.js +89 -26
- package/lib/optimize/SideEffectsFlagPlugin.js +111 -3
- package/lib/optimize/SplitChunksPlugin.js +1 -1
- package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/NoAsyncChunksWarning.js +5 -3
- package/lib/performance/SizeLimitsPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
- package/lib/rules/UseEffectRulePlugin.js +4 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
- package/lib/schemes/DataUriPlugin.js +13 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +2 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +1 -1
- package/lib/typescript/TypeScriptPlugin.js +210 -0
- package/lib/url/URLParserPlugin.js +2 -2
- package/lib/util/AsyncQueue.js +2 -2
- package/lib/util/Hash.js +2 -2
- package/lib/util/LocConverter.js +53 -0
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +3 -3
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +42 -1
- package/lib/util/createMappings.js +118 -0
- package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
- package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
- package/lib/util/fs.js +8 -8
- package/lib/util/hash/md4.js +1 -1
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +48 -0
- package/lib/util/internalSerializables.js +35 -19
- package/lib/util/magicComment.js +10 -7
- package/lib/util/parseJson.js +2 -73
- package/lib/util/source.js +21 -0
- package/lib/util/topologicalSort.js +69 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
- package/lib/webpack.js +3 -1
- package/package.json +22 -20
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +118 -3
- package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
- package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +22 -0
- package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
- package/types.d.ts +810 -101
- package/lib/CaseSensitiveModulesWarning.js +0 -80
- package/lib/GraphHelpers.js +0 -49
- package/lib/NoModeWarning.js +0 -23
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
- /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
- /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
- /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
|
@@ -24,7 +24,7 @@ class DataUriPlugin {
|
|
|
24
24
|
(compilation, { normalModuleFactory }) => {
|
|
25
25
|
normalModuleFactory.hooks.resolveForScheme
|
|
26
26
|
.for("data")
|
|
27
|
-
.tap(PLUGIN_NAME, (resourceData) => {
|
|
27
|
+
.tap(PLUGIN_NAME, (resourceData, resolveData) => {
|
|
28
28
|
const match = URIRegEx.exec(resourceData.resource);
|
|
29
29
|
if (match) {
|
|
30
30
|
resourceData.data.mimetype = match[1] || "";
|
|
@@ -34,6 +34,18 @@ class DataUriPlugin {
|
|
|
34
34
|
);
|
|
35
35
|
resourceData.data.encodedContent = match[4] || "";
|
|
36
36
|
}
|
|
37
|
+
// Inherit the issuer's resolution context so any nested
|
|
38
|
+
// dependencies discovered while parsing the data URI's body
|
|
39
|
+
// (e.g. `url(...)` / `@import` inside an inline CSS data
|
|
40
|
+
// URI) resolve relative to where the URI was referenced
|
|
41
|
+
// from, instead of against the synthetic `data:.../` path
|
|
42
|
+
// that `getContext("data:…")` would otherwise infer.
|
|
43
|
+
if (
|
|
44
|
+
resourceData.context === undefined &&
|
|
45
|
+
resolveData.context !== undefined
|
|
46
|
+
) {
|
|
47
|
+
resourceData.context = resolveData.context;
|
|
48
|
+
}
|
|
37
49
|
});
|
|
38
50
|
|
|
39
51
|
NormalModule.getCompilationHooks(compilation)
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
const { getContext } = require("loader-runner");
|
|
9
9
|
|
|
10
|
-
const ModuleNotFoundError = require("../ModuleNotFoundError");
|
|
11
10
|
const NormalModule = require("../NormalModule");
|
|
11
|
+
const ModuleNotFoundError = require("../errors/ModuleNotFoundError");
|
|
12
12
|
const { isAbsolute, join } = require("../util/fs");
|
|
13
13
|
const { parseResourceWithoutFragment } = require("../util/identifier");
|
|
14
14
|
|
|
@@ -37,7 +37,7 @@ class SerializerMiddleware {
|
|
|
37
37
|
* @returns {SerializedType | Promise<SerializedType> | null} serialized data
|
|
38
38
|
*/
|
|
39
39
|
serialize(data, context) {
|
|
40
|
-
const AbstractMethodError = require("../AbstractMethodError");
|
|
40
|
+
const AbstractMethodError = require("../errors/AbstractMethodError");
|
|
41
41
|
|
|
42
42
|
throw new AbstractMethodError();
|
|
43
43
|
}
|
|
@@ -51,7 +51,7 @@ class SerializerMiddleware {
|
|
|
51
51
|
* @returns {DeserializedType | Promise<DeserializedType>} deserialized data
|
|
52
52
|
*/
|
|
53
53
|
deserialize(data, context) {
|
|
54
|
-
const AbstractMethodError = require("../AbstractMethodError");
|
|
54
|
+
const AbstractMethodError = require("../errors/AbstractMethodError");
|
|
55
55
|
|
|
56
56
|
throw new AbstractMethodError();
|
|
57
57
|
}
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const ModuleNotFoundError = require("../ModuleNotFoundError");
|
|
9
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
|
-
const WebpackError = require("../WebpackError");
|
|
11
9
|
const { parseOptions } = require("../container/options");
|
|
10
|
+
const ModuleNotFoundError = require("../errors/ModuleNotFoundError");
|
|
11
|
+
const WebpackError = require("../errors/WebpackError");
|
|
12
12
|
const LazySet = require("../util/LazySet");
|
|
13
13
|
const { parseRange } = require("../util/semver");
|
|
14
14
|
const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependency");
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
|
10
10
|
const Template = require("../Template");
|
|
11
|
+
const { compareModulesById } = require("../util/comparators");
|
|
11
12
|
const {
|
|
12
13
|
parseVersionRuntimeCode,
|
|
13
14
|
rangeToStringRuntimeCode,
|
|
@@ -71,12 +72,14 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
|
71
72
|
);
|
|
72
73
|
}
|
|
73
74
|
};
|
|
75
|
+
const byId = compareModulesById(chunkGraph);
|
|
74
76
|
for (const chunk of /** @type {Chunk} */ (
|
|
75
77
|
this.chunk
|
|
76
78
|
).getAllReferencedChunks()) {
|
|
77
|
-
const modules = chunkGraph.
|
|
79
|
+
const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
|
78
80
|
chunk,
|
|
79
|
-
"consume-shared"
|
|
81
|
+
"consume-shared",
|
|
82
|
+
byId
|
|
80
83
|
);
|
|
81
84
|
if (!modules) continue;
|
|
82
85
|
addModules(
|
|
@@ -88,9 +91,10 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
|
|
|
88
91
|
for (const chunk of /** @type {Chunk} */ (
|
|
89
92
|
this.chunk
|
|
90
93
|
).getAllInitialChunks()) {
|
|
91
|
-
const modules = chunkGraph.
|
|
94
|
+
const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
|
92
95
|
chunk,
|
|
93
|
-
"consume-shared"
|
|
96
|
+
"consume-shared",
|
|
97
|
+
byId
|
|
94
98
|
);
|
|
95
99
|
if (!modules) continue;
|
|
96
100
|
addModules(modules, chunk, initialConsumes);
|
|
@@ -54,7 +54,7 @@ class ProvideSharedModule extends Module {
|
|
|
54
54
|
* @returns {string} a unique identifier of the module
|
|
55
55
|
*/
|
|
56
56
|
identifier() {
|
|
57
|
-
return `provide module (${this._shareScope}) ${this._name}@${this._version}
|
|
57
|
+
return `provide module (${this._shareScope}) ${this._name}@${this._version}|${this._request}`;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const WebpackError = require("../WebpackError");
|
|
9
8
|
const { parseOptions } = require("../container/options");
|
|
9
|
+
const WebpackError = require("../errors/WebpackError");
|
|
10
10
|
const ProvideForSharedDependency = require("./ProvideForSharedDependency");
|
|
11
11
|
const ProvideSharedDependency = require("./ProvideSharedDependency");
|
|
12
12
|
const ProvideSharedModuleFactory = require("./ProvideSharedModuleFactory");
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const ModuleNotFoundError = require("../ModuleNotFoundError");
|
|
8
|
+
const ModuleNotFoundError = require("../errors/ModuleNotFoundError");
|
|
9
9
|
const LazySet = require("../util/LazySet");
|
|
10
10
|
|
|
11
11
|
/** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
const util = require("util");
|
|
9
9
|
const { WEBPACK_MODULE_TYPE_RUNTIME } = require("../ModuleTypeConstants");
|
|
10
10
|
const ModuleDependency = require("../dependencies/ModuleDependency");
|
|
11
|
-
const formatLocation = require("../formatLocation");
|
|
12
11
|
const { LogType } = require("../logging/Logger");
|
|
13
12
|
const AggressiveSplittingPlugin = require("../optimize/AggressiveSplittingPlugin");
|
|
14
13
|
const SizeLimitsPlugin = require("../performance/SizeLimitsPlugin");
|
|
@@ -22,6 +21,7 @@ const {
|
|
|
22
21
|
compareSelect,
|
|
23
22
|
concatComparators
|
|
24
23
|
} = require("../util/comparators");
|
|
24
|
+
const formatLocation = require("../util/formatLocation");
|
|
25
25
|
const { makePathsRelative, parseResource } = require("../util/identifier");
|
|
26
26
|
|
|
27
27
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
@@ -48,7 +48,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
|
|
|
48
48
|
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
49
49
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
|
50
50
|
/** @typedef {import("../ModuleProfile")} ModuleProfile */
|
|
51
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
51
|
+
/** @typedef {import("../errors/WebpackError")} WebpackError */
|
|
52
52
|
/** @typedef {import("../serialization/AggregateErrorSerializer").AggregateError} AggregateError */
|
|
53
53
|
/** @typedef {import("../serialization/ErrorObjectSerializer").ErrorWithCause} ErrorWithCause */
|
|
54
54
|
/** @typedef {import("../ExportsInfo").ExportInfoName} ExportInfoName */
|
|
@@ -31,7 +31,7 @@ const applyDefaults = (options, defaults) => {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
/** @typedef {{ [Key in Exclude<StatsValue, boolean |
|
|
34
|
+
/** @typedef {{ [Key in Exclude<StatsValue, boolean | StatsOptions | "normal">]: StatsOptions }} NamedPresets */
|
|
35
35
|
|
|
36
36
|
/** @type {NamedPresets} */
|
|
37
37
|
const NAMED_PRESETS = {
|
|
@@ -1510,7 +1510,7 @@ const AVAILABLE_FORMATS = {
|
|
|
1510
1510
|
(oversize ? yellow : green)(filename),
|
|
1511
1511
|
formatFlag: (flag) => `[${flag}]`,
|
|
1512
1512
|
formatLayer: (layer) => `(in ${layer})`,
|
|
1513
|
-
formatSize: require("../
|
|
1513
|
+
formatSize: require("../util/formatSize"),
|
|
1514
1514
|
formatDateTime: (dateTime, { bold }) => {
|
|
1515
1515
|
const d = new Date(dateTime);
|
|
1516
1516
|
const x = twoDigit;
|
|
@@ -18,7 +18,7 @@ const smartGrouping = require("../util/smartGrouping");
|
|
|
18
18
|
/** @typedef {import("../Module")} Module */
|
|
19
19
|
/** @typedef {import("../ModuleGraph").ModuleProfile} ModuleProfile */
|
|
20
20
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
|
21
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
21
|
+
/** @typedef {import("../errors/WebpackError")} WebpackError */
|
|
22
22
|
/** @typedef {import("../util/comparators").Comparator<EXPECTED_ANY>} Comparator */
|
|
23
23
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
24
24
|
/**
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const mod = require("module");
|
|
9
|
+
const {
|
|
10
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
|
11
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
|
12
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
|
13
|
+
} = require("../ModuleTypeConstants");
|
|
14
|
+
const NormalModule = require("../NormalModule");
|
|
15
|
+
const ModuleBuildError = require("../errors/ModuleBuildError");
|
|
16
|
+
const memoize = require("../util/memoize");
|
|
17
|
+
const removeBOM = require("../util/removeBOM");
|
|
18
|
+
|
|
19
|
+
/** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
|
|
20
|
+
/** @typedef {import("../Compiler")} Compiler */
|
|
21
|
+
/** @typedef {import("../NormalModule")} NormalModuleType */
|
|
22
|
+
/** @typedef {import("../NormalModule").Result} Result */
|
|
23
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
24
|
+
|
|
25
|
+
const getSourceMapSource = memoize(
|
|
26
|
+
() => require("webpack-sources").SourceMapSource
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const PLUGIN_NAME = "TypeScriptPlugin";
|
|
30
|
+
|
|
31
|
+
/** @type {Set<string>} */
|
|
32
|
+
const JS_MODULE_TYPES = new Set([
|
|
33
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
|
34
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
|
35
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
const TS_RESOURCE_RE = /\.(?:[mc]?tsx?)$/i;
|
|
39
|
+
const TSX_RESOURCE_RE = /\.[mc]?tsx$/i;
|
|
40
|
+
const TS_DATA_URI_RE = /^data:(?:text|application)\/typescript/i;
|
|
41
|
+
|
|
42
|
+
const TSX_NOT_SUPPORTED =
|
|
43
|
+
"experiments.typescript does not support .tsx/JSX. " +
|
|
44
|
+
"Use a TSX-capable loader (e.g. swc-loader, esbuild-loader, ts-loader) for .tsx files.";
|
|
45
|
+
|
|
46
|
+
const NODE_API_MISSING =
|
|
47
|
+
"experiments.typescript requires Node.js >= 22.6. " +
|
|
48
|
+
"`module.stripTypeScriptTypes` is not available on this Node.js version.";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Whether the resource (path or `data:` URI) should go through the TypeScript
|
|
52
|
+
* transform. Returns true for `.ts`, `.cts`, `.mts`, and the JSX-flavoured
|
|
53
|
+
* variants (so the `.tsx` branch can throw a friendly error), as well as the
|
|
54
|
+
* `text/typescript` / `application/typescript` data URIs.
|
|
55
|
+
* @param {string} resource module resource (without query string)
|
|
56
|
+
* @returns {boolean} true if the resource should be transformed
|
|
57
|
+
*/
|
|
58
|
+
const isTypeScriptResource = (resource) =>
|
|
59
|
+
TS_RESOURCE_RE.test(resource) || TS_DATA_URI_RE.test(resource);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Build a line-granularity identity source map for a strip-types output.
|
|
63
|
+
* `mode: "strip"` replaces type annotations with whitespace, so the stripped
|
|
64
|
+
* output preserves the original line layout — an identity mapping is correct.
|
|
65
|
+
* Node's API does not emit a source map in strip mode (`sourceMap: true` is
|
|
66
|
+
* rejected on Node 22+ and Node 26+), so we construct one by hand.
|
|
67
|
+
* @param {string} resource module resource path
|
|
68
|
+
* @param {string} originalSource pre-strip source content
|
|
69
|
+
* @returns {RawSourceMap} identity source map
|
|
70
|
+
*/
|
|
71
|
+
const createIdentitySourceMap = (resource, originalSource) => {
|
|
72
|
+
const lineCount = (originalSource.match(/\n/g) || []).length + 1;
|
|
73
|
+
// Mappings: each line emits a single segment at column 0 mapping to
|
|
74
|
+
// column 0 of the same line in the source. `AAAA` for line 1, `;AACA`
|
|
75
|
+
// for each subsequent line (cumulative source-line delta of +1 per line).
|
|
76
|
+
const mappings = `AAAA${";AACA".repeat(lineCount - 1)}`;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
version: 3,
|
|
80
|
+
file: resource,
|
|
81
|
+
sources: [resource],
|
|
82
|
+
sourcesContent: [originalSource],
|
|
83
|
+
names: [],
|
|
84
|
+
mappings
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Compose the strip-types source map with an upstream loader source map so the
|
|
90
|
+
* final map points back to the loader's original input (e.g. a `.vue` /
|
|
91
|
+
* `.svelte` / custom loader that emits TS code).
|
|
92
|
+
* @param {string} resource module resource
|
|
93
|
+
* @param {string} strippedSource post-strip JS
|
|
94
|
+
* @param {RawSourceMap} stripMap identity map for the strip step
|
|
95
|
+
* @param {string} preStripSource pre-strip TS (loader output)
|
|
96
|
+
* @param {string | RawSourceMap} loaderSourceMap upstream loader source map
|
|
97
|
+
* @returns {RawSourceMap} composed map
|
|
98
|
+
*/
|
|
99
|
+
const composeWithLoaderSourceMap = (
|
|
100
|
+
resource,
|
|
101
|
+
strippedSource,
|
|
102
|
+
stripMap,
|
|
103
|
+
preStripSource,
|
|
104
|
+
loaderSourceMap
|
|
105
|
+
) => {
|
|
106
|
+
const SourceMapSource = getSourceMapSource();
|
|
107
|
+
const composed = new SourceMapSource(
|
|
108
|
+
strippedSource,
|
|
109
|
+
resource,
|
|
110
|
+
stripMap,
|
|
111
|
+
preStripSource,
|
|
112
|
+
loaderSourceMap,
|
|
113
|
+
true
|
|
114
|
+
);
|
|
115
|
+
return /** @type {RawSourceMap} */ (composed.sourceAndMap().map) || stripMap;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Run `module.stripTypeScriptTypes` on the input, wrapping any thrown
|
|
120
|
+
* `TypeScript ...` errors as `ModuleBuildError` so they surface as
|
|
121
|
+
* per-module build errors instead of uncaught exceptions.
|
|
122
|
+
* @param {string} input pre-strip TS source (BOM-free string)
|
|
123
|
+
* @returns {string} stripped JS
|
|
124
|
+
*/
|
|
125
|
+
const stripTypes = (input) => {
|
|
126
|
+
try {
|
|
127
|
+
// Pass only `mode`. `sourceUrl` would emit a `//# sourceURL=…` pragma
|
|
128
|
+
// into the output (V8 debugger hint), and `sourceMap: true` is
|
|
129
|
+
// rejected in strip mode — we build the source map by hand instead.
|
|
130
|
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
131
|
+
return mod.stripTypeScriptTypes(input, { mode: "strip" });
|
|
132
|
+
} catch (err) {
|
|
133
|
+
throw new ModuleBuildError(/** @type {Error} */ (err));
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Coerce a Buffer-or-string source to a UTF-8 string, dropping any BOM.
|
|
139
|
+
* @param {string | Buffer} source raw source from the loader pipeline
|
|
140
|
+
* @returns {string} UTF-8 string without BOM
|
|
141
|
+
*/
|
|
142
|
+
const toBomFreeString = (source) => {
|
|
143
|
+
const text = Buffer.isBuffer(source) ? source.toString("utf8") : source;
|
|
144
|
+
const stripped = removeBOM(text);
|
|
145
|
+
return typeof stripped === "string" ? stripped : stripped.toString("utf8");
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
class TypeScriptPlugin {
|
|
149
|
+
/**
|
|
150
|
+
* @param {Compiler} compiler webpack compiler
|
|
151
|
+
* @returns {void}
|
|
152
|
+
*/
|
|
153
|
+
apply(compiler) {
|
|
154
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
155
|
+
NormalModule.getCompilationHooks(compilation).processResult.tap(
|
|
156
|
+
PLUGIN_NAME,
|
|
157
|
+
(result, module) => this._processResult(result, module)
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* processResult tap body. Returns the input untouched unless this is a
|
|
164
|
+
* TypeScript module that needs to be transformed.
|
|
165
|
+
* @param {Result} result loader result tuple
|
|
166
|
+
* @param {NormalModuleType} module the normal module
|
|
167
|
+
* @returns {Result} possibly transformed result
|
|
168
|
+
*/
|
|
169
|
+
_processResult(result, module) {
|
|
170
|
+
if (!JS_MODULE_TYPES.has(module.type)) return result;
|
|
171
|
+
|
|
172
|
+
const parser = /** @type {JavascriptParser} */ (module.parser);
|
|
173
|
+
if (!parser.options.typescript) return result;
|
|
174
|
+
|
|
175
|
+
const resource = module.nameForCondition();
|
|
176
|
+
if (!resource || !isTypeScriptResource(resource)) return result;
|
|
177
|
+
|
|
178
|
+
if (TSX_RESOURCE_RE.test(resource)) {
|
|
179
|
+
throw new ModuleBuildError(new Error(TSX_NOT_SUPPORTED));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!("stripTypeScriptTypes" in mod)) {
|
|
183
|
+
throw new ModuleBuildError(new Error(NODE_API_MISSING));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const [rawSource, loaderSourceMap, ...rest] = result;
|
|
187
|
+
const preStripSource = toBomFreeString(rawSource);
|
|
188
|
+
const strippedSource = stripTypes(preStripSource);
|
|
189
|
+
|
|
190
|
+
const needSourceMap = module.useSourceMap || module.useSimpleSourceMap;
|
|
191
|
+
const stripMap = needSourceMap
|
|
192
|
+
? createIdentitySourceMap(module.resource, preStripSource)
|
|
193
|
+
: undefined;
|
|
194
|
+
|
|
195
|
+
const outputSourceMap =
|
|
196
|
+
stripMap && loaderSourceMap
|
|
197
|
+
? composeWithLoaderSourceMap(
|
|
198
|
+
module.resource,
|
|
199
|
+
strippedSource,
|
|
200
|
+
stripMap,
|
|
201
|
+
preStripSource,
|
|
202
|
+
loaderSourceMap
|
|
203
|
+
)
|
|
204
|
+
: stripMap || loaderSourceMap;
|
|
205
|
+
|
|
206
|
+
return [strippedSource, outputSourceMap, ...rest];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module.exports = TypeScriptPlugin;
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { pathToFileURL } = require("url");
|
|
9
|
-
const CommentCompilationWarning = require("../CommentCompilationWarning");
|
|
10
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
11
|
-
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
|
12
10
|
const ConstDependency = require("../dependencies/ConstDependency");
|
|
13
11
|
const ContextDependencyHelpers = require("../dependencies/ContextDependencyHelpers");
|
|
14
12
|
const URLContextDependency = require("../dependencies/URLContextDependency");
|
|
15
13
|
const URLDependency = require("../dependencies/URLDependency");
|
|
14
|
+
const CommentCompilationWarning = require("../errors/CommentCompilationWarning");
|
|
15
|
+
const UnsupportedFeatureWarning = require("../errors/UnsupportedFeatureWarning");
|
|
16
16
|
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
|
|
17
17
|
const { approve } = require("../javascript/JavascriptParserHelpers");
|
|
18
18
|
const InnerGraph = require("../optimize/InnerGraph");
|
package/lib/util/AsyncQueue.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { AsyncSeriesHook, SyncHook } = require("tapable");
|
|
9
|
-
const { makeWebpackError } = require("../HookWebpackError");
|
|
10
|
-
const WebpackError = require("../WebpackError");
|
|
9
|
+
const { makeWebpackError } = require("../errors/HookWebpackError");
|
|
10
|
+
const WebpackError = require("../errors/WebpackError");
|
|
11
11
|
const ArrayQueue = require("./ArrayQueue");
|
|
12
12
|
|
|
13
13
|
const QUEUED_STATE = 0;
|
package/lib/util/Hash.js
CHANGED
|
@@ -33,7 +33,7 @@ class Hash {
|
|
|
33
33
|
* @returns {Hash} updated hash
|
|
34
34
|
*/
|
|
35
35
|
update(data, inputEncoding) {
|
|
36
|
-
const AbstractMethodError = require("../AbstractMethodError");
|
|
36
|
+
const AbstractMethodError = require("../errors/AbstractMethodError");
|
|
37
37
|
|
|
38
38
|
throw new AbstractMethodError();
|
|
39
39
|
}
|
|
@@ -59,7 +59,7 @@ class Hash {
|
|
|
59
59
|
* @returns {string | Buffer} digest
|
|
60
60
|
*/
|
|
61
61
|
digest(encoding) {
|
|
62
|
-
const AbstractMethodError = require("../AbstractMethodError");
|
|
62
|
+
const AbstractMethodError = require("../errors/AbstractMethodError");
|
|
63
63
|
|
|
64
64
|
throw new AbstractMethodError();
|
|
65
65
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Alexander Akait @alexander-akait
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
class LocConverter {
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of LocConverter.
|
|
11
|
+
* @param {string} input input
|
|
12
|
+
*/
|
|
13
|
+
constructor(input) {
|
|
14
|
+
this._input = input;
|
|
15
|
+
this.line = 1;
|
|
16
|
+
this.column = 0;
|
|
17
|
+
this.pos = 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Returns location converter.
|
|
22
|
+
* @param {number} pos position
|
|
23
|
+
* @returns {LocConverter} location converter
|
|
24
|
+
*/
|
|
25
|
+
get(pos) {
|
|
26
|
+
if (this.pos !== pos) {
|
|
27
|
+
if (this.pos < pos) {
|
|
28
|
+
const str = this._input.slice(this.pos, pos);
|
|
29
|
+
let i = str.lastIndexOf("\n");
|
|
30
|
+
if (i === -1) {
|
|
31
|
+
this.column += str.length;
|
|
32
|
+
} else {
|
|
33
|
+
this.column = str.length - i - 1;
|
|
34
|
+
this.line++;
|
|
35
|
+
while (i > 0 && (i = str.lastIndexOf("\n", i - 1)) !== -1) {
|
|
36
|
+
this.line++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
let i = this._input.lastIndexOf("\n", this.pos);
|
|
41
|
+
while (i >= pos) {
|
|
42
|
+
this.line--;
|
|
43
|
+
i = i > 0 ? this._input.lastIndexOf("\n", i - 1) : -1;
|
|
44
|
+
}
|
|
45
|
+
this.column = i === -1 ? pos : pos - i - 1;
|
|
46
|
+
}
|
|
47
|
+
this.pos = pos;
|
|
48
|
+
}
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = LocConverter;
|
package/lib/util/SortableSet.js
CHANGED
|
@@ -108,7 +108,7 @@ class SortableSet extends Set {
|
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* Get data from cache
|
|
111
|
-
* @template
|
|
111
|
+
* @template R
|
|
112
112
|
* @param {(set: SortableSet<T>) => R} fn function to calculate value
|
|
113
113
|
* @returns {R} returns result of fn(this), cached until set changes
|
|
114
114
|
*/
|
package/lib/util/cleverMerge.js
CHANGED
|
@@ -132,10 +132,10 @@ const parseCache = new WeakMap();
|
|
|
132
132
|
* @returns {ParsedObject<T>} parsed object
|
|
133
133
|
*/
|
|
134
134
|
const cachedParseObject = (obj) => {
|
|
135
|
-
const entry = parseCache.get(
|
|
135
|
+
const entry = parseCache.get(obj);
|
|
136
136
|
if (entry !== undefined) return entry;
|
|
137
137
|
const result = parseObject(obj);
|
|
138
|
-
parseCache.set(
|
|
138
|
+
parseCache.set(obj, result);
|
|
139
139
|
return result;
|
|
140
140
|
};
|
|
141
141
|
|
package/lib/util/comparators.js
CHANGED
|
@@ -56,10 +56,10 @@ const { compareRuntime } = require("./runtime");
|
|
|
56
56
|
* @returns {ParameterizedComparator<TArg, T>} comparator
|
|
57
57
|
*/
|
|
58
58
|
const createCachedParameterizedComparator = (fn) => {
|
|
59
|
-
/** @type {WeakMap<
|
|
59
|
+
/** @type {WeakMap<TArg, Comparator<T>>} */
|
|
60
60
|
const map = new WeakMap();
|
|
61
61
|
return (arg) => {
|
|
62
|
-
const cachedResult = map.get(
|
|
62
|
+
const cachedResult = map.get(arg);
|
|
63
63
|
if (cachedResult !== undefined) return cachedResult;
|
|
64
64
|
/**
|
|
65
65
|
* Returns compare result.
|
|
@@ -68,7 +68,7 @@ const createCachedParameterizedComparator = (fn) => {
|
|
|
68
68
|
* @returns {-1 | 0 | 1} compare result
|
|
69
69
|
*/
|
|
70
70
|
const result = fn.bind(null, arg);
|
|
71
|
-
map.set(
|
|
71
|
+
map.set(arg, result);
|
|
72
72
|
return result;
|
|
73
73
|
};
|
|
74
74
|
};
|
package/lib/util/concatenate.js
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
const Template = require("../Template");
|
|
9
9
|
|
|
10
|
-
/** @typedef {import("eslint-scope").Scope} Scope */
|
|
11
|
-
/** @typedef {import("eslint-scope").Reference} Reference */
|
|
12
|
-
/** @typedef {import("eslint-scope").Variable} Variable */
|
|
13
10
|
/** @typedef {import("estree").Node} Node */
|
|
11
|
+
/** @typedef {import("../javascript/JavascriptModulesPlugin").Scope} Scope */
|
|
12
|
+
/** @typedef {import("../javascript/JavascriptModulesPlugin").Reference} Reference */
|
|
13
|
+
/** @typedef {import("../javascript/JavascriptModulesPlugin").Variable} Variable */
|
|
14
14
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
15
15
|
/** @typedef {Set<string>} UsedNames */
|
|
16
16
|
|
package/lib/util/conventions.js
CHANGED
|
@@ -80,6 +80,26 @@ module.exports.camelCase = (input) => {
|
|
|
80
80
|
.replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, (m) => m.toUpperCase());
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Safely stringify an arbitrary value for an error message — falls back to
|
|
85
|
+
* `String(...)` when JSON.stringify would throw (BigInt, circular, etc.).
|
|
86
|
+
* @param {EXPECTED_ANY} value value to stringify
|
|
87
|
+
* @returns {string} stringified value
|
|
88
|
+
*/
|
|
89
|
+
const safeStringify = (value) => {
|
|
90
|
+
try {
|
|
91
|
+
const json = JSON.stringify(value);
|
|
92
|
+
if (json !== undefined) return json;
|
|
93
|
+
} catch (_err) {
|
|
94
|
+
// fall through to String fallback
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
return String(value);
|
|
98
|
+
} catch (_err) {
|
|
99
|
+
return "[value cannot be converted to string]";
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
83
103
|
/**
|
|
84
104
|
* Returns results.
|
|
85
105
|
* @param {string} input input
|
|
@@ -90,7 +110,28 @@ module.exports.cssExportConvention = (input, convention) => {
|
|
|
90
110
|
/** @type {Set<string>} */
|
|
91
111
|
const set = new Set();
|
|
92
112
|
if (typeof convention === "function") {
|
|
93
|
-
|
|
113
|
+
const result = convention(input);
|
|
114
|
+
const validate = (/** @type {string} */ name) => {
|
|
115
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`exportsConvention function must return a non-empty string or an array of non-empty strings, got ${safeStringify(result)}`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
if (Array.isArray(result)) {
|
|
122
|
+
if (result.length === 0) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
"exportsConvention function returned an empty array; it must return at least one name"
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
for (const name of result) {
|
|
128
|
+
validate(name);
|
|
129
|
+
set.add(name);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
validate(result);
|
|
133
|
+
set.add(result);
|
|
134
|
+
}
|
|
94
135
|
} else {
|
|
95
136
|
switch (convention) {
|
|
96
137
|
case "camel-case": {
|