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.
Files changed (146) hide show
  1. package/README.md +121 -134
  2. package/lib/ChunkGraph.js +2 -2
  3. package/lib/CodeGenerationResults.js +1 -1
  4. package/lib/CompatibilityPlugin.js +25 -2
  5. package/lib/Compilation.js +30 -13
  6. package/lib/ConcatenationScope.js +0 -15
  7. package/lib/ContextModule.js +3 -1
  8. package/lib/CssModule.js +6 -1
  9. package/lib/DefinePlugin.js +12 -12
  10. package/lib/Dependency.js +8 -1
  11. package/lib/DependencyTemplate.js +1 -0
  12. package/lib/DependencyTemplates.js +1 -1
  13. package/lib/DotenvPlugin.js +457 -0
  14. package/lib/EnvironmentPlugin.js +19 -16
  15. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  16. package/lib/ExportsInfo.js +6 -2
  17. package/lib/ExternalModule.js +20 -28
  18. package/lib/ExternalModuleFactoryPlugin.js +10 -8
  19. package/lib/ExternalsPlugin.js +2 -1
  20. package/lib/FileSystemInfo.js +9 -12
  21. package/lib/ManifestPlugin.js +235 -0
  22. package/lib/Module.js +3 -0
  23. package/lib/ModuleFilenameHelpers.js +1 -1
  24. package/lib/ModuleGraph.js +2 -1
  25. package/lib/ModuleSourceTypesConstants.js +0 -6
  26. package/lib/MultiCompiler.js +1 -1
  27. package/lib/NodeStuffPlugin.js +419 -121
  28. package/lib/NormalModule.js +18 -17
  29. package/lib/NormalModuleFactory.js +75 -4
  30. package/lib/RuntimeGlobals.js +22 -4
  31. package/lib/RuntimePlugin.js +27 -6
  32. package/lib/RuntimeTemplate.js +125 -57
  33. package/lib/SourceMapDevToolPlugin.js +26 -8
  34. package/lib/WebpackOptionsApply.js +33 -9
  35. package/lib/asset/AssetBytesGenerator.js +2 -1
  36. package/lib/asset/AssetGenerator.js +3 -5
  37. package/lib/asset/AssetSourceGenerator.js +1 -1
  38. package/lib/cache/getLazyHashedEtag.js +1 -1
  39. package/lib/config/browserslistTargetHandler.js +82 -76
  40. package/lib/config/defaults.js +105 -20
  41. package/lib/config/normalization.js +2 -1
  42. package/lib/config/target.js +7 -1
  43. package/lib/css/CssGenerator.js +283 -57
  44. package/lib/css/CssLoadingRuntimeModule.js +2 -0
  45. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  46. package/lib/css/CssModulesPlugin.js +86 -40
  47. package/lib/css/CssParser.js +1174 -667
  48. package/lib/css/walkCssTokens.js +98 -1
  49. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  50. package/lib/dependencies/CommonJsPlugin.js +12 -0
  51. package/lib/dependencies/ContextElementDependency.js +2 -2
  52. package/lib/dependencies/CssIcssExportDependency.js +247 -8
  53. package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
  54. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
  55. package/lib/dependencies/CssIcssImportDependency.js +60 -54
  56. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
  57. package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
  58. package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
  59. package/lib/dependencies/CssImportDependency.js +15 -5
  60. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  61. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
  62. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  63. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  64. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  65. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
  66. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
  67. package/lib/dependencies/HarmonyImportDependency.js +27 -28
  68. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  69. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  71. package/lib/dependencies/ImportContextDependency.js +13 -0
  72. package/lib/dependencies/ImportDependency.js +10 -4
  73. package/lib/dependencies/ImportEagerDependency.js +6 -3
  74. package/lib/dependencies/ImportMetaPlugin.js +98 -10
  75. package/lib/dependencies/ImportParserPlugin.js +19 -21
  76. package/lib/dependencies/ImportPhase.js +121 -0
  77. package/lib/dependencies/ImportWeakDependency.js +6 -3
  78. package/lib/dependencies/ModuleDependency.js +5 -1
  79. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  80. package/lib/dependencies/WorkerPlugin.js +1 -3
  81. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  82. package/lib/hmr/LazyCompilationPlugin.js +1 -0
  83. package/lib/ids/HashedModuleIdsPlugin.js +5 -7
  84. package/lib/ids/IdHelpers.js +5 -2
  85. package/lib/index.js +6 -0
  86. package/lib/javascript/ChunkHelpers.js +16 -5
  87. package/lib/javascript/JavascriptGenerator.js +101 -101
  88. package/lib/javascript/JavascriptModulesPlugin.js +25 -16
  89. package/lib/javascript/JavascriptParser.js +143 -39
  90. package/lib/json/JsonParser.js +7 -1
  91. package/lib/library/ModuleLibraryPlugin.js +0 -10
  92. package/lib/library/SystemLibraryPlugin.js +19 -5
  93. package/lib/library/UmdLibraryPlugin.js +1 -1
  94. package/lib/node/NodeTargetPlugin.js +9 -1
  95. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  96. package/lib/optimize/ConcatenatedModule.js +161 -135
  97. package/lib/optimize/RealContentHashPlugin.js +5 -3
  98. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  99. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  100. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  101. package/lib/serialization/FileMiddleware.js +1 -1
  102. package/lib/serialization/ObjectMiddleware.js +1 -1
  103. package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
  104. package/lib/util/Hash.js +35 -5
  105. package/lib/util/comparators.js +4 -3
  106. package/lib/util/create-schema-validation.js +1 -1
  107. package/lib/util/createHash.js +85 -15
  108. package/lib/util/hash/BatchedHash.js +47 -8
  109. package/lib/util/hash/wasm-hash.js +53 -13
  110. package/lib/util/internalSerializables.js +4 -4
  111. package/lib/util/jsonParseEvenBetterErrors.js +10 -0
  112. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  113. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
  114. package/lib/wasm-async/AsyncWebAssemblyParser.js +0 -9
  115. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
  116. package/lib/wasm-sync/WebAssemblyParser.js +0 -9
  117. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  118. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  119. package/lib/webpack.js +85 -82
  120. package/module.d.ts +5 -0
  121. package/package.json +28 -26
  122. package/schemas/WebpackOptions.check.js +1 -1
  123. package/schemas/WebpackOptions.json +110 -15
  124. package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
  125. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  126. package/schemas/plugins/ManifestPlugin.json +98 -0
  127. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  128. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  129. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  130. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  131. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  132. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  133. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  134. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  135. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  136. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  137. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  138. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  139. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  140. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  141. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  142. package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
  143. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  144. package/types.d.ts +788 -127
  145. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -252
  146. package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
@@ -1,252 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Ivan Kopeykin @vankop
4
- */
5
-
6
- "use strict";
7
-
8
- const { cssExportConvention } = require("../util/conventions");
9
- const createHash = require("../util/createHash");
10
- const { makePathsRelative } = require("../util/identifier");
11
- const makeSerializable = require("../util/makeSerializable");
12
- const memoize = require("../util/memoize");
13
- const NullDependency = require("./NullDependency");
14
-
15
- /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
16
- /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
17
- /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
18
- /** @typedef {import("../ChunkGraph")} ChunkGraph */
19
- /** @typedef {import("../CssModule")} CssModule */
20
- /** @typedef {import("../Dependency")} Dependency */
21
- /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
22
- /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
23
- /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
24
- /** @typedef {import("../ModuleGraph")} ModuleGraph */
25
- /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
26
- /** @typedef {import("../css/CssGenerator")} CssGenerator */
27
- /** @typedef {import("../css/CssParser").Range} Range */
28
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
29
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
30
- /** @typedef {import("../util/Hash")} Hash */
31
-
32
- const getCssParser = memoize(() => require("../css/CssParser"));
33
-
34
- /**
35
- * @param {string} local css local
36
- * @param {CssModule} module module
37
- * @param {ChunkGraph} chunkGraph chunk graph
38
- * @param {RuntimeTemplate} runtimeTemplate runtime template
39
- * @returns {string} local ident
40
- */
41
- const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
42
- const generator = /** @type {CssGenerator} */ (module.generator);
43
- const localIdentName =
44
- /** @type {CssGeneratorLocalIdentName} */
45
- (generator.localIdentName);
46
- const relativeResourcePath = makePathsRelative(
47
- /** @type {string} */
48
- (module.context),
49
- /** @type {string} */
50
- (module.getResource()),
51
- runtimeTemplate.compilation.compiler.root
52
- );
53
- const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
54
- runtimeTemplate.outputOptions;
55
- const hash = createHash(hashFunction);
56
-
57
- if (hashSalt) {
58
- hash.update(hashSalt);
59
- }
60
-
61
- hash.update(relativeResourcePath);
62
-
63
- if (!/\[local\]/.test(localIdentName)) {
64
- hash.update(local);
65
- }
66
-
67
- const localIdentHash =
68
- /** @type {string} */
69
- (hash.digest(hashDigest)).slice(0, hashDigestLength);
70
-
71
- return runtimeTemplate.compilation
72
- .getPath(localIdentName, {
73
- filename: relativeResourcePath,
74
- hash: localIdentHash,
75
- contentHash: localIdentHash,
76
- chunkGraph,
77
- module
78
- })
79
- .replace(/\[local\]/g, local)
80
- .replace(/\[uniqueName\]/g, /** @type {string} */ (uniqueName))
81
- .replace(/^((-?[0-9])|--)/, "_$1");
82
- };
83
-
84
- class CssLocalIdentifierDependency extends NullDependency {
85
- /**
86
- * @param {string} name name
87
- * @param {Range} range range
88
- * @param {string=} prefix prefix
89
- */
90
- constructor(name, range, prefix = "") {
91
- super();
92
- this.name = name;
93
- this.range = range;
94
- this.prefix = prefix;
95
- this._conventionNames = undefined;
96
- this._hashUpdate = undefined;
97
- }
98
-
99
- get type() {
100
- return "css local identifier";
101
- }
102
-
103
- /**
104
- * @param {string} name export name
105
- * @param {CssGeneratorExportsConvention} convention convention of the export name
106
- * @returns {string[]} convention results
107
- */
108
- getExportsConventionNames(name, convention) {
109
- if (this._conventionNames) {
110
- return this._conventionNames;
111
- }
112
- this._conventionNames = cssExportConvention(this.name, convention);
113
- return this._conventionNames;
114
- }
115
-
116
- /**
117
- * Returns the exported names
118
- * @param {ModuleGraph} moduleGraph module graph
119
- * @returns {ExportsSpec | undefined} export names
120
- */
121
- getExports(moduleGraph) {
122
- const module = /** @type {CssModule} */ (moduleGraph.getParentModule(this));
123
- const generator = /** @type {CssGenerator} */ (module.generator);
124
- const names = this.getExportsConventionNames(
125
- this.name,
126
- /** @type {CssGeneratorExportsConvention} */ (generator.convention)
127
- );
128
- return {
129
- exports: names.map((name) => ({
130
- name,
131
- canMangle: true
132
- })),
133
- dependencies: undefined
134
- };
135
- }
136
-
137
- /**
138
- * Update the hash
139
- * @param {Hash} hash hash to be updated
140
- * @param {UpdateHashContext} context context
141
- * @returns {void}
142
- */
143
- updateHash(hash, { chunkGraph }) {
144
- if (this._hashUpdate === undefined) {
145
- const module =
146
- /** @type {CssModule} */
147
- (chunkGraph.moduleGraph.getParentModule(this));
148
- const generator = /** @type {CssGenerator} */ (module.generator);
149
- const names = this.getExportsConventionNames(
150
- this.name,
151
- /** @type {CssGeneratorExportsConvention} */
152
- (generator.convention)
153
- );
154
- this._hashUpdate = `exportsConvention|${JSON.stringify(names)}|localIdentName|${JSON.stringify(generator.localIdentName)}`;
155
- }
156
- hash.update(this._hashUpdate);
157
- }
158
-
159
- /**
160
- * @param {ObjectSerializerContext} context context
161
- */
162
- serialize(context) {
163
- const { write } = context;
164
- write(this.name);
165
- write(this.range);
166
- write(this.prefix);
167
- super.serialize(context);
168
- }
169
-
170
- /**
171
- * @param {ObjectDeserializerContext} context context
172
- */
173
- deserialize(context) {
174
- const { read } = context;
175
- this.name = read();
176
- this.range = read();
177
- this.prefix = read();
178
- super.deserialize(context);
179
- }
180
- }
181
-
182
- CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTemplate extends (
183
- NullDependency.Template
184
- ) {
185
- /**
186
- * @param {Dependency} dependency the dependency for which the template should be applied
187
- * @param {string} local local name
188
- * @param {DependencyTemplateContext} templateContext the context object
189
- * @returns {string} identifier
190
- */
191
- static getIdentifier(
192
- dependency,
193
- local,
194
- { module: m, chunkGraph, runtimeTemplate }
195
- ) {
196
- const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
197
- const module = /** @type {CssModule} */ (m);
198
-
199
- return (
200
- dep.prefix +
201
- getCssParser().escapeIdentifier(
202
- getLocalIdent(local, module, chunkGraph, runtimeTemplate)
203
- )
204
- );
205
- }
206
-
207
- /**
208
- * @param {Dependency} dependency the dependency for which the template should be applied
209
- * @param {ReplaceSource} source the current replace source which can be modified
210
- * @param {DependencyTemplateContext} templateContext the context object
211
- * @returns {void}
212
- */
213
- apply(dependency, source, templateContext) {
214
- const { module: m, moduleGraph, runtime, cssData } = templateContext;
215
- const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
216
- const module = /** @type {CssModule} */ (m);
217
- const generator = /** @type {CssGenerator} */ (module.generator);
218
- const names = dep.getExportsConventionNames(
219
- dep.name,
220
- /** @type {CssGeneratorExportsConvention} */
221
- (generator.convention)
222
- );
223
- const usedNames =
224
- /** @type {string[]} */
225
- (
226
- names
227
- .map((name) =>
228
- moduleGraph.getExportInfo(module, name).getUsedName(name, runtime)
229
- )
230
- .filter(Boolean)
231
- );
232
- const local = usedNames.length === 0 ? names[0] : usedNames[0];
233
- const identifier = CssLocalIdentifierDependencyTemplate.getIdentifier(
234
- dep,
235
- local,
236
- templateContext
237
- );
238
-
239
- source.replace(dep.range[0], dep.range[1] - 1, identifier);
240
-
241
- for (const used of [...usedNames, ...names]) {
242
- cssData.exports.set(used, getCssParser().unescapeIdentifier(identifier));
243
- }
244
- }
245
- };
246
-
247
- makeSerializable(
248
- CssLocalIdentifierDependency,
249
- "webpack/lib/dependencies/CssLocalIdentifierDependency"
250
- );
251
-
252
- module.exports = CssLocalIdentifierDependency;
@@ -1,6 +0,0 @@
1
- /*
2
- * This file was automatically generated.
3
- * DO NOT MODIFY BY HAND.
4
- * Run `yarn fix:special` to update
5
- */
6
- const t=/^(?:[A-Za-z]:[\\/]|\\\\|\/)/;function e(r,{instancePath:s="",parentData:n,parentDataProperty:a,rootData:i=r}={}){let o=null,l=0;if(0===l){if(!r||"object"!=typeof r||Array.isArray(r))return e.errors=[{params:{type:"object"}}],!1;{const s=l;for(const t in r)if("context"!==t&&"hashDigest"!==t&&"hashDigestLength"!==t&&"hashFunction"!==t)return e.errors=[{params:{additionalProperty:t}}],!1;if(s===l){if(void 0!==r.context){let s=r.context;const n=l;if(l===n){if("string"!=typeof s)return e.errors=[{params:{type:"string"}}],!1;if(s.includes("!")||!0!==t.test(s))return e.errors=[{params:{}}],!1}var u=n===l}else u=!0;if(u){if(void 0!==r.hashDigest){let t=r.hashDigest;const s=l;if("hex"!==t&&"latin1"!==t&&"base64"!==t)return e.errors=[{params:{}}],!1;u=s===l}else u=!0;if(u){if(void 0!==r.hashDigestLength){let t=r.hashDigestLength;const s=l;if(l===s){if("number"!=typeof t)return e.errors=[{params:{type:"number"}}],!1;if(t<1||isNaN(t))return e.errors=[{params:{comparison:">=",limit:1}}],!1}u=s===l}else u=!0;if(u)if(void 0!==r.hashFunction){let t=r.hashFunction;const s=l,n=l;let a=!1,i=null;const p=l,h=l;let c=!1;const m=l;if(l===m)if("string"==typeof t){if(t.length<1){const t={params:{}};null===o?o=[t]:o.push(t),l++}}else{const t={params:{type:"string"}};null===o?o=[t]:o.push(t),l++}var f=m===l;if(c=c||f,!c){const e=l;if(!(t instanceof Function)){const t={params:{}};null===o?o=[t]:o.push(t),l++}f=e===l,c=c||f}if(c)l=h,null!==o&&(h?o.length=h:o=null);else{const t={params:{}};null===o?o=[t]:o.push(t),l++}if(p===l&&(a=!0,i=0),!a){const t={params:{passingSchemas:i}};return null===o?o=[t]:o.push(t),l++,e.errors=o,!1}l=n,null!==o&&(n?o.length=n:o=null),u=s===l}else u=!0}}}}}return e.errors=o,0===l}module.exports=e,module.exports.default=e;