webpack 5.80.0 → 5.82.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (135) hide show
  1. package/bin/webpack.js +13 -2
  2. package/lib/AsyncDependenciesBlock.js +8 -0
  3. package/lib/CodeGenerationResults.js +2 -2
  4. package/lib/Compilation.js +4 -2
  5. package/lib/ContextModule.js +8 -0
  6. package/lib/CssModule.js +169 -0
  7. package/lib/DefinePlugin.js +81 -44
  8. package/lib/DelegatedModule.js +5 -0
  9. package/lib/DependenciesBlock.js +8 -0
  10. package/lib/Dependency.js +8 -0
  11. package/lib/DllModule.js +8 -0
  12. package/lib/ExportsInfo.js +3 -0
  13. package/lib/ExternalModule.js +8 -0
  14. package/lib/FileSystemInfo.js +8 -0
  15. package/lib/LoaderOptionsPlugin.js +12 -2
  16. package/lib/Module.js +8 -0
  17. package/lib/ModuleBuildError.js +9 -0
  18. package/lib/ModuleError.js +9 -0
  19. package/lib/ModuleFilenameHelpers.js +113 -4
  20. package/lib/ModuleParseError.js +9 -0
  21. package/lib/ModuleTypeConstants.js +21 -0
  22. package/lib/ModuleWarning.js +9 -0
  23. package/lib/NormalModule.js +8 -0
  24. package/lib/NormalModuleFactory.js +15 -3
  25. package/lib/RawModule.js +8 -0
  26. package/lib/WebpackError.js +8 -0
  27. package/lib/WebpackOptionsApply.js +33 -40
  28. package/lib/asset/RawDataUrlModule.js +8 -0
  29. package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
  30. package/lib/cache/ResolverCachePlugin.js +3 -0
  31. package/lib/config/defaults.js +1 -0
  32. package/lib/config/normalization.js +1 -0
  33. package/lib/container/ContainerEntryModule.js +5 -0
  34. package/lib/container/ContainerExposedDependency.js +9 -0
  35. package/lib/container/FallbackDependency.js +6 -0
  36. package/lib/container/FallbackModule.js +5 -0
  37. package/lib/container/RemoteModule.js +5 -0
  38. package/lib/css/CssGenerator.js +4 -0
  39. package/lib/css/CssLoadingRuntimeModule.js +9 -2
  40. package/lib/css/CssModulesPlugin.js +201 -57
  41. package/lib/css/CssParser.js +270 -147
  42. package/lib/css/walkCssTokens.js +121 -65
  43. package/lib/debug/ProfilingPlugin.js +2 -0
  44. package/lib/dependencies/AMDDefineDependency.js +8 -0
  45. package/lib/dependencies/AMDRequireArrayDependency.js +8 -0
  46. package/lib/dependencies/AMDRequireContextDependency.js +9 -0
  47. package/lib/dependencies/AMDRequireDependency.js +8 -0
  48. package/lib/dependencies/CachedConstDependency.js +8 -0
  49. package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
  50. package/lib/dependencies/CommonJsExportRequireDependency.js +8 -0
  51. package/lib/dependencies/CommonJsExportsDependency.js +8 -0
  52. package/lib/dependencies/CommonJsExportsParserPlugin.js +65 -3
  53. package/lib/dependencies/CommonJsFullRequireDependency.js +8 -0
  54. package/lib/dependencies/CommonJsRequireContextDependency.js +9 -0
  55. package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
  56. package/lib/dependencies/ConstDependency.js +8 -0
  57. package/lib/dependencies/ContextDependency.js +8 -0
  58. package/lib/dependencies/ContextElementDependency.js +8 -0
  59. package/lib/dependencies/CreateScriptUrlDependency.js +8 -0
  60. package/lib/dependencies/CssExportDependency.js +8 -0
  61. package/lib/dependencies/CssImportDependency.js +52 -1
  62. package/lib/dependencies/CssLocalIdentifierDependency.js +8 -0
  63. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +8 -0
  64. package/lib/dependencies/CssUrlDependency.js +8 -0
  65. package/lib/dependencies/DllEntryDependency.js +9 -0
  66. package/lib/dependencies/ExportsInfoDependency.js +5 -0
  67. package/lib/dependencies/HarmonyAcceptDependency.js +8 -0
  68. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +8 -0
  69. package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
  70. package/lib/dependencies/HarmonyExportHeaderDependency.js +8 -0
  71. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +14 -0
  72. package/lib/dependencies/HarmonyExportSpecifierDependency.js +8 -0
  73. package/lib/dependencies/HarmonyImportDependency.js +8 -0
  74. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -0
  75. package/lib/dependencies/HarmonyImportSpecifierDependency.js +8 -0
  76. package/lib/dependencies/ImportContextDependency.js +9 -0
  77. package/lib/dependencies/ImportDependency.js +8 -0
  78. package/lib/dependencies/JsonExportsDependency.js +8 -0
  79. package/lib/dependencies/LocalModuleDependency.js +8 -0
  80. package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
  81. package/lib/dependencies/ModuleDependency.js +8 -0
  82. package/lib/dependencies/ProvidedDependency.js +8 -0
  83. package/lib/dependencies/PureExpressionDependency.js +8 -0
  84. package/lib/dependencies/RequireEnsureDependency.js +8 -0
  85. package/lib/dependencies/RequireHeaderDependency.js +5 -0
  86. package/lib/dependencies/RequireResolveContextDependency.js +9 -0
  87. package/lib/dependencies/RequireResolveHeaderDependency.js +5 -0
  88. package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
  89. package/lib/dependencies/StaticExportsDependency.js +8 -0
  90. package/lib/dependencies/URLDependency.js +8 -0
  91. package/lib/dependencies/UnsupportedDependency.js +8 -0
  92. package/lib/dependencies/WebAssemblyExportImportedDependency.js +8 -0
  93. package/lib/dependencies/WebAssemblyImportDependency.js +8 -0
  94. package/lib/dependencies/WorkerDependency.js +8 -0
  95. package/lib/index.js +1 -0
  96. package/lib/javascript/BasicEvaluatedExpression.js +108 -1
  97. package/lib/javascript/JavascriptParser.js +133 -12
  98. package/lib/json/JsonData.js +25 -0
  99. package/lib/json/JsonGenerator.js +15 -3
  100. package/lib/json/JsonModulesPlugin.js +1 -0
  101. package/lib/json/JsonParser.js +2 -1
  102. package/lib/library/ModuleLibraryPlugin.js +2 -1
  103. package/lib/optimize/RealContentHashPlugin.js +6 -0
  104. package/lib/runtime/AutoPublicPathRuntimeModule.js +6 -1
  105. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  106. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +22 -3
  107. package/lib/schemes/DataUriPlugin.js +4 -0
  108. package/lib/schemes/HttpUriPlugin.js +38 -0
  109. package/lib/serialization/ObjectMiddleware.js +2 -0
  110. package/lib/sharing/ConsumeSharedModule.js +8 -0
  111. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -3
  112. package/lib/sharing/ProvideSharedDependency.js +6 -0
  113. package/lib/sharing/ProvideSharedModule.js +5 -0
  114. package/lib/sharing/ShareRuntimeModule.js +7 -4
  115. package/lib/sharing/utils.js +293 -7
  116. package/lib/stats/DefaultStatsPrinterPlugin.js +25 -0
  117. package/lib/util/LazySet.js +10 -2
  118. package/lib/util/MapHelpers.js +19 -5
  119. package/lib/util/StackedCacheMap.js +6 -0
  120. package/lib/util/StringXor.js +51 -0
  121. package/lib/util/binarySearchBounds.js +49 -0
  122. package/lib/util/compileBooleanMatcher.js +31 -0
  123. package/lib/util/deprecation.js +8 -0
  124. package/lib/util/identifier.js +4 -0
  125. package/lib/util/internalSerializables.js +1 -0
  126. package/lib/util/numberHash.js +75 -21
  127. package/lib/util/propertyAccess.js +5 -0
  128. package/lib/util/semver.js +1 -1
  129. package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
  130. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -0
  131. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  132. package/package.json +4 -5
  133. package/schemas/WebpackOptions.check.js +1 -1
  134. package/schemas/WebpackOptions.json +33 -0
  135. package/types.d.ts +176 -48
@@ -5,10 +5,18 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /**
9
+ * @param {string} str string
10
+ * @returns {string} quoted meta
11
+ */
8
12
  const quoteMeta = str => {
9
13
  return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
10
14
  };
11
15
 
16
+ /**
17
+ * @param {string} str string
18
+ * @returns {string} string
19
+ */
12
20
  const toSimpleString = str => {
13
21
  if (`${+str}` === str) {
14
22
  return str;
@@ -49,19 +57,28 @@ const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => {
49
57
  }
50
58
  };
51
59
 
60
+ /**
61
+ * @param {Set<string>} itemsSet items set
62
+ * @param {(str: string) => string | false} getKey get key function
63
+ * @param {(str: Array<string>) => boolean} condition condition
64
+ * @returns {Array<Array<string>>} list of common items
65
+ */
52
66
  const popCommonItems = (itemsSet, getKey, condition) => {
67
+ /** @type {Map<string, Array<string>>} */
53
68
  const map = new Map();
54
69
  for (const item of itemsSet) {
55
70
  const key = getKey(item);
56
71
  if (key) {
57
72
  let list = map.get(key);
58
73
  if (list === undefined) {
74
+ /** @type {Array<string>} */
59
75
  list = [];
60
76
  map.set(key, list);
61
77
  }
62
78
  list.push(item);
63
79
  }
64
80
  }
81
+ /** @type {Array<Array<string>>} */
65
82
  const result = [];
66
83
  for (const list of map.values()) {
67
84
  if (condition(list)) {
@@ -74,6 +91,10 @@ const popCommonItems = (itemsSet, getKey, condition) => {
74
91
  return result;
75
92
  };
76
93
 
94
+ /**
95
+ * @param {Array<string>} items items
96
+ * @returns {string} common prefix
97
+ */
77
98
  const getCommonPrefix = items => {
78
99
  let prefix = items[0];
79
100
  for (let i = 1; i < items.length; i++) {
@@ -88,6 +109,10 @@ const getCommonPrefix = items => {
88
109
  return prefix;
89
110
  };
90
111
 
112
+ /**
113
+ * @param {Array<string>} items items
114
+ * @returns {string} common suffix
115
+ */
91
116
  const getCommonSuffix = items => {
92
117
  let suffix = items[0];
93
118
  for (let i = 1; i < items.length; i++) {
@@ -102,10 +127,15 @@ const getCommonSuffix = items => {
102
127
  return suffix;
103
128
  };
104
129
 
130
+ /**
131
+ * @param {Array<string>} itemsArr array of items
132
+ * @returns {string} regexp
133
+ */
105
134
  const itemsToRegexp = itemsArr => {
106
135
  if (itemsArr.length === 1) {
107
136
  return quoteMeta(itemsArr[0]);
108
137
  }
138
+ /** @type {Array<string>} */
109
139
  const finishedItems = [];
110
140
 
111
141
  // merge single char items: (a|b|c|d|ef) => ([abcd]|ef)
@@ -146,6 +176,7 @@ const itemsToRegexp = itemsArr => {
146
176
 
147
177
  // special case for 2 items with common suffix
148
178
  if (finishedItems.length === 0 && items.size === 2) {
179
+ /** @type {Iterator<string>} */
149
180
  const it = items[Symbol.iterator]();
150
181
  const a = it.next().value;
151
182
  const b = it.next().value;
@@ -178,6 +178,14 @@ exports.createArrayToSetDeprecationSet = name => {
178
178
  return SetDeprecatedArray;
179
179
  };
180
180
 
181
+ /**
182
+ * @template T
183
+ * @param {Object} obj object
184
+ * @param {string} name property name
185
+ * @param {string} code deprecation code
186
+ * @param {string} note additional note
187
+ * @returns {Object} frozen object with deprecation when modifying
188
+ */
181
189
  exports.soonFrozenObjectDeprecation = (obj, name, code, note = "") => {
182
190
  const message = `${name} will be frozen in future, all modifications are deprecated.${
183
191
  note && `\n${note}`
@@ -15,6 +15,10 @@ const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
15
15
  * @property {Map<string, Map<string, string>>=} relativePaths
16
16
  */
17
17
 
18
+ /**
19
+ * @param {string} relativePath relative path
20
+ * @returns {string} request
21
+ */
18
22
  const relativePathToRequest = relativePath => {
19
23
  if (relativePath === "") return "./.";
20
24
  if (relativePath === "..") return "../.";
@@ -189,6 +189,7 @@ module.exports = {
189
189
  ModuleParseError: () => require("../ModuleParseError"),
190
190
  ModuleWarning: () => require("../ModuleWarning"),
191
191
  NormalModule: () => require("../NormalModule"),
192
+ CssModule: () => require("../CssModule"),
192
193
  RawDataUrlModule: () => require("../asset/RawDataUrlModule"),
193
194
  RawModule: () => require("../RawModule"),
194
195
  "sharing/ConsumeSharedModule": () =>
@@ -5,41 +5,95 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /**
9
+ * The maximum safe integer value for 32-bit integers.
10
+ * @type {number}
11
+ */
8
12
  const SAFE_LIMIT = 0x80000000;
13
+
14
+ /**
15
+ * The maximum safe integer value for 32-bit integers minus one. This is used
16
+ * in the algorithm to ensure that intermediate hash values do not exceed the
17
+ * 32-bit integer limit.
18
+ * @type {number}
19
+ */
9
20
  const SAFE_PART = SAFE_LIMIT - 1;
21
+
22
+ /**
23
+ * The number of 32-bit integers used to store intermediate hash values.
24
+ * @type {number}
25
+ */
10
26
  const COUNT = 4;
27
+
28
+ /**
29
+ * An array used to store intermediate hash values during the calculation.
30
+ * @type {number[]}
31
+ */
11
32
  const arr = [0, 0, 0, 0, 0];
33
+
34
+ /**
35
+ * An array of prime numbers used in the hash calculation.
36
+ * @type {number[]}
37
+ */
12
38
  const primes = [3, 7, 17, 19];
13
39
 
40
+ /**
41
+ * Computes a hash value for the given string and range. This hashing algorithm is a modified
42
+ * version of the [FNV-1a algorithm](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function).
43
+ * It is optimized for speed and does **not** generate a cryptographic hash value.
44
+ *
45
+ * We use `numberHash` in `lib/ids/IdHelpers.js` to generate hash values for the module identifier. The generated
46
+ * hash is used as a prefix for the module id's to avoid collisions with other modules.
47
+ *
48
+ * @param {string} str The input string to hash.
49
+ * @param {number} range The range of the hash value (0 to range-1).
50
+ * @returns {number} - The computed hash value.
51
+ *
52
+ * @example
53
+ *
54
+ * ```js
55
+ * const numberHash = require("webpack/lib/util/numberHash");
56
+ * numberHash("hello", 1000); // 57
57
+ * numberHash("hello world"); // 990
58
+ * ```
59
+ *
60
+ */
14
61
  module.exports = (str, range) => {
62
+ /**
63
+ * Initialize the array with zeros before it is used
64
+ * to store intermediate hash values.
65
+ */
15
66
  arr.fill(0);
67
+ // For each character in the string
16
68
  for (let i = 0; i < str.length; i++) {
69
+ // Get the character code.
17
70
  const c = str.charCodeAt(i);
18
- for (let j = 0; j < COUNT; j++) {
19
- const p = (j + COUNT - 1) % COUNT;
20
- arr[j] = (arr[j] + c * primes[j] + arr[p]) & SAFE_PART;
21
- }
22
- for (let j = 0; j < COUNT; j++) {
23
- const q = arr[j] % COUNT;
24
- arr[j] = arr[j] ^ (arr[q] >> 1);
25
- }
71
+
72
+ // For each 32-bit integer used to store the hash value
73
+ // add the character code to the current hash value and multiply by the prime number and
74
+ // add the previous 32-bit integer.
75
+ arr[0] = (arr[0] + c * primes[0] + arr[3]) & SAFE_PART;
76
+ arr[1] = (arr[1] + c * primes[1] + arr[0]) & SAFE_PART;
77
+ arr[2] = (arr[2] + c * primes[2] + arr[1]) & SAFE_PART;
78
+ arr[3] = (arr[3] + c * primes[3] + arr[2]) & SAFE_PART;
79
+
80
+ // For each 32-bit integer used to store the hash value
81
+ // XOR the current hash value with the value of the next 32-bit integer.
82
+ arr[0] = arr[0] ^ (arr[arr[0] % COUNT] >> 1);
83
+ arr[1] = arr[1] ^ (arr[arr[1] % COUNT] >> 1);
84
+ arr[2] = arr[2] ^ (arr[arr[2] % COUNT] >> 1);
85
+ arr[3] = arr[3] ^ (arr[arr[3] % COUNT] >> 1);
26
86
  }
87
+
27
88
  if (range <= SAFE_PART) {
28
- let sum = 0;
29
- for (let j = 0; j < COUNT; j++) {
30
- sum = (sum + arr[j]) % range;
31
- }
32
- return sum;
89
+ return (arr[0] + arr[1] + arr[2] + arr[3]) % range;
33
90
  } else {
34
- let sum1 = 0;
35
- let sum2 = 0;
91
+ // Calculate the range extension.
36
92
  const rangeExt = Math.floor(range / SAFE_LIMIT);
37
- for (let j = 0; j < COUNT; j += 2) {
38
- sum1 = (sum1 + arr[j]) & SAFE_PART;
39
- }
40
- for (let j = 1; j < COUNT; j += 2) {
41
- sum2 = (sum2 + arr[j]) % rangeExt;
42
- }
93
+
94
+ const sum1 = (arr[0] + arr[2]) & SAFE_PART;
95
+ const sum2 = (arr[0] + arr[2]) % rangeExt;
96
+
43
97
  return (sum2 * SAFE_LIMIT + sum1) % range;
44
98
  }
45
99
  };
@@ -60,6 +60,11 @@ const RESERVED_IDENTIFIER = new Set([
60
60
  "false"
61
61
  ]);
62
62
 
63
+ /**
64
+ * @param {ArrayLike<string>} properties properties
65
+ * @param {number} start start index
66
+ * @returns {string} chain of property accesses
67
+ */
63
68
  const propertyAccess = (properties, start = 0) => {
64
69
  let str = "";
65
70
  for (let i = start; i < properties.length; i++) {
@@ -288,7 +288,7 @@ const satisfy = (range, version) => {
288
288
  if (0 in range) {
289
289
  // @ts-expect-error
290
290
  version = parseVersion(version);
291
- var fixCount = range[0];
291
+ var fixCount = /** @type {number} */ (range[0]);
292
292
  // when negated is set it swill set for < instead of >=
293
293
  var negated = fixCount < 0;
294
294
  if (negated) fixCount = -fixCount - 1;
@@ -12,6 +12,10 @@
12
12
  /** @type {WeakMap<Compiler, Set<WasmLoadingType>>} */
13
13
  const enabledTypes = new WeakMap();
14
14
 
15
+ /**
16
+ * @param {Compiler} compiler compiler instance
17
+ * @returns {Set<WasmLoadingType>} enabled types
18
+ */
15
19
  const getEnabledTypes = compiler => {
16
20
  let set = enabledTypes.get(compiler);
17
21
  if (set === undefined) {
@@ -85,6 +85,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
85
85
  }
86
86
  }
87
87
 
88
+ /** @type {Array<string>} */
88
89
  const promises = [];
89
90
 
90
91
  const importStatements = Array.from(
@@ -47,7 +47,7 @@ class WebAssemblyParser extends Parser {
47
47
  // parse it
48
48
  const program = decode(source, decoderOpts);
49
49
  const module = program.body[0];
50
-
50
+ /** @type {Array<string>} */
51
51
  const exports = [];
52
52
  t.traverse(module, {
53
53
  ModuleExport({ node }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.80.0",
3
+ "version": "5.82.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
@@ -56,7 +56,7 @@
56
56
  "eslint": "^8.38.0",
57
57
  "eslint-config-prettier": "^8.1.0",
58
58
  "eslint-plugin-jest": "^27.2.1",
59
- "eslint-plugin-jsdoc": "^41.1.1",
59
+ "eslint-plugin-jsdoc": "^43.0.5",
60
60
  "eslint-plugin-node": "^11.0.0",
61
61
  "eslint-plugin-prettier": "^4.2.1",
62
62
  "file-loader": "^6.0.0",
@@ -76,7 +76,6 @@
76
76
  "less": "^4.0.0",
77
77
  "less-loader": "^8.0.0",
78
78
  "lint-staged": "^13.2.1",
79
- "loader-utils": "^2.0.3",
80
79
  "lodash": "^4.17.19",
81
80
  "lodash-es": "^4.17.15",
82
81
  "memfs": "^3.5.0",
@@ -96,11 +95,11 @@
96
95
  "simple-git": "^3.17.0",
97
96
  "strip-ansi": "^6.0.0",
98
97
  "style-loader": "^2.0.0",
99
- "terser": "^5.16.9",
98
+ "terser": "^5.17.0",
100
99
  "toml": "^3.0.0",
101
100
  "tooling": "webpack/tooling#v1.22.1",
102
101
  "ts-loader": "^9.4.2",
103
- "typescript": "^4.8.4",
102
+ "typescript": "^5.0.4",
104
103
  "url-loader": "^4.1.0",
105
104
  "wast-loader": "^1.11.5",
106
105
  "webassembly-feature": "1.3.0",