webpack 5.96.1 → 5.97.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.
Files changed (64) hide show
  1. package/lib/CssModule.js +5 -0
  2. package/lib/DependencyTemplate.js +2 -2
  3. package/lib/EvalSourceMapDevToolPlugin.js +5 -0
  4. package/lib/FalseIIFEUmdWarning.js +19 -0
  5. package/lib/HotModuleReplacementPlugin.js +4 -0
  6. package/lib/Module.js +6 -0
  7. package/lib/ModuleSourceTypesConstants.js +12 -0
  8. package/lib/NormalModule.js +1 -0
  9. package/lib/RuntimeTemplate.js +7 -0
  10. package/lib/SourceMapDevToolPlugin.js +8 -0
  11. package/lib/WebpackOptionsApply.js +3 -1
  12. package/lib/asset/AssetModulesPlugin.js +7 -2
  13. package/lib/config/defaults.js +52 -36
  14. package/lib/config/normalization.js +0 -1
  15. package/lib/config/target.js +8 -8
  16. package/lib/css/CssGenerator.js +139 -35
  17. package/lib/css/CssLoadingRuntimeModule.js +108 -198
  18. package/lib/css/CssModulesPlugin.js +78 -124
  19. package/lib/css/CssParser.js +545 -121
  20. package/lib/css/walkCssTokens.js +41 -19
  21. package/lib/dependencies/CachedConstDependency.js +2 -1
  22. package/lib/dependencies/ContextDependencyTemplateAsId.js +3 -2
  23. package/lib/dependencies/{CssExportDependency.js → CssIcssExportDependency.js} +35 -35
  24. package/lib/dependencies/CssIcssImportDependency.js +118 -0
  25. package/lib/dependencies/CssIcssSymbolDependency.js +132 -0
  26. package/lib/dependencies/CssImportDependency.js +0 -8
  27. package/lib/dependencies/CssLocalIdentifierDependency.js +69 -73
  28. package/lib/dependencies/CssUrlDependency.js +1 -0
  29. package/lib/esm/ModuleChunkFormatPlugin.js +8 -4
  30. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +17 -10
  31. package/lib/index.js +9 -3
  32. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -4
  33. package/lib/library/AssignLibraryPlugin.js +1 -1
  34. package/lib/library/EnableLibraryPlugin.js +17 -0
  35. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +81 -78
  36. package/lib/node/ReadFileCompileWasmPlugin.js +76 -57
  37. package/lib/optimize/MergeDuplicateChunksPlugin.js +22 -2
  38. package/lib/sharing/ConsumeSharedPlugin.js +35 -12
  39. package/lib/sharing/utils.js +35 -4
  40. package/lib/stats/DefaultStatsFactoryPlugin.js +0 -5
  41. package/lib/util/Queue.js +52 -24
  42. package/lib/util/generateDebugId.js +33 -0
  43. package/lib/util/internalSerializables.js +6 -2
  44. package/lib/wasm/EnableWasmLoadingPlugin.js +36 -25
  45. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +26 -2
  46. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +103 -0
  47. package/lib/wasm-sync/WebAssemblyParser.js +1 -1
  48. package/lib/web/FetchCompileAsyncWasmPlugin.js +43 -44
  49. package/lib/web/FetchCompileWasmPlugin.js +4 -4
  50. package/package.json +4 -4
  51. package/schemas/WebpackOptions.check.js +1 -1
  52. package/schemas/WebpackOptions.json +34 -12
  53. package/schemas/plugins/BannerPlugin.json +1 -1
  54. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  55. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  56. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  57. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  58. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  59. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  60. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +7 -0
  61. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +6 -0
  62. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.json +11 -0
  63. package/types.d.ts +84 -23
  64. package/lib/css/CssExportsGenerator.js +0 -207
@@ -1,207 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Sergey Melyukov @smelukov
4
- */
5
-
6
- "use strict";
7
-
8
- const { ReplaceSource, RawSource, ConcatSource } = require("webpack-sources");
9
- const { UsageState } = require("../ExportsInfo");
10
- const Generator = require("../Generator");
11
- const { JS_TYPES } = require("../ModuleSourceTypesConstants");
12
- const RuntimeGlobals = require("../RuntimeGlobals");
13
- const Template = require("../Template");
14
-
15
- /** @typedef {import("webpack-sources").Source} Source */
16
- /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
17
- /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
18
- /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
19
- /** @typedef {import("../Dependency")} Dependency */
20
- /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
21
- /** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
22
- /** @typedef {import("../Generator").GenerateContext} GenerateContext */
23
- /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
24
- /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
25
- /** @typedef {import("../Module").SourceTypes} SourceTypes */
26
- /** @typedef {import("../NormalModule")} NormalModule */
27
- /** @typedef {import("../util/Hash")} Hash */
28
-
29
- /**
30
- * @template T
31
- * @typedef {import("../InitFragment")<T>} InitFragment
32
- */
33
-
34
- class CssExportsGenerator extends Generator {
35
- /**
36
- * @param {CssGeneratorExportsConvention} convention the convention of the exports name
37
- * @param {CssGeneratorLocalIdentName} localIdentName css export local ident name
38
- * @param {boolean} esModule whether to use ES modules syntax
39
- */
40
- constructor(convention, localIdentName, esModule) {
41
- super();
42
- this.convention = convention;
43
- this.localIdentName = localIdentName;
44
- /** @type {boolean} */
45
- this.esModule = esModule;
46
- }
47
-
48
- /**
49
- * @param {NormalModule} module module for which the bailout reason should be determined
50
- * @param {ConcatenationBailoutReasonContext} context context
51
- * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
52
- */
53
- getConcatenationBailoutReason(module, context) {
54
- if (!this.esModule) {
55
- return "Module is not an ECMAScript module";
56
- }
57
- // TODO webpack 6: remove /\[moduleid\]/.test
58
- if (
59
- /\[id\]/.test(this.localIdentName) ||
60
- /\[moduleid\]/.test(this.localIdentName)
61
- ) {
62
- return "The localIdentName includes moduleId ([id] or [moduleid])";
63
- }
64
- return undefined;
65
- }
66
-
67
- /**
68
- * @param {NormalModule} module module for which the code should be generated
69
- * @param {GenerateContext} generateContext context for generate
70
- * @returns {Source | null} generated code
71
- */
72
- generate(module, generateContext) {
73
- const source = new ReplaceSource(new RawSource(""));
74
- /** @type {InitFragment<GenerateContext>[]} */
75
- const initFragments = [];
76
- /** @type {CssExportsData} */
77
- const cssExportsData = {
78
- esModule: this.esModule,
79
- exports: new Map()
80
- };
81
-
82
- generateContext.runtimeRequirements.add(RuntimeGlobals.module);
83
-
84
- /** @type {InitFragment<GenerateContext>[] | undefined} */
85
- let chunkInitFragments;
86
- const runtimeRequirements = new Set();
87
-
88
- /** @type {DependencyTemplateContext} */
89
- const templateContext = {
90
- runtimeTemplate: generateContext.runtimeTemplate,
91
- dependencyTemplates: generateContext.dependencyTemplates,
92
- moduleGraph: generateContext.moduleGraph,
93
- chunkGraph: generateContext.chunkGraph,
94
- module,
95
- runtime: generateContext.runtime,
96
- runtimeRequirements,
97
- concatenationScope: generateContext.concatenationScope,
98
- codeGenerationResults:
99
- /** @type {CodeGenerationResults} */
100
- (generateContext.codeGenerationResults),
101
- initFragments,
102
- cssExportsData,
103
- get chunkInitFragments() {
104
- if (!chunkInitFragments) {
105
- const data =
106
- /** @type {NonNullable<GenerateContext["getData"]>} */
107
- (generateContext.getData)();
108
- chunkInitFragments = data.get("chunkInitFragments");
109
- if (!chunkInitFragments) {
110
- chunkInitFragments = [];
111
- data.set("chunkInitFragments", chunkInitFragments);
112
- }
113
- }
114
-
115
- return chunkInitFragments;
116
- }
117
- };
118
-
119
- /**
120
- * @param {Dependency} dependency the dependency
121
- */
122
- const handleDependency = dependency => {
123
- const constructor = /** @type {new (...args: any[]) => Dependency} */ (
124
- dependency.constructor
125
- );
126
- const template = generateContext.dependencyTemplates.get(constructor);
127
- if (!template) {
128
- throw new Error(
129
- `No template for dependency: ${dependency.constructor.name}`
130
- );
131
- }
132
-
133
- template.apply(dependency, source, templateContext);
134
- };
135
-
136
- for (const dependency of module.dependencies) {
137
- handleDependency(dependency);
138
- }
139
-
140
- if (generateContext.concatenationScope) {
141
- const source = new ConcatSource();
142
- const usedIdentifiers = new Set();
143
- for (const [name, v] of cssExportsData.exports) {
144
- let identifier = Template.toIdentifier(name);
145
- const i = 0;
146
- while (usedIdentifiers.has(identifier)) {
147
- identifier = Template.toIdentifier(name + i);
148
- }
149
- usedIdentifiers.add(identifier);
150
- generateContext.concatenationScope.registerExport(name, identifier);
151
- source.add(
152
- `${
153
- generateContext.runtimeTemplate.supportsConst() ? "const" : "var"
154
- } ${identifier} = ${JSON.stringify(v)};\n`
155
- );
156
- }
157
- return source;
158
- }
159
- const needNsObj =
160
- this.esModule &&
161
- generateContext.moduleGraph
162
- .getExportsInfo(module)
163
- .otherExportsInfo.getUsed(generateContext.runtime) !==
164
- UsageState.Unused;
165
- if (needNsObj) {
166
- generateContext.runtimeRequirements.add(
167
- RuntimeGlobals.makeNamespaceObject
168
- );
169
- }
170
- const exports = [];
171
- for (const [name, v] of cssExportsData.exports) {
172
- exports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
173
- }
174
- return new RawSource(
175
- `${needNsObj ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
176
- module.moduleArgument
177
- }.exports = {\n${exports.join(",\n")}\n}${needNsObj ? ")" : ""};`
178
- );
179
- }
180
-
181
- /**
182
- * @param {NormalModule} module fresh module
183
- * @returns {SourceTypes} available types (do not mutate)
184
- */
185
- getTypes(module) {
186
- return JS_TYPES;
187
- }
188
-
189
- /**
190
- * @param {NormalModule} module the module
191
- * @param {string=} type source type
192
- * @returns {number} estimate size of the module
193
- */
194
- getSize(module, type) {
195
- return 42;
196
- }
197
-
198
- /**
199
- * @param {Hash} hash hash that will be modified
200
- * @param {UpdateHashContext} updateHashContext context for updating hash
201
- */
202
- updateHash(hash, { module }) {
203
- hash.update(this.esModule.toString());
204
- }
205
- }
206
-
207
- module.exports = CssExportsGenerator;