webpack 5.102.1 → 5.104.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 +121 -134
- package/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +28 -2
- package/lib/Compilation.js +58 -21
- package/lib/Compiler.js +3 -3
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +45 -14
- package/lib/DelegatedModule.js +7 -4
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +462 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +28 -35
- package/lib/ExternalModuleFactoryPlugin.js +11 -9
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +27 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +29 -13
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +424 -116
- package/lib/NormalModule.js +23 -20
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +120 -57
- package/lib/SourceMapDevToolPlugin.js +26 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +67 -15
- package/lib/asset/AssetBytesGenerator.js +16 -12
- package/lib/asset/AssetGenerator.js +31 -26
- package/lib/asset/AssetSourceGenerator.js +16 -12
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +24 -0
- package/lib/config/defaults.js +226 -61
- package/lib/config/normalization.js +4 -3
- package/lib/config/target.js +11 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +304 -76
- package/lib/css/CssLoadingRuntimeModule.js +14 -4
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +72 -67
- package/lib/css/CssParser.js +1726 -732
- package/lib/css/walkCssTokens.js +128 -11
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +389 -12
- package/lib/dependencies/CssIcssImportDependency.js +114 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
- package/lib/dependencies/CssImportDependency.js +17 -6
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -9
- package/lib/dependencies/ImportParserPlugin.js +21 -23
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +5 -3
- package/lib/ids/IdHelpers.js +20 -8
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +105 -104
- package/lib/javascript/JavascriptModulesPlugin.js +80 -37
- package/lib/javascript/JavascriptParser.js +161 -44
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -23
- package/lib/library/SystemLibraryPlugin.js +8 -1
- package/lib/library/UmdLibraryPlugin.js +2 -2
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +208 -167
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/schemes/HttpUriPlugin.js +78 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +54 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +34 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +160 -101
- package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +771 -436
- package/lib/ModuleSourceTypesConstants.js +0 -123
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
|
@@ -5,14 +5,25 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const { CSS_TYPE, JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
|
|
9
|
+
const WebpackError = require("../WebpackError");
|
|
8
10
|
const { cssExportConvention } = require("../util/conventions");
|
|
11
|
+
const createHash = require("../util/createHash");
|
|
12
|
+
const { makePathsRelative } = require("../util/identifier");
|
|
9
13
|
const makeSerializable = require("../util/makeSerializable");
|
|
14
|
+
const memoize = require("../util/memoize");
|
|
15
|
+
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
|
16
|
+
const CssIcssImportDependency = require("./CssIcssImportDependency");
|
|
10
17
|
const NullDependency = require("./NullDependency");
|
|
11
18
|
|
|
19
|
+
const getCssParser = memoize(() => require("../css/CssParser"));
|
|
20
|
+
|
|
12
21
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
13
22
|
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
|
23
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
|
14
24
|
/** @typedef {import("../CssModule")} CssModule */
|
|
15
25
|
/** @typedef {import("../Dependency")} Dependency */
|
|
26
|
+
/** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
|
|
16
27
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
|
17
28
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
|
18
29
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
|
@@ -21,16 +32,144 @@ const NullDependency = require("./NullDependency");
|
|
|
21
32
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
22
33
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
23
34
|
/** @typedef {import("../util/Hash")} Hash */
|
|
35
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
36
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
37
|
+
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
38
|
+
/** @typedef {import("../css/CssParser").Range} Range */
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {string} local css local
|
|
42
|
+
* @param {CssModule} module module
|
|
43
|
+
* @param {ChunkGraph} chunkGraph chunk graph
|
|
44
|
+
* @param {RuntimeTemplate} runtimeTemplate runtime template
|
|
45
|
+
* @returns {string} local ident
|
|
46
|
+
*/
|
|
47
|
+
const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
|
|
48
|
+
const generator = /** @type {CssGenerator} */ (module.generator);
|
|
49
|
+
const localIdentName =
|
|
50
|
+
/** @type {CssGeneratorLocalIdentName} */
|
|
51
|
+
(generator.options.localIdentName);
|
|
52
|
+
const relativeResourcePath = makePathsRelative(
|
|
53
|
+
/** @type {string} */
|
|
54
|
+
(module.context),
|
|
55
|
+
/** @type {string} */
|
|
56
|
+
(module.getResource()),
|
|
57
|
+
runtimeTemplate.compilation.compiler.root
|
|
58
|
+
);
|
|
59
|
+
const { uniqueName } = runtimeTemplate.outputOptions;
|
|
60
|
+
|
|
61
|
+
let localIdentHash = "";
|
|
62
|
+
|
|
63
|
+
if (/\[(fullhash|hash)\]/.test(localIdentName)) {
|
|
64
|
+
const hashSalt = generator.options.localIdentHashSalt;
|
|
65
|
+
const hashDigest =
|
|
66
|
+
/** @type {string} */
|
|
67
|
+
(generator.options.localIdentHashDigest);
|
|
68
|
+
const hashDigestLength = generator.options.localIdentHashDigestLength;
|
|
69
|
+
const { hashFunction } = runtimeTemplate.outputOptions;
|
|
70
|
+
|
|
71
|
+
const hash = createHash(hashFunction);
|
|
72
|
+
|
|
73
|
+
if (hashSalt) {
|
|
74
|
+
hash.update(hashSalt);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (uniqueName) {
|
|
78
|
+
hash.update(uniqueName);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
hash.update(relativeResourcePath);
|
|
82
|
+
hash.update(local);
|
|
83
|
+
|
|
84
|
+
localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let contentHash = "";
|
|
88
|
+
|
|
89
|
+
if (/\[contenthash\]/.test(localIdentName)) {
|
|
90
|
+
const hash = createHash(runtimeTemplate.outputOptions.hashFunction);
|
|
91
|
+
const source = module.originalSource();
|
|
92
|
+
|
|
93
|
+
if (source) {
|
|
94
|
+
hash.update(source.buffer());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (module.error) {
|
|
98
|
+
hash.update(module.error.toString());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const fullContentHash = hash.digest(
|
|
102
|
+
runtimeTemplate.outputOptions.hashDigest
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
contentHash = nonNumericOnlyHash(
|
|
106
|
+
fullContentHash,
|
|
107
|
+
runtimeTemplate.outputOptions.hashDigestLength
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let localIdent = runtimeTemplate.compilation.getPath(localIdentName, {
|
|
112
|
+
prepareId: (id) => {
|
|
113
|
+
if (typeof id !== "string") return id;
|
|
114
|
+
|
|
115
|
+
return id
|
|
116
|
+
.replace(/^([.-]|[^a-zA-Z0-9_-])+/, "")
|
|
117
|
+
.replace(/[^a-zA-Z0-9_-]+/g, "_");
|
|
118
|
+
},
|
|
119
|
+
filename: relativeResourcePath,
|
|
120
|
+
hash: localIdentHash,
|
|
121
|
+
contentHash,
|
|
122
|
+
chunkGraph,
|
|
123
|
+
module
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (/\[local\]/.test(localIdentName)) {
|
|
127
|
+
localIdent = localIdent.replace(/\[local\]/g, local);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (/\[uniqueName\]/.test(localIdentName)) {
|
|
131
|
+
localIdent = localIdent.replace(
|
|
132
|
+
/\[uniqueName\]/g,
|
|
133
|
+
/** @type {string} */ (uniqueName)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Protect the first character from unsupported values
|
|
138
|
+
return localIdent.replace(/^((-?[0-9])|--)/, "_$1");
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// 0 - replace, 1 - replace, 2 - append, 2 - once
|
|
142
|
+
/** @typedef {0 | 1 | 2 | 3 | 4} ExportMode */
|
|
143
|
+
// 0 - normal, 1 - custom css variable, 2 - grid custom ident
|
|
144
|
+
/** @typedef {0 | 1 | 2} ExportType */
|
|
24
145
|
|
|
25
146
|
class CssIcssExportDependency extends NullDependency {
|
|
26
147
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
148
|
+
* Example of dependency:
|
|
149
|
+
*
|
|
150
|
+
* :export { LOCAL_NAME: EXPORT_NAME }
|
|
151
|
+
* @param {string} name export name
|
|
152
|
+
* @param {string | [string, string, boolean]} value export value or true when we need interpolate name as a value
|
|
153
|
+
* @param {Range=} range range
|
|
154
|
+
* @param {boolean=} interpolate true when value need to be interpolated, otherwise false
|
|
155
|
+
* @param {ExportMode=} exportMode export mode
|
|
156
|
+
* @param {ExportType=} exportType export type
|
|
29
157
|
*/
|
|
30
|
-
constructor(
|
|
158
|
+
constructor(
|
|
159
|
+
name,
|
|
160
|
+
value,
|
|
161
|
+
range,
|
|
162
|
+
interpolate = false,
|
|
163
|
+
exportMode = CssIcssExportDependency.EXPORT_MODE.REPLACE,
|
|
164
|
+
exportType = CssIcssExportDependency.EXPORT_TYPE.NORMAL
|
|
165
|
+
) {
|
|
31
166
|
super();
|
|
32
167
|
this.name = name;
|
|
33
168
|
this.value = value;
|
|
169
|
+
this.range = range;
|
|
170
|
+
this.interpolate = interpolate;
|
|
171
|
+
this.exportMode = exportMode;
|
|
172
|
+
this.exportType = exportType;
|
|
34
173
|
this._hashUpdate = undefined;
|
|
35
174
|
}
|
|
36
175
|
|
|
@@ -51,21 +190,52 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
51
190
|
return this._conventionNames;
|
|
52
191
|
}
|
|
53
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Returns list of exports referenced by this dependency
|
|
195
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
196
|
+
* @param {RuntimeSpec} runtime the runtime for which the module is analysed
|
|
197
|
+
* @returns {ReferencedExports} referenced exports
|
|
198
|
+
*/
|
|
199
|
+
getReferencedExports(moduleGraph, runtime) {
|
|
200
|
+
if (
|
|
201
|
+
this.exportMode === CssIcssExportDependency.EXPORT_MODE.SELF_REFERENCE
|
|
202
|
+
) {
|
|
203
|
+
return [
|
|
204
|
+
{
|
|
205
|
+
name: [this.name],
|
|
206
|
+
canMangle: true
|
|
207
|
+
}
|
|
208
|
+
];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return super.getReferencedExports(moduleGraph, runtime);
|
|
212
|
+
}
|
|
213
|
+
|
|
54
214
|
/**
|
|
55
215
|
* Returns the exported names
|
|
56
216
|
* @param {ModuleGraph} moduleGraph module graph
|
|
57
217
|
* @returns {ExportsSpec | undefined} export names
|
|
58
218
|
*/
|
|
59
219
|
getExports(moduleGraph) {
|
|
220
|
+
if (
|
|
221
|
+
this.exportMode === CssIcssExportDependency.EXPORT_MODE.NONE ||
|
|
222
|
+
this.exportMode === CssIcssExportDependency.EXPORT_MODE.SELF_REFERENCE
|
|
223
|
+
) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
60
227
|
const module = /** @type {CssModule} */ (moduleGraph.getParentModule(this));
|
|
61
228
|
const generator = /** @type {CssGenerator} */ (module.generator);
|
|
62
229
|
const names = this.getExportsConventionNames(
|
|
63
230
|
this.name,
|
|
64
231
|
/** @type {CssGeneratorExportsConvention} */
|
|
65
|
-
(generator.
|
|
232
|
+
(generator.options.exportsConvention)
|
|
66
233
|
);
|
|
67
234
|
return {
|
|
68
|
-
exports:
|
|
235
|
+
exports: [
|
|
236
|
+
...names,
|
|
237
|
+
...(Array.isArray(this.value) ? [this.value[1]] : [])
|
|
238
|
+
].map((name) => ({
|
|
69
239
|
name,
|
|
70
240
|
canMangle: true
|
|
71
241
|
})),
|
|
@@ -73,6 +243,34 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
73
243
|
};
|
|
74
244
|
}
|
|
75
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Returns warnings
|
|
248
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
249
|
+
* @returns {WebpackError[] | null | undefined} warnings
|
|
250
|
+
*/
|
|
251
|
+
getWarnings(moduleGraph) {
|
|
252
|
+
if (
|
|
253
|
+
this.exportMode === CssIcssExportDependency.EXPORT_MODE.SELF_REFERENCE &&
|
|
254
|
+
!Array.isArray(this.value)
|
|
255
|
+
) {
|
|
256
|
+
const module = moduleGraph.getParentModule(this);
|
|
257
|
+
|
|
258
|
+
if (
|
|
259
|
+
module &&
|
|
260
|
+
!moduleGraph.getExportsInfo(module).isExportProvided(this.value)
|
|
261
|
+
) {
|
|
262
|
+
const error = new WebpackError(
|
|
263
|
+
`Self-referencing name "${this.value}" not found`
|
|
264
|
+
);
|
|
265
|
+
error.module = module;
|
|
266
|
+
|
|
267
|
+
return [error];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
|
|
76
274
|
/**
|
|
77
275
|
* Update the hash
|
|
78
276
|
* @param {Hash} hash hash to be updated
|
|
@@ -88,11 +286,10 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
88
286
|
const names = this.getExportsConventionNames(
|
|
89
287
|
this.name,
|
|
90
288
|
/** @type {CssGeneratorExportsConvention} */
|
|
91
|
-
(generator.
|
|
289
|
+
(generator.options.exportsConvention)
|
|
92
290
|
);
|
|
93
|
-
this._hashUpdate = JSON.stringify(names)
|
|
291
|
+
this._hashUpdate = `exportsConvention|${JSON.stringify(names)}|localIdentName|${JSON.stringify(generator.options.localIdentName)}`;
|
|
94
292
|
}
|
|
95
|
-
hash.update("exportsConvention");
|
|
96
293
|
hash.update(this._hashUpdate);
|
|
97
294
|
}
|
|
98
295
|
|
|
@@ -103,6 +300,10 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
103
300
|
const { write } = context;
|
|
104
301
|
write(this.name);
|
|
105
302
|
write(this.value);
|
|
303
|
+
write(this.range);
|
|
304
|
+
write(this.interpolate);
|
|
305
|
+
write(this.exportMode);
|
|
306
|
+
write(this.exportType);
|
|
106
307
|
super.serialize(context);
|
|
107
308
|
}
|
|
108
309
|
|
|
@@ -113,6 +314,10 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
113
314
|
const { read } = context;
|
|
114
315
|
this.name = read();
|
|
115
316
|
this.value = read();
|
|
317
|
+
this.range = read();
|
|
318
|
+
this.interpolate = read();
|
|
319
|
+
this.exportMode = read();
|
|
320
|
+
this.exportType = read();
|
|
116
321
|
super.deserialize(context);
|
|
117
322
|
}
|
|
118
323
|
}
|
|
@@ -120,20 +325,106 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
120
325
|
CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends (
|
|
121
326
|
NullDependency.Template
|
|
122
327
|
) {
|
|
328
|
+
// TODO looking how to cache
|
|
329
|
+
/**
|
|
330
|
+
* @param {string} symbol the name of symbol
|
|
331
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
332
|
+
* @returns {string | undefined} found reference
|
|
333
|
+
*/
|
|
334
|
+
static findReference(symbol, templateContext) {
|
|
335
|
+
for (const item of templateContext.module.dependencies) {
|
|
336
|
+
if (item instanceof CssIcssImportDependency) {
|
|
337
|
+
// Looking for the referring module
|
|
338
|
+
const module = templateContext.moduleGraph.getModule(item);
|
|
339
|
+
|
|
340
|
+
if (!module) {
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
for (let i = module.dependencies.length - 1; i >= 0; i--) {
|
|
345
|
+
const nestedDep = module.dependencies[i];
|
|
346
|
+
if (
|
|
347
|
+
nestedDep instanceof CssIcssExportDependency &&
|
|
348
|
+
symbol === nestedDep.name
|
|
349
|
+
) {
|
|
350
|
+
if (Array.isArray(nestedDep.value)) {
|
|
351
|
+
return this.findReference(nestedDep.value[1], {
|
|
352
|
+
...templateContext,
|
|
353
|
+
module
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return CssIcssExportDependency.Template.getIdentifier(
|
|
358
|
+
nestedDep.value,
|
|
359
|
+
nestedDep,
|
|
360
|
+
{
|
|
361
|
+
...templateContext,
|
|
362
|
+
module
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* @param {string} value value to identifier
|
|
373
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
374
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
375
|
+
* @returns {string} identifier
|
|
376
|
+
*/
|
|
377
|
+
static getIdentifier(value, dependency, templateContext) {
|
|
378
|
+
const dep = /** @type {CssIcssExportDependency} */ (dependency);
|
|
379
|
+
|
|
380
|
+
if (dep.interpolate) {
|
|
381
|
+
const { module: m } = templateContext;
|
|
382
|
+
const module = /** @type {CssModule} */ (m);
|
|
383
|
+
const generator = /** @type {CssGenerator} */ (module.generator);
|
|
384
|
+
const local = cssExportConvention(
|
|
385
|
+
value,
|
|
386
|
+
/** @type {CssGeneratorExportsConvention} */
|
|
387
|
+
(generator.options.exportsConvention)
|
|
388
|
+
)[0];
|
|
389
|
+
const prefix =
|
|
390
|
+
dep.exportType === CssIcssExportDependency.EXPORT_TYPE.CUSTOM_VARIABLE
|
|
391
|
+
? "--"
|
|
392
|
+
: "";
|
|
393
|
+
|
|
394
|
+
return (
|
|
395
|
+
prefix +
|
|
396
|
+
getCssParser().escapeIdentifier(
|
|
397
|
+
getLocalIdent(
|
|
398
|
+
local,
|
|
399
|
+
/** @type {CssModule} */
|
|
400
|
+
(templateContext.module),
|
|
401
|
+
templateContext.chunkGraph,
|
|
402
|
+
templateContext.runtimeTemplate
|
|
403
|
+
)
|
|
404
|
+
)
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return /** @type {string} */ (dep.value);
|
|
409
|
+
}
|
|
410
|
+
|
|
123
411
|
/**
|
|
124
412
|
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
125
413
|
* @param {ReplaceSource} source the current replace source which can be modified
|
|
126
414
|
* @param {DependencyTemplateContext} templateContext the context object
|
|
127
415
|
* @returns {void}
|
|
128
416
|
*/
|
|
129
|
-
apply(dependency, source,
|
|
417
|
+
apply(dependency, source, templateContext) {
|
|
130
418
|
const dep = /** @type {CssIcssExportDependency} */ (dependency);
|
|
419
|
+
if (!dep.range && templateContext.type !== JAVASCRIPT_TYPE) return;
|
|
420
|
+
const { cssData } = templateContext;
|
|
421
|
+
const { module: m, moduleGraph, runtime } = templateContext;
|
|
131
422
|
const module = /** @type {CssModule} */ (m);
|
|
132
423
|
const generator = /** @type {CssGenerator} */ (module.generator);
|
|
133
424
|
const names = dep.getExportsConventionNames(
|
|
134
425
|
dep.name,
|
|
135
426
|
/** @type {CssGeneratorExportsConvention} */
|
|
136
|
-
(generator.
|
|
427
|
+
(generator.options.exportsConvention)
|
|
137
428
|
);
|
|
138
429
|
const usedNames =
|
|
139
430
|
/** @type {string[]} */
|
|
@@ -145,12 +436,98 @@ CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends
|
|
|
145
436
|
.filter(Boolean)
|
|
146
437
|
);
|
|
147
438
|
|
|
148
|
-
|
|
149
|
-
|
|
439
|
+
const allNames = new Set([...usedNames, ...names]);
|
|
440
|
+
const isReference = Array.isArray(dep.value);
|
|
441
|
+
|
|
442
|
+
/** @type {string} */
|
|
443
|
+
let value;
|
|
444
|
+
|
|
445
|
+
if (isReference && dep.value[2] === true) {
|
|
446
|
+
const resolved = CssIcssExportDependencyTemplate.findReference(
|
|
447
|
+
dep.value[1],
|
|
448
|
+
templateContext
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
// Fallback to the original name if not found
|
|
452
|
+
value = resolved || dep.value[0];
|
|
453
|
+
} else {
|
|
454
|
+
value = isReference ? dep.value[1] : /** @type {string} */ (dep.value);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (dep.interpolate) {
|
|
458
|
+
value = CssIcssExportDependencyTemplate.getIdentifier(
|
|
459
|
+
value,
|
|
460
|
+
dep,
|
|
461
|
+
templateContext
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (
|
|
466
|
+
dep.exportType ===
|
|
467
|
+
CssIcssExportDependency.EXPORT_TYPE.GRID_CUSTOM_IDENTIFIER
|
|
468
|
+
) {
|
|
469
|
+
value += `-${dep.name}`;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (
|
|
473
|
+
templateContext.type === JAVASCRIPT_TYPE &&
|
|
474
|
+
dep.exportMode !== CssIcssExportDependency.EXPORT_MODE.NONE
|
|
475
|
+
) {
|
|
476
|
+
for (const used of allNames) {
|
|
477
|
+
if (dep.exportMode === CssIcssExportDependency.EXPORT_MODE.ONCE) {
|
|
478
|
+
const newValue = getCssParser().unescapeIdentifier(value);
|
|
479
|
+
if (isReference) {
|
|
480
|
+
cssData.exports.set(dep.value[1], newValue);
|
|
481
|
+
}
|
|
482
|
+
if (cssData.exports.has(used)) return;
|
|
483
|
+
cssData.exports.set(used, newValue);
|
|
484
|
+
} else {
|
|
485
|
+
const originalValue =
|
|
486
|
+
dep.exportMode === CssIcssExportDependency.EXPORT_MODE.REPLACE
|
|
487
|
+
? undefined
|
|
488
|
+
: cssData.exports.get(used);
|
|
489
|
+
|
|
490
|
+
const newValue =
|
|
491
|
+
dep.exportMode ===
|
|
492
|
+
CssIcssExportDependency.EXPORT_MODE.SELF_REFERENCE
|
|
493
|
+
? cssData.exports.get(
|
|
494
|
+
isReference ? dep.value[0] : /** @type {string} */ (dep.value)
|
|
495
|
+
) || value
|
|
496
|
+
: getCssParser().unescapeIdentifier(value);
|
|
497
|
+
|
|
498
|
+
cssData.exports.set(
|
|
499
|
+
used,
|
|
500
|
+
`${originalValue ? `${originalValue}${newValue ? " " : ""}` : ""}${newValue}`
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
} else if (
|
|
505
|
+
dep.range &&
|
|
506
|
+
templateContext.type === CSS_TYPE &&
|
|
507
|
+
dep.exportMode !== CssIcssExportDependency.EXPORT_MODE.APPEND &&
|
|
508
|
+
dep.exportMode !== CssIcssExportDependency.EXPORT_MODE.SELF_REFERENCE
|
|
509
|
+
) {
|
|
510
|
+
source.replace(dep.range[0], dep.range[1] - 1, value);
|
|
150
511
|
}
|
|
151
512
|
}
|
|
152
513
|
};
|
|
153
514
|
|
|
515
|
+
/** @type {Record<"NONE" | "REPLACE" | "APPEND" | "ONCE" | "SELF_REFERENCE", ExportMode>} */
|
|
516
|
+
CssIcssExportDependency.EXPORT_MODE = {
|
|
517
|
+
NONE: 0,
|
|
518
|
+
REPLACE: 1,
|
|
519
|
+
APPEND: 2,
|
|
520
|
+
ONCE: 3,
|
|
521
|
+
SELF_REFERENCE: 4
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
/** @type {Record<"NORMAL" | "CUSTOM_VARIABLE" | "GRID_CUSTOM_IDENTIFIER", ExportType>} */
|
|
525
|
+
CssIcssExportDependency.EXPORT_TYPE = {
|
|
526
|
+
NORMAL: 0,
|
|
527
|
+
CUSTOM_VARIABLE: 1,
|
|
528
|
+
GRID_CUSTOM_IDENTIFIER: 2
|
|
529
|
+
};
|
|
530
|
+
|
|
154
531
|
makeSerializable(
|
|
155
532
|
CssIcssExportDependency,
|
|
156
533
|
"webpack/lib/dependencies/CssIcssExportDependency"
|