webpack 5.112.0 → 5.112.2
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/bin/webpack.js +13 -7
- package/lib/Compilation.js +198 -61
- package/lib/Compiler.js +12 -25
- package/lib/asset/AssetBytesGenerator.js +14 -6
- package/lib/asset/AssetBytesParser.js +10 -8
- package/lib/asset/AssetGenerator.js +36 -48
- package/lib/asset/AssetModule.js +11 -0
- package/lib/asset/AssetModulesPlugin.js +5 -4
- package/lib/asset/AssetParser.js +8 -8
- package/lib/asset/AssetSourceGenerator.js +16 -8
- package/lib/asset/AssetSourceParser.js +10 -8
- package/lib/asset/WebManifestGenerator.js +11 -6
- package/lib/asset/WebManifestParser.js +3 -3
- package/lib/async-modules/AsyncModuleHelpers.js +8 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
- package/lib/cache/CacheFacade.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +6 -10
- package/lib/cache/ResolverCachePlugin.js +58 -8
- package/lib/config/WebpackOptionsApply.js +8 -28
- package/lib/config/cli.js +9 -6
- package/lib/config/defaults.js +24 -13
- package/lib/config/getClaimedAssetTypes.js +2 -2
- package/lib/config/target.js +1 -1
- package/lib/context/ContextModule.js +1 -1
- package/lib/context/ContextModuleFactory.js +1 -1
- package/lib/context/ContextReplacementPlugin.js +3 -9
- package/lib/css/CssGenerator.js +40 -47
- package/lib/css/CssModule.js +10 -0
- package/lib/css/CssModulesPlugin.js +13 -6
- package/lib/css/CssParser.js +33 -32
- package/lib/css/conventions.js +1 -1
- package/lib/css/data.js +224 -219
- package/lib/css/syntax-parser.js +1312 -312
- package/lib/css/syntax-printer.js +1142 -1025
- package/lib/debug/ProfilingPlugin.js +65 -43
- package/lib/define/DefinePlugin.js +10 -15
- package/lib/define/DotenvPlugin.js +10 -6
- package/lib/define/EnvironmentPlugin.js +4 -2
- package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
- package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
- package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
- package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
- package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
- package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
- package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
- package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
- package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
- package/lib/dependencies/core/CachedConstDependency.js +9 -6
- package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
- package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
- package/lib/dependencies/css/CssUrlDependency.js +2 -6
- package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
- package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
- package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
- package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
- package/lib/dependencies/esm/ESMExports.js +2 -10
- package/lib/dependencies/esm/ESMImportDependency.js +17 -2
- package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
- package/lib/dependencies/esm/ESMImportGuard.js +11 -23
- package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
- package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
- package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
- package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
- package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
- package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
- package/lib/dependencies/helpers/DynamicExports.js +4 -6
- package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
- package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
- package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
- package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
- package/lib/dependencies/import/ImportParserPlugin.js +3 -6
- package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
- package/lib/dependencies/url/URLParserPlugin.js +1 -1
- package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
- package/lib/devtool/ModuleFilenameHelpers.js +1 -1
- package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
- package/lib/dll/DelegatedModule.js +3 -3
- package/lib/dll/DllModule.js +3 -1
- package/lib/dll/DllReferencePlugin.js +1 -4
- package/lib/errors/AbstractMethodError.js +1 -1
- package/lib/errors/ErrorHelpers.js +2 -1
- package/lib/errors/HookWebpackError.js +2 -1
- package/lib/errors/JSONParseError.js +4 -4
- package/lib/errors/WebpackError.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
- package/lib/externals/ExternalModule.js +12 -9
- package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
- package/lib/externals/ExternalsPlugin.js +1 -1
- package/lib/fs/FileSystemInfo.js +4 -4
- package/lib/graph/AsyncDependenciesBlock.js +1 -1
- package/lib/graph/ChunkGraph.js +5 -0
- package/lib/graph/Dependency.js +8 -2
- package/lib/graph/ExportsInfo.js +1 -1
- package/lib/graph/ModuleGraph.js +14 -3
- package/lib/graph/buildChunkGraph.js +17 -19
- package/lib/graph/findGraphRoots.js +1 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
- package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
- package/lib/hmr/LazyCompilationPlugin.js +1 -7
- package/lib/html/HtmlGenerator.js +25 -17
- package/lib/html/HtmlModule.js +11 -1
- package/lib/html/HtmlModulesPlugin.js +12 -11
- package/lib/html/HtmlParser.js +10 -9
- package/lib/html/builtinEmbeddedRenderer.js +31 -33
- package/lib/html/data.js +42 -21
- package/lib/html/htmlMinify.js +4 -1
- package/lib/html/syntax-parser.js +34 -35
- package/lib/html/syntax-printer.js +2 -3
- package/lib/html/xmlMinify.js +4 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -12
- package/lib/javascript/APIPlugin.js +7 -13
- package/lib/javascript/BasicEvaluatedExpression.js +5 -5
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
- package/lib/javascript/ConstPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +16 -11
- package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
- package/lib/javascript/JavascriptModule.js +10 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -4
- package/lib/javascript/JavascriptParser.js +99 -11
- package/lib/javascript/ScopeAnalyzer.js +183 -107
- package/lib/javascript/UseStrictPlugin.js +2 -5
- package/lib/javascript/jsMinify.js +1 -1
- package/lib/javascript/regexp.js +2 -2
- package/lib/javascript/syntax-parser.js +2114 -1506
- package/lib/javascript/syntax-printer-data.js +167 -1
- package/lib/javascript/syntax-printer.js +9554 -2782
- package/lib/json/JsonGenerator.js +15 -7
- package/lib/json/JsonModule.js +11 -0
- package/lib/json/JsonParser.js +7 -6
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +399 -23
- package/lib/loaders/LoaderRunner.js +76 -38
- package/lib/loaders/loadLoader.js +16 -10
- package/lib/module/Generator.js +17 -9
- package/lib/module/Module.js +2 -2
- package/lib/module/NormalModule.js +7 -5
- package/lib/module/NormalModuleFactory.js +11 -17
- package/lib/module/Parser.js +9 -2
- package/lib/module/extractSourceMap.js +69 -18
- package/lib/module/findCaseMismatch.js +2 -2
- package/lib/node/ExternalModuleInitFragment.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
- package/lib/node/nodeConsole.js +4 -3
- package/lib/optimize/CircularModulesPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +4 -8
- package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
- package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
- package/lib/optimize/InlineExports.js +4 -7
- package/lib/optimize/LazyBarrels.js +41 -5
- package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
- package/lib/optimize/RealContentHashPlugin.js +2 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
- package/lib/optimize/SplitChunksPlugin.js +11 -24
- package/lib/optimize/TupleQueue.js +1 -1
- package/lib/output/CleanPlugin.js +3 -1
- package/lib/output/CopyPlugin.js +3 -4
- package/lib/performance/EvalUsagePlugin.js +1 -3
- package/lib/performance/HotspotsPlugin.js +33 -9
- package/lib/performance/PureAnnotationsPlugin.js +16 -10
- package/lib/performance/TopLevelThisPlugin.js +17 -9
- package/lib/prefetch/ResourceHintPlugin.js +1 -1
- package/lib/provide/ProvidedDependency.js +36 -4
- package/lib/rules/BasicEffectRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +15 -5
- package/lib/rules/UseEffectRulePlugin.js +1 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
- package/lib/runtime/RuntimeGlobals.js +6 -0
- package/lib/runtime/RuntimePlugin.js +2 -0
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/schemes/VirtualUrlPlugin.js +3 -1
- package/lib/serialization/AggregateErrorSerializer.js +3 -3
- package/lib/serialization/BinaryMiddleware.js +4 -1
- package/lib/serialization/ErrorObjectSerializer.js +2 -5
- package/lib/serialization/ObjectMiddleware.js +17 -15
- package/lib/serialization/PlainObjectSerializer.js +3 -7
- package/lib/serialization/Serializer.js +21 -11
- package/lib/serialization/SerializerMiddleware.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
- package/lib/stats/StatsFactory.js +194 -24
- package/lib/stats/StatsPrinter.js +126 -13
- package/lib/template/DependencyTemplate.js +1 -1
- package/lib/template/RuntimeTemplate.js +13 -32
- package/lib/template/Template.js +1 -1
- package/lib/util/SourceProcessor.js +146 -29
- package/lib/util/WeakTupleMap.js +10 -4
- package/lib/util/cleverMerge.js +61 -33
- package/lib/util/comparators.js +9 -5
- package/lib/util/dataURL.js +2 -0
- package/lib/util/deprecation.js +4 -3
- package/lib/util/globUtils.js +1 -4
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/makeSerializable.js +6 -4
- package/lib/util/memoize.js +1 -1
- package/lib/util/parseJson.js +2 -2
- package/lib/util/serialization.js +31 -27
- package/lib/wasm/AsyncWasmModule.js +12 -2
- package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
- package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
- package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
- package/lib/wasm-sync/SyncWasmModule.js +16 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm-sync/WebAssemblyParser.js +10 -12
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
- package/lib/web/FetchCompileWasmPlugin.js +2 -6
- package/package.json +18 -19
- package/schemas/WebpackOptions.check.js +3 -3
- package/schemas/WebpackOptions.json +2 -2
- package/schemas/plugins/BannerPlugin.check.js +3 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
- package/schemas/plugins/HtmlParserOptions.check.js +3 -3
- package/schemas/plugins/IgnorePlugin.check.js +3 -3
- package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
- package/schemas/plugins/ManifestPlugin.check.js +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +3 -3
- package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
- package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
- package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
- package/schemas/plugins/container/ExternalsType.check.js +3 -3
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssParserOptions.check.js +3 -3
- package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
- package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
- package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.js +3 -3
- package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
- package/schemas/plugins/output/CleanOptions.check.js +7 -0
- package/schemas/plugins/output/CleanOptions.json +3 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
- package/types.d.ts +1482 -358
package/lib/css/CssGenerator.js
CHANGED
|
@@ -49,6 +49,7 @@ const CSS_TYPE_PREFIX = `${CSS_TYPE}/`;
|
|
|
49
49
|
|
|
50
50
|
const URL_SCHEME_REGEXP = /^(?:data|https?):/;
|
|
51
51
|
|
|
52
|
+
/** @import CssModule, { BuiltCssModule, CssNormalModule } from "./CssModule" */
|
|
52
53
|
/** @import { Source, RawSourceMap } from "webpack-sources" */
|
|
53
54
|
/**
|
|
54
55
|
* @import {
|
|
@@ -77,12 +78,6 @@ const URL_SCHEME_REGEXP = /^(?:data|https?):/;
|
|
|
77
78
|
/** @import NormalModule from "../module/NormalModule" */
|
|
78
79
|
/** @import Hash from "../util/Hash" */
|
|
79
80
|
/** @import { ModuleFactoryCacheEntry } from "./CssModulesPlugin" */
|
|
80
|
-
/**
|
|
81
|
-
* @import CssModule, {
|
|
82
|
-
* CssModuleBuildInfo,
|
|
83
|
-
* CssModuleBuildMeta
|
|
84
|
-
* } from "./CssModule"
|
|
85
|
-
*/
|
|
86
81
|
|
|
87
82
|
/** @typedef {{ line: number, column: number }} SourcePosition */
|
|
88
83
|
/** @typedef {Map<string, SourcePosition>} ExportLocsMap */
|
|
@@ -152,6 +147,14 @@ const buildExportsSourceMap = (
|
|
|
152
147
|
};
|
|
153
148
|
};
|
|
154
149
|
|
|
150
|
+
/**
|
|
151
|
+
* The module type the JSDoc inherited from `Generator` names.
|
|
152
|
+
* @typedef {CssNormalModule} TModule
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @extends {Generator<TModule>}
|
|
157
|
+
*/
|
|
155
158
|
class CssGenerator extends Generator {
|
|
156
159
|
/**
|
|
157
160
|
* Creates an instance of CssGenerator.
|
|
@@ -189,7 +192,7 @@ class CssGenerator extends Generator {
|
|
|
189
192
|
|
|
190
193
|
/**
|
|
191
194
|
* Returns the reason this module cannot be concatenated, when one exists.
|
|
192
|
-
* @param {
|
|
195
|
+
* @param {TModule} module module for which the bailout reason should be determined
|
|
193
196
|
* @param {ConcatenationBailoutReasonContext} context context
|
|
194
197
|
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
195
198
|
*/
|
|
@@ -224,7 +227,7 @@ class CssGenerator extends Generator {
|
|
|
224
227
|
|
|
225
228
|
/**
|
|
226
229
|
* Processes the provided module.
|
|
227
|
-
* @param {
|
|
230
|
+
* @param {TModule} module the module to generate
|
|
228
231
|
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
|
229
232
|
* @param {ReplaceSource} source the current replace source which can be modified
|
|
230
233
|
* @param {GenerateContext & { cssData: CssData }} generateContext the generateContext
|
|
@@ -233,7 +236,7 @@ class CssGenerator extends Generator {
|
|
|
233
236
|
sourceModule(module, initFragments, source, generateContext) {
|
|
234
237
|
// Only `dependency` varies across `template.apply` calls, so one context
|
|
235
238
|
// (and one lazy `chunkInitFragments` getter) serves the whole module.
|
|
236
|
-
/** @type {InitFragment<
|
|
239
|
+
/** @type {InitFragment<import("../javascript/JavascriptModulesPlugin").ChunkRenderContext>[] | undefined} */
|
|
237
240
|
let chunkInitFragments;
|
|
238
241
|
/** @type {CssDependencyTemplateContext} */
|
|
239
242
|
const templateContext = {
|
|
@@ -280,12 +283,13 @@ class CssGenerator extends Generator {
|
|
|
280
283
|
|
|
281
284
|
/**
|
|
282
285
|
* Generates generated code for this runtime module.
|
|
283
|
-
* @param {
|
|
286
|
+
* @param {TModule} module module for which the code should be generated
|
|
284
287
|
* @param {GenerateContext} generateContext context for generate
|
|
285
288
|
* @returns {Source | null} generated code
|
|
286
289
|
*/
|
|
287
290
|
generate(module, generateContext) {
|
|
288
291
|
const exportType = /** @type {CssModule} */ (module).exportType || "link";
|
|
292
|
+
const { buildInfo, buildMeta } = /** @type {BuiltCssModule} */ (module);
|
|
289
293
|
const source =
|
|
290
294
|
generateContext.type === JAVASCRIPT_TYPE && exportType === "link"
|
|
291
295
|
? new ReplaceSource(new RawSource(""))
|
|
@@ -314,8 +318,7 @@ class CssGenerator extends Generator {
|
|
|
314
318
|
case JAVASCRIPT_TYPE: {
|
|
315
319
|
const compilation = generateContext.runtimeTemplate.compilation;
|
|
316
320
|
const devtool = compilation.options.devtool;
|
|
317
|
-
const isCssModule =
|
|
318
|
-
.isCssModule;
|
|
321
|
+
const isCssModule = buildMeta.isCssModule;
|
|
319
322
|
|
|
320
323
|
const generateContentCode = () => {
|
|
321
324
|
switch (exportType) {
|
|
@@ -412,8 +415,7 @@ class CssGenerator extends Generator {
|
|
|
412
415
|
/** @type {Source | null} */
|
|
413
416
|
const defaultExport = generateJSDefaultExport();
|
|
414
417
|
|
|
415
|
-
|
|
416
|
-
(module.buildInfo).cssData = cssData;
|
|
418
|
+
buildInfo.cssData = cssData;
|
|
417
419
|
|
|
418
420
|
// Required for HMR
|
|
419
421
|
if (module.hot) {
|
|
@@ -575,7 +577,7 @@ class CssGenerator extends Generator {
|
|
|
575
577
|
// `SourceMapDevToolPlugin` can match the module and apply the
|
|
576
578
|
// devtool filename template instead of leaking this raw name
|
|
577
579
|
const sourceName = contextifySourceUrl(
|
|
578
|
-
|
|
580
|
+
compilation.options.context,
|
|
579
581
|
module.identifier(),
|
|
580
582
|
compilation.compiler.root
|
|
581
583
|
);
|
|
@@ -611,7 +613,7 @@ class CssGenerator extends Generator {
|
|
|
611
613
|
/**
|
|
612
614
|
* Generates fallback output for the provided error condition.
|
|
613
615
|
* @param {Error} error the error
|
|
614
|
-
* @param {
|
|
616
|
+
* @param {TModule} module module for which the code should be generated
|
|
615
617
|
* @param {GenerateContext} generateContext context for generate
|
|
616
618
|
* @returns {Source | null} generated code
|
|
617
619
|
*/
|
|
@@ -641,7 +643,7 @@ class CssGenerator extends Generator {
|
|
|
641
643
|
|
|
642
644
|
/**
|
|
643
645
|
* Returns the source types available for this module.
|
|
644
|
-
* @param {
|
|
646
|
+
* @param {TModule} module fresh module
|
|
645
647
|
* @returns {SourceTypes} available types (do not mutate)
|
|
646
648
|
*/
|
|
647
649
|
getTypes(module) {
|
|
@@ -684,16 +686,6 @@ class CssGenerator extends Generator {
|
|
|
684
686
|
continue;
|
|
685
687
|
}
|
|
686
688
|
|
|
687
|
-
// `importModule()` executes the module as JavaScript, and its dependency
|
|
688
|
-
// carries no origin module (`connectOrigin: false` in `LoaderPlugin`).
|
|
689
|
-
if (
|
|
690
|
-
connection.dependency !== null &&
|
|
691
|
-
isDependencyKind(connection.dependency, "loader-import")
|
|
692
|
-
) {
|
|
693
|
-
hasJs = true;
|
|
694
|
-
continue;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
689
|
if (!connection.originModule) {
|
|
698
690
|
continue;
|
|
699
691
|
}
|
|
@@ -730,22 +722,20 @@ class CssGenerator extends Generator {
|
|
|
730
722
|
|
|
731
723
|
/**
|
|
732
724
|
* Returns the estimated size for the requested source type.
|
|
733
|
-
* @param {
|
|
725
|
+
* @param {TModule} module the module
|
|
734
726
|
* @param {SourceType=} type source type
|
|
735
727
|
* @returns {number} estimate size of the module
|
|
736
728
|
*/
|
|
737
729
|
getSize(module, type) {
|
|
738
730
|
switch (type) {
|
|
739
731
|
case JAVASCRIPT_TYPE: {
|
|
740
|
-
const
|
|
741
|
-
|
|
732
|
+
const { buildInfo, buildMeta } = /** @type {BuiltCssModule} */ (module);
|
|
733
|
+
const cssData = buildInfo.cssData;
|
|
742
734
|
if (!cssData) {
|
|
743
735
|
return 42;
|
|
744
736
|
}
|
|
745
737
|
if (cssData.exports.size === 0) {
|
|
746
|
-
if (
|
|
747
|
-
/** @type {CssModuleBuildMeta} */ (module.buildMeta).isCssModule
|
|
748
|
-
) {
|
|
738
|
+
if (buildMeta.isCssModule) {
|
|
749
739
|
return 42;
|
|
750
740
|
}
|
|
751
741
|
return 0;
|
|
@@ -778,7 +768,7 @@ class CssGenerator extends Generator {
|
|
|
778
768
|
/**
|
|
779
769
|
* Updates the hash with the data contributed by this instance.
|
|
780
770
|
* @param {Hash} hash hash that will be modified
|
|
781
|
-
* @param {UpdateHashContext} updateHashContext context for updating hash
|
|
771
|
+
* @param {UpdateHashContext<TModule>} updateHashContext context for updating hash
|
|
782
772
|
*/
|
|
783
773
|
updateHash(hash, { module, runtimeTemplate }) {
|
|
784
774
|
hash.update(/** @type {boolean} */ (this._esModule).toString());
|
|
@@ -805,7 +795,7 @@ class CssGenerator extends Generator {
|
|
|
805
795
|
|
|
806
796
|
/**
|
|
807
797
|
* Resolve the effective `@charset` by walking text imports.
|
|
808
|
-
* @param {
|
|
798
|
+
* @param {TModule} module the module
|
|
809
799
|
* @param {ModuleGraph} moduleGraph module graph
|
|
810
800
|
* @param {WeakSet<NormalModule>=} visited cycle guard
|
|
811
801
|
* @returns {string | undefined} the effective charset
|
|
@@ -817,14 +807,12 @@ class CssGenerator extends Generator {
|
|
|
817
807
|
return undefined;
|
|
818
808
|
}
|
|
819
809
|
visited.add(module);
|
|
820
|
-
const own =
|
|
821
|
-
module.buildInfo &&
|
|
822
|
-
/** @type {CssModuleBuildInfo} */ (module.buildInfo).charset;
|
|
810
|
+
const own = module.buildInfo && module.buildInfo.charset;
|
|
823
811
|
if (own !== undefined) return own;
|
|
824
812
|
if (exportType !== "text") return undefined;
|
|
825
813
|
for (const dep of module.dependencies) {
|
|
826
814
|
if (isDependencyKind(dep, "css-import")) {
|
|
827
|
-
const depModule = /** @type {
|
|
815
|
+
const depModule = /** @type {BuiltCssModule} */ (
|
|
828
816
|
moduleGraph.getModule(dep)
|
|
829
817
|
);
|
|
830
818
|
const inherited = this._getEffectiveCharset(
|
|
@@ -840,7 +828,7 @@ class CssGenerator extends Generator {
|
|
|
840
828
|
|
|
841
829
|
/**
|
|
842
830
|
* Generate JS expressions for `@import` side effects (`style` exportType only).
|
|
843
|
-
* @param {
|
|
831
|
+
* @param {TModule} module the module to generate CSS text for
|
|
844
832
|
* @param {GenerateContext} generateContext the generate context
|
|
845
833
|
* @returns {string[]} JS expressions, one per `@import` dependency
|
|
846
834
|
*/
|
|
@@ -850,7 +838,10 @@ class CssGenerator extends Generator {
|
|
|
850
838
|
|
|
851
839
|
for (const dep of module.dependencies) {
|
|
852
840
|
if (!isDependencyKind(dep, "css-import")) continue;
|
|
853
|
-
const depModule = /** @type {CssModule} */ (
|
|
841
|
+
const depModule = /** @type {CssModule & BuiltCssModule} */ (
|
|
842
|
+
moduleGraph.getModule(dep)
|
|
843
|
+
);
|
|
844
|
+
if (!depModule) continue;
|
|
854
845
|
if (concatenationScope && concatenationScope.isModuleInScope(depModule)) {
|
|
855
846
|
continue;
|
|
856
847
|
}
|
|
@@ -870,7 +861,7 @@ class CssGenerator extends Generator {
|
|
|
870
861
|
|
|
871
862
|
/**
|
|
872
863
|
* Recursively merge `@import`'d CSS into a single Source (text/css-style-sheet only).
|
|
873
|
-
* @param {
|
|
864
|
+
* @param {TModule} module the module to render
|
|
874
865
|
* @param {GenerateContext} generateContext the generate context
|
|
875
866
|
* @param {Set<NormalModule>} ancestors modules on the current path (cycle guard)
|
|
876
867
|
* @returns {Source | null} merged CSS source, or null when the module has no content
|
|
@@ -885,7 +876,9 @@ class CssGenerator extends Generator {
|
|
|
885
876
|
|
|
886
877
|
for (const dep of module.dependencies) {
|
|
887
878
|
if (!isDependencyKind(dep, "css-import")) continue;
|
|
888
|
-
const depModule = /** @type {CssModule} */ (
|
|
879
|
+
const depModule = /** @type {CssModule & BuiltCssModule} */ (
|
|
880
|
+
moduleGraph.getModule(dep)
|
|
881
|
+
);
|
|
889
882
|
if (!depModule) continue;
|
|
890
883
|
const depExportType = depModule.exportType;
|
|
891
884
|
if (depExportType !== "text" && depExportType !== "css-style-sheet") {
|
|
@@ -912,7 +905,7 @@ class CssGenerator extends Generator {
|
|
|
912
905
|
|
|
913
906
|
/**
|
|
914
907
|
* Generate CSS source for the current module
|
|
915
|
-
* @param {
|
|
908
|
+
* @param {TModule} module the module to generate CSS source for
|
|
916
909
|
* @param {GenerateContext} generateContext the generate context
|
|
917
910
|
* @returns {Source | null} the CSS source
|
|
918
911
|
*/
|
|
@@ -957,7 +950,7 @@ class CssGenerator extends Generator {
|
|
|
957
950
|
const { compilation } = runtimeTemplate;
|
|
958
951
|
const outputOptions = compilation.outputOptions;
|
|
959
952
|
const absolutify = makePathsAbsolute.bindContextCache(
|
|
960
|
-
|
|
953
|
+
compilation.options.context,
|
|
961
954
|
compilation.compiler.root
|
|
962
955
|
);
|
|
963
956
|
const options = {
|
|
@@ -1013,7 +1006,7 @@ class CssGenerator extends Generator {
|
|
|
1013
1006
|
* Offer CSS bound for a JS string literal to `renderEmbeddedSource`. No `.css`
|
|
1014
1007
|
* asset carries this text, so an asset-level minimizer never sees it.
|
|
1015
1008
|
* @param {Source} cssSource the CSS source
|
|
1016
|
-
* @param {
|
|
1009
|
+
* @param {TModule} module the module
|
|
1017
1010
|
* @param {GenerateContext} generateContext the generate context
|
|
1018
1011
|
* @returns {Source} the source a tap returned, or the original
|
|
1019
1012
|
*/
|
|
@@ -1077,7 +1070,7 @@ class CssGenerator extends Generator {
|
|
|
1077
1070
|
/**
|
|
1078
1071
|
* Generate the merged CSS text for a module, optionally wrapped as a
|
|
1079
1072
|
* JS string literal for embedding in JavaScript output.
|
|
1080
|
-
* @param {
|
|
1073
|
+
* @param {TModule} module the module
|
|
1081
1074
|
* @param {GenerateContext} generateContext the generate context
|
|
1082
1075
|
* @param {boolean} asJsLiteral wrap the result as a JS string literal
|
|
1083
1076
|
* @returns {Source} the CSS text source
|
package/lib/css/CssModule.js
CHANGED
|
@@ -47,6 +47,16 @@ const makeSerializable = require("../util/makeSerializable");
|
|
|
47
47
|
|
|
48
48
|
/** @typedef {BuildMeta & KnownCssModuleBuildMeta} CssModuleBuildMeta */
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* A css module before or after its build, typed with its build info and build meta.
|
|
52
|
+
* @typedef {NormalModule & { buildInfo?: CssModuleBuildInfo, buildMeta?: CssModuleBuildMeta }} CssNormalModule
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A built css module, typed with its build info and build meta.
|
|
57
|
+
* @typedef {NormalModule & { buildInfo: CssModuleBuildInfo, buildMeta: CssModuleBuildMeta }} BuiltCssModule
|
|
58
|
+
*/
|
|
59
|
+
|
|
50
60
|
class CssModule extends NormalModule {
|
|
51
61
|
/**
|
|
52
62
|
* Creates an instance of CssModule.
|
|
@@ -567,7 +567,7 @@ class CssModulesPlugin {
|
|
|
567
567
|
return new CssModule(
|
|
568
568
|
/** @type {CssModuleCreateData} */
|
|
569
569
|
(
|
|
570
|
-
/** @type {
|
|
570
|
+
/** @type {Partial<CssModuleCreateData>} */ ({
|
|
571
571
|
...createData,
|
|
572
572
|
exportType
|
|
573
573
|
})
|
|
@@ -609,7 +609,7 @@ class CssModulesPlugin {
|
|
|
609
609
|
);
|
|
610
610
|
}
|
|
611
611
|
if (injectHMRCode) {
|
|
612
|
-
const currentModule =
|
|
612
|
+
const currentModule = rootModule;
|
|
613
613
|
const exportType = currentModule.exportType || "link";
|
|
614
614
|
// When exportType !== "link", modules behave like JavaScript modules
|
|
615
615
|
if (["link", "style"].includes(exportType)) {
|
|
@@ -904,6 +904,7 @@ class CssModulesPlugin {
|
|
|
904
904
|
|
|
905
905
|
// Get ordered list of modules per chunk group
|
|
906
906
|
// Lists are in reverse order to allow to use Array.pop()
|
|
907
|
+
const numberOfGroups = chunk.getNumberOfGroups();
|
|
907
908
|
const modulesByChunkGroup = Array.from(
|
|
908
909
|
chunk.groupsIterable,
|
|
909
910
|
(chunkGroup) => {
|
|
@@ -919,11 +920,14 @@ class CssModulesPlugin {
|
|
|
919
920
|
)
|
|
920
921
|
.map((item) => item.module);
|
|
921
922
|
|
|
922
|
-
return {
|
|
923
|
+
return {
|
|
924
|
+
list: sortedModules,
|
|
925
|
+
set: numberOfGroups > 1 ? new Set(sortedModules) : undefined
|
|
926
|
+
};
|
|
923
927
|
}
|
|
924
928
|
);
|
|
925
929
|
|
|
926
|
-
if (
|
|
930
|
+
if (numberOfGroups === 1) {
|
|
927
931
|
return modulesByChunkGroup[0].list.reverse();
|
|
928
932
|
}
|
|
929
933
|
|
|
@@ -967,7 +971,7 @@ class CssModulesPlugin {
|
|
|
967
971
|
if (list.length === 0) continue;
|
|
968
972
|
const lastModule = list[list.length - 1];
|
|
969
973
|
if (lastModule === selectedModule) continue;
|
|
970
|
-
if (!set.has(selectedModule)) continue;
|
|
974
|
+
if (!(/** @type {Set<Module>} */ (set).has(selectedModule))) continue;
|
|
971
975
|
failedModules.add(selectedModule);
|
|
972
976
|
if (failedModules.has(lastModule)) {
|
|
973
977
|
// There is a conflict, try other alternatives
|
|
@@ -1026,7 +1030,10 @@ class CssModulesPlugin {
|
|
|
1026
1030
|
const lastModule = list[list.length - 1];
|
|
1027
1031
|
if (lastModule === selectedModule) {
|
|
1028
1032
|
list.pop();
|
|
1029
|
-
} else if (
|
|
1033
|
+
} else if (
|
|
1034
|
+
hasFailed &&
|
|
1035
|
+
/** @type {Set<Module>} */ (set).has(selectedModule)
|
|
1036
|
+
) {
|
|
1030
1037
|
const idx = list.indexOf(selectedModule);
|
|
1031
1038
|
if (idx >= 0) list.splice(idx, 1);
|
|
1032
1039
|
}
|
package/lib/css/CssParser.js
CHANGED
|
@@ -63,14 +63,7 @@ const getCommentCompilationWarning = memoize(() =>
|
|
|
63
63
|
|
|
64
64
|
// `SourceProcessor` drives the parse and hands already-built AST nodes to the visitors; positions are read from those nodes' ranges rather than re-scanning the source.
|
|
65
65
|
|
|
66
|
-
/** @import {
|
|
67
|
-
/**
|
|
68
|
-
* @import CssModule, {
|
|
69
|
-
* CssModuleBuildInfo,
|
|
70
|
-
* CssModuleBuildMeta,
|
|
71
|
-
* Inheritance
|
|
72
|
-
* } from "./CssModule"
|
|
73
|
-
*/
|
|
66
|
+
/** @import CssModule, { BuiltCssModule, Inheritance } from "./CssModule" */
|
|
74
67
|
/** @import { ParserState, PreparsedAst } from "../module/Parser" */
|
|
75
68
|
/**
|
|
76
69
|
* @import {
|
|
@@ -851,6 +844,9 @@ const parseIcssImportRequest = (second, rule, source) => {
|
|
|
851
844
|
};
|
|
852
845
|
};
|
|
853
846
|
|
|
847
|
+
/**
|
|
848
|
+
* @extends {Parser<BuiltCssModule>}
|
|
849
|
+
*/
|
|
854
850
|
class CssParser extends Parser {
|
|
855
851
|
/**
|
|
856
852
|
* Creates an instance of CssParser.
|
|
@@ -1066,7 +1062,7 @@ class CssParser extends Parser {
|
|
|
1066
1062
|
);
|
|
1067
1063
|
};
|
|
1068
1064
|
|
|
1069
|
-
const module = state.module;
|
|
1065
|
+
const module = /** @type {CssModule & BuiltCssModule} */ (state.module);
|
|
1070
1066
|
|
|
1071
1067
|
// Every CSS Modules export declaration is tracked here so `_resolveAmbiguousExports` can arbitrate cross-kind collisions in one pass at end-of-parse: a class silently wins over CSS-scoped kinds (`@keyframes`, `@counter-style`, `@container`, custom property, grid identifier) — matching css-loader / lightning css / postcss-modules — while other pairs (`class` ↔ `id`, `class` ↔ `:export`, `class` ↔ `@value`, …) surface as a warning so the user can resolve them.
|
|
1072
1068
|
/** @typedef {{ kind: string, line: number, column: number, entries: number[] }} DeclarationOfKind */
|
|
@@ -1226,11 +1222,9 @@ class CssParser extends Parser {
|
|
|
1226
1222
|
});
|
|
1227
1223
|
const knownPropertyIndex = getKnownPropertyIndex(knownProperties);
|
|
1228
1224
|
|
|
1229
|
-
|
|
1230
|
-
(module.
|
|
1231
|
-
|
|
1232
|
-
/** @type {CssModuleBuildMeta} */
|
|
1233
|
-
(module.buildMeta).needIdInConcatenation = true;
|
|
1225
|
+
module.buildMeta.isCssModule = isModules;
|
|
1226
|
+
if (module.exportType === "style") {
|
|
1227
|
+
module.buildMeta.needIdInConcatenation = true;
|
|
1234
1228
|
}
|
|
1235
1229
|
|
|
1236
1230
|
const locConverter = new LocConverter(source);
|
|
@@ -4604,8 +4598,7 @@ class CssParser extends Parser {
|
|
|
4604
4598
|
(v) => A.type(v) !== NodeType.Whitespace
|
|
4605
4599
|
);
|
|
4606
4600
|
if (string && A.type(string) === NodeType.String) {
|
|
4607
|
-
|
|
4608
|
-
(module.buildInfo).charset = source
|
|
4601
|
+
module.buildInfo.charset = source
|
|
4609
4602
|
.slice(A.start(string) + 1, A.end(string) - 1)
|
|
4610
4603
|
.toUpperCase();
|
|
4611
4604
|
}
|
|
@@ -5022,7 +5015,18 @@ class CssParser extends Parser {
|
|
|
5022
5015
|
!(dashed.active && declIsDashed) &&
|
|
5023
5016
|
icssDefinitions.has(declName)
|
|
5024
5017
|
) {
|
|
5025
|
-
|
|
5018
|
+
// `themeColor: blue` names the same custom property that
|
|
5019
|
+
// `var(themeColor)` resolves to, so scope it under the dashed
|
|
5020
|
+
// name the value holds instead of substituting it verbatim.
|
|
5021
|
+
const dashedName =
|
|
5022
|
+
this.options.dashedIdents && effectiveLocalMode
|
|
5023
|
+
? localizableDashedValue(declName)
|
|
5024
|
+
: undefined;
|
|
5025
|
+
if (dashedName !== undefined) {
|
|
5026
|
+
emitNamedDashedIdentExport(dashedName, nameStart, nameEnd);
|
|
5027
|
+
} else {
|
|
5028
|
+
emitICSSSymbol(declName, nameStart, nameEnd);
|
|
5029
|
+
}
|
|
5026
5030
|
}
|
|
5027
5031
|
}
|
|
5028
5032
|
},
|
|
@@ -5310,25 +5314,22 @@ class CssParser extends Parser {
|
|
|
5310
5314
|
// `as` selects the top-level production of §5.3: a `style` attribute is a
|
|
5311
5315
|
// block's contents, anything else a full stylesheet. `as` and `skip` are
|
|
5312
5316
|
// per-parse, so only the per-source `locConverter` reaches `process`.
|
|
5313
|
-
new SourceProcessor()
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
?
|
|
5320
|
-
:
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
locConverter
|
|
5324
|
-
});
|
|
5317
|
+
new SourceProcessor().use(visitors).process(source, {
|
|
5318
|
+
as: /** @type {"stylesheet" | "block-contents"} */ (this.options.as),
|
|
5319
|
+
// Non-modules parses skip selector preludes, but `@custom-selector` expansion needs them, so keep them when the file may use one.
|
|
5320
|
+
skip: isModules
|
|
5321
|
+
? undefined
|
|
5322
|
+
: mayHaveCustomSelectors
|
|
5323
|
+
? SKIP_NON_MODULES_KEEP_SELECTORS
|
|
5324
|
+
: SKIP_NON_MODULES,
|
|
5325
|
+
locConverter
|
|
5326
|
+
});
|
|
5325
5327
|
|
|
5326
5328
|
if (customMediaQueries || customSelectorUses) {
|
|
5327
5329
|
resolveCustomMediaAndSelectors();
|
|
5328
5330
|
}
|
|
5329
5331
|
|
|
5330
|
-
|
|
5331
|
-
(module.buildInfo).strict = true;
|
|
5332
|
+
module.buildInfo.strict = true;
|
|
5332
5333
|
|
|
5333
5334
|
// Topologically sort the `composes … from` files and tag each file's first import dep with `sourceOrder` for cascade-correct load order (cycles keep their natural position).
|
|
5334
5335
|
if (composesFirstFileImport.size > 1) {
|
|
@@ -5342,7 +5343,7 @@ class CssParser extends Parser {
|
|
|
5342
5343
|
);
|
|
5343
5344
|
}
|
|
5344
5345
|
|
|
5345
|
-
const buildMeta =
|
|
5346
|
+
const buildMeta = module.buildMeta;
|
|
5346
5347
|
|
|
5347
5348
|
buildMeta.exportsType = this.options.namedExports ? "namespace" : "default";
|
|
5348
5349
|
buildMeta.defaultObject = this.options.namedExports
|
package/lib/css/conventions.js
CHANGED
|
@@ -87,7 +87,7 @@ module.exports.camelCase = (input) => {
|
|
|
87
87
|
/**
|
|
88
88
|
* Safely stringify an arbitrary value for an error message — falls back to
|
|
89
89
|
* `String(...)` when JSON.stringify would throw (BigInt, circular, etc.).
|
|
90
|
-
* @param {
|
|
90
|
+
* @param {string | string[]} value value to stringify
|
|
91
91
|
* @returns {string} stringified value
|
|
92
92
|
*/
|
|
93
93
|
const safeStringify = (value) => {
|