webpack 5.102.0 → 5.103.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/lib/ChunkGraph.js +2 -2
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +25 -2
- package/lib/Compilation.js +30 -13
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +3 -1
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +12 -12
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DotenvPlugin.js +457 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +20 -28
- package/lib/ExternalModuleFactoryPlugin.js +10 -8
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +9 -12
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +0 -6
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +419 -121
- package/lib/NormalModule.js +18 -17
- package/lib/NormalModuleFactory.js +75 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +125 -57
- package/lib/SourceMapDevToolPlugin.js +26 -8
- package/lib/WebpackOptionsApply.js +33 -9
- package/lib/asset/AssetBytesGenerator.js +2 -1
- package/lib/asset/AssetGenerator.js +3 -5
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/browserslistTargetHandler.js +82 -76
- package/lib/config/defaults.js +105 -20
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +7 -1
- package/lib/css/CssGenerator.js +283 -57
- package/lib/css/CssLoadingRuntimeModule.js +2 -0
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +86 -40
- package/lib/css/CssParser.js +1174 -667
- package/lib/css/walkCssTokens.js +98 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssIcssExportDependency.js +247 -8
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
- package/lib/dependencies/CssIcssImportDependency.js +60 -54
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
- package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
- package/lib/dependencies/CssImportDependency.js +15 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -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 +32 -21
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
- package/lib/dependencies/HarmonyImportDependency.js +27 -28
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportContextDependency.js +13 -0
- package/lib/dependencies/ImportDependency.js +10 -4
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaPlugin.js +98 -10
- package/lib/dependencies/ImportParserPlugin.js +19 -21
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +1 -3
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +5 -7
- package/lib/ids/IdHelpers.js +5 -2
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +101 -101
- package/lib/javascript/JavascriptModulesPlugin.js +25 -16
- package/lib/javascript/JavascriptParser.js +143 -39
- package/lib/json/JsonParser.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +0 -10
- package/lib/library/SystemLibraryPlugin.js +19 -5
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +161 -135
- package/lib/optimize/RealContentHashPlugin.js +5 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/serialization/FileMiddleware.js +1 -1
- package/lib/serialization/ObjectMiddleware.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
- package/lib/util/Hash.js +35 -5
- package/lib/util/comparators.js +4 -3
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +85 -15
- package/lib/util/hash/BatchedHash.js +47 -8
- package/lib/util/hash/wasm-hash.js +53 -13
- package/lib/util/internalSerializables.js +4 -4
- package/lib/util/jsonParseEvenBetterErrors.js +10 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
- package/lib/wasm-async/AsyncWebAssemblyParser.js +0 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
- package/lib/wasm-sync/WebAssemblyParser.js +0 -9
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +28 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +110 -15
- package/schemas/plugins/{HashedModuleIdsPlugin.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/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -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/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +788 -127
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -252
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
package/lib/css/walkCssTokens.js
CHANGED
|
@@ -66,7 +66,7 @@ const CC_LOWER_Z = "z".charCodeAt(0);
|
|
|
66
66
|
const CC_UPPER_A = "A".charCodeAt(0);
|
|
67
67
|
const CC_UPPER_F = "F".charCodeAt(0);
|
|
68
68
|
const CC_UPPER_E = "E".charCodeAt(0);
|
|
69
|
-
const CC_UPPER_U = "
|
|
69
|
+
const CC_UPPER_U = "U".charCodeAt(0);
|
|
70
70
|
const CC_UPPER_Z = "Z".charCodeAt(0);
|
|
71
71
|
const CC_0 = "0".charCodeAt(0);
|
|
72
72
|
const CC_9 = "9".charCodeAt(0);
|
|
@@ -1197,6 +1197,102 @@ module.exports = (input, pos = 0, callbacks = {}) => {
|
|
|
1197
1197
|
return pos;
|
|
1198
1198
|
};
|
|
1199
1199
|
|
|
1200
|
+
/**
|
|
1201
|
+
* @param {string} input input css
|
|
1202
|
+
* @param {number} pos pos
|
|
1203
|
+
* @param {CssTokenCallbacks} callbacks callbacks
|
|
1204
|
+
* @param {CssTokenCallbacks} additional additional callbacks
|
|
1205
|
+
* @param {{ onlyTopLevel?: boolean, declarationValue?: boolean, atRulePrelude?: boolean, functionValue?: boolean }=} options options
|
|
1206
|
+
* @returns {number} pos
|
|
1207
|
+
*/
|
|
1208
|
+
const consumeUntil = (input, pos, callbacks, additional, options = {}) => {
|
|
1209
|
+
let needHandle = true;
|
|
1210
|
+
let needTerminate = false;
|
|
1211
|
+
|
|
1212
|
+
/** @type {CssTokenCallbacks} */
|
|
1213
|
+
const servicedCallbacks = {};
|
|
1214
|
+
|
|
1215
|
+
let balanced = 0;
|
|
1216
|
+
|
|
1217
|
+
if (options.onlyTopLevel) {
|
|
1218
|
+
servicedCallbacks.function = (input, start, end) => {
|
|
1219
|
+
balanced++;
|
|
1220
|
+
if (!options.functionValue) {
|
|
1221
|
+
needHandle = false;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
if (additional.function !== undefined) {
|
|
1225
|
+
return additional.function(input, start, end);
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
return end;
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
servicedCallbacks.leftParenthesis = (_input, _start, end) => {
|
|
1232
|
+
balanced++;
|
|
1233
|
+
needHandle = false;
|
|
1234
|
+
return end;
|
|
1235
|
+
};
|
|
1236
|
+
servicedCallbacks.rightParenthesis = (_input, _start, end) => {
|
|
1237
|
+
balanced--;
|
|
1238
|
+
if (balanced === 0) {
|
|
1239
|
+
needHandle = true;
|
|
1240
|
+
}
|
|
1241
|
+
return end;
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
if (options.declarationValue) {
|
|
1246
|
+
servicedCallbacks.semicolon = (_input, _start, end) => {
|
|
1247
|
+
needTerminate = true;
|
|
1248
|
+
return end;
|
|
1249
|
+
};
|
|
1250
|
+
|
|
1251
|
+
servicedCallbacks.rightCurlyBracket = (_input, _start, end) => {
|
|
1252
|
+
needTerminate = true;
|
|
1253
|
+
return end;
|
|
1254
|
+
};
|
|
1255
|
+
} else if (options.functionValue) {
|
|
1256
|
+
servicedCallbacks.rightParenthesis = (_input, _start, end) => {
|
|
1257
|
+
balanced--;
|
|
1258
|
+
if (balanced === 0) {
|
|
1259
|
+
needTerminate = true;
|
|
1260
|
+
}
|
|
1261
|
+
return end;
|
|
1262
|
+
};
|
|
1263
|
+
} else if (options.atRulePrelude) {
|
|
1264
|
+
servicedCallbacks.leftCurlyBracket = (_input, _start, end) => {
|
|
1265
|
+
needTerminate = true;
|
|
1266
|
+
return end;
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
while (pos < input.length) {
|
|
1271
|
+
// Consume comments.
|
|
1272
|
+
pos = consumeComments(
|
|
1273
|
+
input,
|
|
1274
|
+
pos,
|
|
1275
|
+
needHandle ? { ...servicedCallbacks, ...callbacks } : servicedCallbacks
|
|
1276
|
+
);
|
|
1277
|
+
|
|
1278
|
+
const start = pos;
|
|
1279
|
+
|
|
1280
|
+
// Consume the next input code point.
|
|
1281
|
+
pos++;
|
|
1282
|
+
pos = consumeAToken(
|
|
1283
|
+
input,
|
|
1284
|
+
pos,
|
|
1285
|
+
needHandle ? { ...servicedCallbacks, ...callbacks } : servicedCallbacks
|
|
1286
|
+
);
|
|
1287
|
+
|
|
1288
|
+
if (needTerminate) {
|
|
1289
|
+
return start;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
return pos;
|
|
1294
|
+
};
|
|
1295
|
+
|
|
1200
1296
|
/**
|
|
1201
1297
|
* @param {string} input input
|
|
1202
1298
|
* @param {number} pos position
|
|
@@ -1608,6 +1704,7 @@ const eatUntil = (chars) => {
|
|
|
1608
1704
|
};
|
|
1609
1705
|
};
|
|
1610
1706
|
|
|
1707
|
+
module.exports.consumeUntil = consumeUntil;
|
|
1611
1708
|
module.exports.eatComments = eatComments;
|
|
1612
1709
|
module.exports.eatIdentSequence = eatIdentSequence;
|
|
1613
1710
|
module.exports.eatIdentSequenceOrString = eatIdentSequenceOrString;
|
|
@@ -126,15 +126,6 @@ class CommonJsImportsParserPlugin {
|
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
// #region Unsupported
|
|
129
|
-
parser.hooks.expression
|
|
130
|
-
.for("require.main")
|
|
131
|
-
.tap(
|
|
132
|
-
PLUGIN_NAME,
|
|
133
|
-
expressionIsUnsupported(
|
|
134
|
-
parser,
|
|
135
|
-
"require.main is not supported by webpack."
|
|
136
|
-
)
|
|
137
|
-
);
|
|
138
129
|
parser.hooks.call
|
|
139
130
|
.for("require.main.require")
|
|
140
131
|
.tap(
|
|
@@ -15,6 +15,7 @@ const SelfModuleFactory = require("../SelfModuleFactory");
|
|
|
15
15
|
const Template = require("../Template");
|
|
16
16
|
const {
|
|
17
17
|
evaluateToIdentifier,
|
|
18
|
+
expressionIsUnsupported,
|
|
18
19
|
toConstantDependency
|
|
19
20
|
} = require("../javascript/JavascriptParserHelpers");
|
|
20
21
|
const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
|
|
@@ -198,6 +199,17 @@ class CommonJsPlugin {
|
|
|
198
199
|
[RuntimeGlobals.moduleCache, RuntimeGlobals.entryModuleId]
|
|
199
200
|
)
|
|
200
201
|
);
|
|
202
|
+
|
|
203
|
+
parser.hooks.expression
|
|
204
|
+
.for("require.extensions")
|
|
205
|
+
.tap(
|
|
206
|
+
PLUGIN_NAME,
|
|
207
|
+
expressionIsUnsupported(
|
|
208
|
+
parser,
|
|
209
|
+
"require.extensions is not supported by webpack. Use a loader instead."
|
|
210
|
+
)
|
|
211
|
+
);
|
|
212
|
+
|
|
201
213
|
parser.hooks.expression
|
|
202
214
|
.for(RuntimeGlobals.moduleLoaded)
|
|
203
215
|
.tap(PLUGIN_NAME, (expr) => {
|
|
@@ -68,8 +68,8 @@ class ContextElementDependency extends ModuleDependency {
|
|
|
68
68
|
*/
|
|
69
69
|
getResourceIdentifier() {
|
|
70
70
|
let str = super.getResourceIdentifier();
|
|
71
|
-
if (this.attributes
|
|
72
|
-
str += JSON.stringify(this.attributes)
|
|
71
|
+
if (this.attributes) {
|
|
72
|
+
str += `|importAttributes${JSON.stringify(this.attributes)}`;
|
|
73
73
|
}
|
|
74
74
|
return str;
|
|
75
75
|
}
|
|
@@ -6,11 +6,18 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { cssExportConvention } = require("../util/conventions");
|
|
9
|
+
const createHash = require("../util/createHash");
|
|
10
|
+
const { makePathsRelative } = require("../util/identifier");
|
|
9
11
|
const makeSerializable = require("../util/makeSerializable");
|
|
12
|
+
const memoize = require("../util/memoize");
|
|
13
|
+
const CssIcssImportDependency = require("./CssIcssImportDependency");
|
|
10
14
|
const NullDependency = require("./NullDependency");
|
|
11
15
|
|
|
16
|
+
const getCssParser = memoize(() => require("../css/CssParser"));
|
|
17
|
+
|
|
12
18
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
13
19
|
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
|
20
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
|
|
14
21
|
/** @typedef {import("../CssModule")} CssModule */
|
|
15
22
|
/** @typedef {import("../Dependency")} Dependency */
|
|
16
23
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
|
@@ -21,16 +28,82 @@ const NullDependency = require("./NullDependency");
|
|
|
21
28
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
22
29
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
23
30
|
/** @typedef {import("../util/Hash")} Hash */
|
|
31
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
32
|
+
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
33
|
+
/** @typedef {import("../css/CssParser").Range} Range */
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} local css local
|
|
37
|
+
* @param {CssModule} module module
|
|
38
|
+
* @param {ChunkGraph} chunkGraph chunk graph
|
|
39
|
+
* @param {RuntimeTemplate} runtimeTemplate runtime template
|
|
40
|
+
* @returns {string} local ident
|
|
41
|
+
*/
|
|
42
|
+
const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
|
|
43
|
+
const generator = /** @type {CssGenerator} */ (module.generator);
|
|
44
|
+
const localIdentName =
|
|
45
|
+
/** @type {CssGeneratorLocalIdentName} */
|
|
46
|
+
(generator.localIdentName);
|
|
47
|
+
const relativeResourcePath = makePathsRelative(
|
|
48
|
+
/** @type {string} */
|
|
49
|
+
(module.context),
|
|
50
|
+
/** @type {string} */
|
|
51
|
+
(module.getResource()),
|
|
52
|
+
runtimeTemplate.compilation.compiler.root
|
|
53
|
+
);
|
|
54
|
+
const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
|
|
55
|
+
runtimeTemplate.outputOptions;
|
|
56
|
+
const hash = createHash(hashFunction);
|
|
57
|
+
|
|
58
|
+
if (hashSalt) {
|
|
59
|
+
hash.update(hashSalt);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
hash.update(relativeResourcePath);
|
|
63
|
+
|
|
64
|
+
if (!/\[local\]/.test(localIdentName)) {
|
|
65
|
+
hash.update(local);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength);
|
|
69
|
+
|
|
70
|
+
return runtimeTemplate.compilation
|
|
71
|
+
.getPath(localIdentName, {
|
|
72
|
+
filename: relativeResourcePath,
|
|
73
|
+
hash: localIdentHash,
|
|
74
|
+
contentHash: localIdentHash,
|
|
75
|
+
chunkGraph,
|
|
76
|
+
module
|
|
77
|
+
})
|
|
78
|
+
.replace(/\[local\]/g, local)
|
|
79
|
+
.replace(/\[uniqueName\]/g, /** @type {string} */ (uniqueName))
|
|
80
|
+
.replace(/^((-?[0-9])|--)/, "_$1");
|
|
81
|
+
};
|
|
82
|
+
// 0 - replace, 1 - append, 2 - once
|
|
83
|
+
/** @typedef {0 | 1 | 2} ExportMode */
|
|
84
|
+
// 0 - none, 1 - name, 1 - value
|
|
85
|
+
/** @typedef {0 | 1 | 2} InterpolationMode */
|
|
24
86
|
|
|
25
87
|
class CssIcssExportDependency extends NullDependency {
|
|
26
88
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
89
|
+
* Example of dependency:
|
|
90
|
+
*
|
|
91
|
+
* :export { LOCAL_NAME: EXPORT_NAME }
|
|
92
|
+
* @param {string} name export name
|
|
93
|
+
* @param {string} value export value or true when we need interpolate name as a value
|
|
94
|
+
* @param {string=} reexport reexport name
|
|
95
|
+
* @param {Range=} range range
|
|
29
96
|
*/
|
|
30
|
-
constructor(name, value) {
|
|
97
|
+
constructor(name, value, reexport, range) {
|
|
31
98
|
super();
|
|
32
99
|
this.name = name;
|
|
33
100
|
this.value = value;
|
|
101
|
+
this.reexport = reexport;
|
|
102
|
+
this.range = range;
|
|
103
|
+
/** @type {undefined | InterpolationMode} */
|
|
104
|
+
this.interpolationMode = undefined;
|
|
105
|
+
/** @type {ExportMode} */
|
|
106
|
+
this.exportMode = CssIcssExportDependency.EXPORT_MODE.REPLACE;
|
|
34
107
|
this._hashUpdate = undefined;
|
|
35
108
|
}
|
|
36
109
|
|
|
@@ -90,9 +163,8 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
90
163
|
/** @type {CssGeneratorExportsConvention} */
|
|
91
164
|
(generator.convention)
|
|
92
165
|
);
|
|
93
|
-
this._hashUpdate = JSON.stringify(names)
|
|
166
|
+
this._hashUpdate = `exportsConvention|${JSON.stringify(names)}|localIdentName|${JSON.stringify(generator.localIdentName)}`;
|
|
94
167
|
}
|
|
95
|
-
hash.update("exportsConvention");
|
|
96
168
|
hash.update(this._hashUpdate);
|
|
97
169
|
}
|
|
98
170
|
|
|
@@ -103,6 +175,10 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
103
175
|
const { write } = context;
|
|
104
176
|
write(this.name);
|
|
105
177
|
write(this.value);
|
|
178
|
+
write(this.reexport);
|
|
179
|
+
write(this.range);
|
|
180
|
+
write(this.interpolationMode);
|
|
181
|
+
write(this.exportMode);
|
|
106
182
|
super.serialize(context);
|
|
107
183
|
}
|
|
108
184
|
|
|
@@ -113,6 +189,10 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
113
189
|
const { read } = context;
|
|
114
190
|
this.name = read();
|
|
115
191
|
this.value = read();
|
|
192
|
+
this.reexport = read();
|
|
193
|
+
this.range = read();
|
|
194
|
+
this.interpolationMode = read();
|
|
195
|
+
this.exportMode = read();
|
|
116
196
|
super.deserialize(context);
|
|
117
197
|
}
|
|
118
198
|
}
|
|
@@ -120,14 +200,111 @@ class CssIcssExportDependency extends NullDependency {
|
|
|
120
200
|
CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends (
|
|
121
201
|
NullDependency.Template
|
|
122
202
|
) {
|
|
203
|
+
// TODO looking how to cache
|
|
204
|
+
/**
|
|
205
|
+
* @param {string} symbol the name of symbol
|
|
206
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
207
|
+
* @returns {string | undefined} found reference
|
|
208
|
+
*/
|
|
209
|
+
static findReference(symbol, templateContext) {
|
|
210
|
+
for (const item of templateContext.module.dependencies) {
|
|
211
|
+
if (item instanceof CssIcssImportDependency) {
|
|
212
|
+
// Looking for the referring module
|
|
213
|
+
const module = templateContext.moduleGraph.getModule(item);
|
|
214
|
+
|
|
215
|
+
if (!module) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
for (let i = module.dependencies.length - 1; i >= 0; i--) {
|
|
220
|
+
const nestedDep = module.dependencies[i];
|
|
221
|
+
if (
|
|
222
|
+
nestedDep instanceof CssIcssExportDependency &&
|
|
223
|
+
symbol === nestedDep.name
|
|
224
|
+
) {
|
|
225
|
+
if (nestedDep.reexport) {
|
|
226
|
+
return this.findReference(nestedDep.reexport, {
|
|
227
|
+
...templateContext,
|
|
228
|
+
module
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return CssIcssExportDependency.Template.getIdentifier(nestedDep, {
|
|
233
|
+
...templateContext,
|
|
234
|
+
module
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
244
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
245
|
+
* @returns {string} identifier
|
|
246
|
+
*/
|
|
247
|
+
static getIdentifier(dependency, templateContext) {
|
|
248
|
+
const dep = /** @type {CssIcssExportDependency} */ (dependency);
|
|
249
|
+
|
|
250
|
+
if (
|
|
251
|
+
dep.interpolationMode ===
|
|
252
|
+
CssIcssExportDependency.INTERPOLATION_MODE.NAME ||
|
|
253
|
+
dep.interpolationMode === CssIcssExportDependency.INTERPOLATION_MODE.VALUE
|
|
254
|
+
) {
|
|
255
|
+
const { module: m, moduleGraph, runtime } = templateContext;
|
|
256
|
+
const module = /** @type {CssModule} */ (m);
|
|
257
|
+
const generator = /** @type {CssGenerator} */ (module.generator);
|
|
258
|
+
const names = dep.getExportsConventionNames(
|
|
259
|
+
dep.interpolationMode ===
|
|
260
|
+
CssIcssExportDependency.INTERPOLATION_MODE.NAME
|
|
261
|
+
? dep.name
|
|
262
|
+
: dep.value,
|
|
263
|
+
/** @type {CssGeneratorExportsConvention} */
|
|
264
|
+
(generator.convention)
|
|
265
|
+
);
|
|
266
|
+
const usedNames =
|
|
267
|
+
/** @type {string[]} */
|
|
268
|
+
(
|
|
269
|
+
names
|
|
270
|
+
.map((name) =>
|
|
271
|
+
moduleGraph.getExportInfo(module, name).getUsedName(name, runtime)
|
|
272
|
+
)
|
|
273
|
+
.filter(Boolean)
|
|
274
|
+
);
|
|
275
|
+
const local = usedNames.length === 0 ? names[0] : usedNames[0];
|
|
276
|
+
const prefix =
|
|
277
|
+
/** @type {CssIcssExportDependency & { prefix: string }} */
|
|
278
|
+
(dependency).prefix;
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
(prefix || "") +
|
|
282
|
+
getCssParser().escapeIdentifier(
|
|
283
|
+
getLocalIdent(
|
|
284
|
+
local,
|
|
285
|
+
/** @type {CssModule} */
|
|
286
|
+
(templateContext.module),
|
|
287
|
+
templateContext.chunkGraph,
|
|
288
|
+
templateContext.runtimeTemplate
|
|
289
|
+
)
|
|
290
|
+
)
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return /** @type {string} */ (dep.value);
|
|
295
|
+
}
|
|
296
|
+
|
|
123
297
|
/**
|
|
124
298
|
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
125
299
|
* @param {ReplaceSource} source the current replace source which can be modified
|
|
126
300
|
* @param {DependencyTemplateContext} templateContext the context object
|
|
127
301
|
* @returns {void}
|
|
128
302
|
*/
|
|
129
|
-
apply(dependency, source,
|
|
303
|
+
apply(dependency, source, templateContext) {
|
|
130
304
|
const dep = /** @type {CssIcssExportDependency} */ (dependency);
|
|
305
|
+
if (!dep.range && templateContext.type !== "javascript") return;
|
|
306
|
+
const { cssData } = templateContext;
|
|
307
|
+
const { module: m, moduleGraph, runtime } = templateContext;
|
|
131
308
|
const module = /** @type {CssModule} */ (m);
|
|
132
309
|
const generator = /** @type {CssGenerator} */ (module.generator);
|
|
133
310
|
const names = dep.getExportsConventionNames(
|
|
@@ -145,12 +322,74 @@ CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends
|
|
|
145
322
|
.filter(Boolean)
|
|
146
323
|
);
|
|
147
324
|
|
|
148
|
-
|
|
149
|
-
|
|
325
|
+
const allNames = new Set([...usedNames, ...names]);
|
|
326
|
+
|
|
327
|
+
/** @type {string} */
|
|
328
|
+
let value;
|
|
329
|
+
|
|
330
|
+
if (dep.reexport) {
|
|
331
|
+
const resolved = CssIcssExportDependencyTemplate.findReference(
|
|
332
|
+
dep.reexport,
|
|
333
|
+
templateContext
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
if (resolved) {
|
|
337
|
+
dep.value = resolved;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (typeof dep.interpolationMode !== "undefined") {
|
|
342
|
+
value = CssIcssExportDependencyTemplate.getIdentifier(
|
|
343
|
+
dep,
|
|
344
|
+
templateContext
|
|
345
|
+
);
|
|
346
|
+
} else {
|
|
347
|
+
value = dep.value;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (templateContext.type === "javascript") {
|
|
351
|
+
for (const used of allNames) {
|
|
352
|
+
if (dep.exportMode === 2) {
|
|
353
|
+
if (cssData.exports.has(used)) return;
|
|
354
|
+
cssData.exports.set(
|
|
355
|
+
used,
|
|
356
|
+
`${getCssParser().unescapeIdentifier(value)}`
|
|
357
|
+
);
|
|
358
|
+
} else {
|
|
359
|
+
const originalValue =
|
|
360
|
+
dep.exportMode === 0 ? undefined : cssData.exports.get(used);
|
|
361
|
+
const newValue = getCssParser().unescapeIdentifier(value);
|
|
362
|
+
|
|
363
|
+
cssData.exports.set(
|
|
364
|
+
used,
|
|
365
|
+
`${originalValue ? `${originalValue}${newValue ? " " : ""}` : ""}${newValue}`
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
} else if (
|
|
370
|
+
dep.range &&
|
|
371
|
+
templateContext.type === "css" &&
|
|
372
|
+
dep.exportMode !== 1
|
|
373
|
+
) {
|
|
374
|
+
source.replace(dep.range[0], dep.range[1] - 1, value);
|
|
150
375
|
}
|
|
151
376
|
}
|
|
152
377
|
};
|
|
153
378
|
|
|
379
|
+
/** @type {Record<"REPLACE" | "APPEND" | "ONCE", ExportMode>} */
|
|
380
|
+
CssIcssExportDependency.EXPORT_MODE = {
|
|
381
|
+
REPLACE: 0,
|
|
382
|
+
APPEND: 1,
|
|
383
|
+
ONCE: 2
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
/** @type {Record<"NONE" | "NAME" | "VALUE", InterpolationMode>} */
|
|
387
|
+
CssIcssExportDependency.INTERPOLATION_MODE = {
|
|
388
|
+
NONE: 0,
|
|
389
|
+
NAME: 1,
|
|
390
|
+
VALUE: 2
|
|
391
|
+
};
|
|
392
|
+
|
|
154
393
|
makeSerializable(
|
|
155
394
|
CssIcssExportDependency,
|
|
156
395
|
"webpack/lib/dependencies/CssIcssExportDependency"
|
|
@@ -0,0 +1,124 @@
|
|
|
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 { cssExportConvention } = require("../util/conventions");
|
|
9
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
10
|
+
const CssIcssExportDependency = require("./CssIcssExportDependency");
|
|
11
|
+
const CssIcssImportDependency = require("./CssIcssImportDependency");
|
|
12
|
+
const ModuleDependency = require("./ModuleDependency");
|
|
13
|
+
|
|
14
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
15
|
+
/** @typedef {import("../Dependency")} Dependency */
|
|
16
|
+
/** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
|
|
17
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
18
|
+
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
|
19
|
+
/** @typedef {import("../Module")} Module */
|
|
20
|
+
/** @typedef {import("../CssModule")} CssModule */
|
|
21
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
22
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
23
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
24
|
+
/** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
|
|
25
|
+
/** @typedef {import("../css/CssGenerator")} CssGenerator */
|
|
26
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
27
|
+
|
|
28
|
+
class CssIcssFromIdentifierDependency extends CssIcssImportDependency {
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} request request request path which needs resolving
|
|
31
|
+
* @param {"local" | "global"} mode mode of the parsed CSS
|
|
32
|
+
* @param {Range} range the range of dependency
|
|
33
|
+
* @param {string} name import class name
|
|
34
|
+
* @param {string} exportName export class name
|
|
35
|
+
* @param {string=} prefix prefix
|
|
36
|
+
*/
|
|
37
|
+
constructor(request, mode, range, name, exportName, prefix) {
|
|
38
|
+
super(request, range, mode, name);
|
|
39
|
+
this.exportName = exportName;
|
|
40
|
+
this.value = name;
|
|
41
|
+
this.prefix = prefix;
|
|
42
|
+
this.interpolationMode = CssIcssExportDependency.INTERPOLATION_MODE.VALUE;
|
|
43
|
+
this.exportMode = CssIcssExportDependency.EXPORT_MODE.APPEND;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get type() {
|
|
47
|
+
return "css from identifier";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @returns {string | null} an identifier to merge equal requests
|
|
52
|
+
*/
|
|
53
|
+
getResourceIdentifier() {
|
|
54
|
+
return `${super.getResourceIdentifier()}|exportName${this.exportName}|prefix${this.prefix}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} name export name
|
|
59
|
+
* @param {CssGeneratorExportsConvention} convention convention of the export name
|
|
60
|
+
* @returns {string[]} convention results
|
|
61
|
+
*/
|
|
62
|
+
getExportsConventionNames(name, convention) {
|
|
63
|
+
return cssExportConvention(name, convention);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {ObjectSerializerContext} context context
|
|
68
|
+
*/
|
|
69
|
+
serialize(context) {
|
|
70
|
+
const { write } = context;
|
|
71
|
+
write(this.exportName);
|
|
72
|
+
write(this.prefix);
|
|
73
|
+
write(this.interpolationMode);
|
|
74
|
+
write(this.exportMode);
|
|
75
|
+
super.serialize(context);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {ObjectDeserializerContext} context context
|
|
80
|
+
*/
|
|
81
|
+
deserialize(context) {
|
|
82
|
+
const { read } = context;
|
|
83
|
+
this.exportName = read();
|
|
84
|
+
this.prefix = read();
|
|
85
|
+
this.interpolationMode = read();
|
|
86
|
+
this.exportMode = read();
|
|
87
|
+
super.deserialize(context);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
CssIcssFromIdentifierDependency.Template = class CssIcssFromIdentifierDependencyTemplate extends (
|
|
92
|
+
ModuleDependency.Template
|
|
93
|
+
) {
|
|
94
|
+
/**
|
|
95
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
96
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
97
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
98
|
+
* @returns {void}
|
|
99
|
+
*/
|
|
100
|
+
apply(dependency, source, templateContext) {
|
|
101
|
+
const { moduleGraph } = templateContext;
|
|
102
|
+
const dep = /** @type {CssIcssFromIdentifierDependency} */ (dependency);
|
|
103
|
+
const module =
|
|
104
|
+
/** @type {CssModule} */
|
|
105
|
+
(moduleGraph.getModule(dep));
|
|
106
|
+
|
|
107
|
+
if (!moduleGraph.getExportsInfo(module).isExportProvided(dep.name)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const template = new CssIcssExportDependency.Template();
|
|
112
|
+
const originalName = dep.name;
|
|
113
|
+
dep.name = dep.exportName;
|
|
114
|
+
template.apply(dep, source, { ...templateContext, module });
|
|
115
|
+
dep.name = originalName;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
makeSerializable(
|
|
120
|
+
CssIcssFromIdentifierDependency,
|
|
121
|
+
"webpack/lib/dependencies/CssIcssFromIdentifierDependency"
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
module.exports = CssIcssFromIdentifierDependency;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 makeSerializable = require("../util/makeSerializable");
|
|
9
|
+
const CssIcssExportDependency = require("./CssIcssExportDependency");
|
|
10
|
+
|
|
11
|
+
/** @typedef {import("../css/CssParser").Range} Range */
|
|
12
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
13
|
+
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
|
14
|
+
|
|
15
|
+
class CssIcssGlobalIdentifierDependency extends CssIcssExportDependency {
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} name export identifier name
|
|
18
|
+
* @param {string} value identifier value
|
|
19
|
+
* @param {string | undefined} reexport reexport name
|
|
20
|
+
* @param {Range} range the range of dependency
|
|
21
|
+
*/
|
|
22
|
+
constructor(name, value, reexport, range) {
|
|
23
|
+
super(name, value, reexport, range);
|
|
24
|
+
this.exportMode = CssIcssExportDependency.EXPORT_MODE.APPEND;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get type() {
|
|
28
|
+
return "css global identifier";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns the exported names
|
|
33
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
34
|
+
* @returns {ExportsSpec | undefined} export names
|
|
35
|
+
*/
|
|
36
|
+
getExports(moduleGraph) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
CssIcssGlobalIdentifierDependency.Template = CssIcssExportDependency.Template;
|
|
42
|
+
|
|
43
|
+
makeSerializable(
|
|
44
|
+
CssIcssGlobalIdentifierDependency,
|
|
45
|
+
"webpack/lib/dependencies/CssIcssGlobalDependency"
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
module.exports = CssIcssGlobalIdentifierDependency;
|