webpack 5.81.0 → 5.82.1

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 (62) hide show
  1. package/bin/webpack.js +13 -2
  2. package/lib/Compilation.js +4 -1
  3. package/lib/CssModule.js +39 -7
  4. package/lib/DependenciesBlock.js +8 -0
  5. package/lib/FileSystemInfo.js +1 -1
  6. package/lib/HotModuleReplacementPlugin.js +3 -2
  7. package/lib/Module.js +3 -2
  8. package/lib/ModuleTypeConstants.js +90 -0
  9. package/lib/NormalModule.js +2 -1
  10. package/lib/RuntimeModule.js +4 -3
  11. package/lib/Template.js +2 -1
  12. package/lib/WebpackOptionsApply.js +33 -40
  13. package/lib/asset/AssetGenerator.js +4 -3
  14. package/lib/asset/AssetModulesPlugin.js +21 -11
  15. package/lib/asset/RawDataUrlModule.js +2 -1
  16. package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
  17. package/lib/config/defaults.js +4 -2
  18. package/lib/container/FallbackModule.js +2 -1
  19. package/lib/container/RemoteModule.js +2 -1
  20. package/lib/css/CssGenerator.js +4 -0
  21. package/lib/css/CssLoadingRuntimeModule.js +9 -2
  22. package/lib/css/CssModulesPlugin.js +149 -39
  23. package/lib/css/CssParser.js +443 -319
  24. package/lib/css/walkCssTokens.js +118 -27
  25. package/lib/debug/ProfilingPlugin.js +2 -0
  26. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -0
  27. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  28. package/lib/hmr/LazyCompilationPlugin.js +13 -4
  29. package/lib/javascript/BasicEvaluatedExpression.js +108 -1
  30. package/lib/javascript/JavascriptModulesPlugin.js +3 -2
  31. package/lib/javascript/JavascriptParser.js +132 -11
  32. package/lib/json/JsonData.js +25 -0
  33. package/lib/json/JsonGenerator.js +15 -3
  34. package/lib/json/JsonModulesPlugin.js +1 -0
  35. package/lib/json/JsonParser.js +2 -1
  36. package/lib/library/ModuleLibraryPlugin.js +2 -1
  37. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +3 -1
  38. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  39. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +22 -3
  40. package/lib/schemes/DataUriPlugin.js +4 -0
  41. package/lib/schemes/HttpUriPlugin.js +38 -0
  42. package/lib/sharing/ConsumeSharedModule.js +5 -2
  43. package/lib/sharing/ProvideSharedModule.js +2 -1
  44. package/lib/sharing/utils.js +293 -7
  45. package/lib/stats/DefaultStatsFactoryPlugin.js +7 -4
  46. package/lib/stats/DefaultStatsPrinterPlugin.js +25 -0
  47. package/lib/util/StackedCacheMap.js +6 -0
  48. package/lib/util/StringXor.js +51 -0
  49. package/lib/util/compileBooleanMatcher.js +31 -0
  50. package/lib/util/createHash.js +4 -3
  51. package/lib/util/deprecation.js +8 -0
  52. package/lib/util/identifier.js +4 -0
  53. package/lib/util/numberHash.js +75 -21
  54. package/lib/util/propertyAccess.js +5 -0
  55. package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
  56. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -0
  57. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  58. package/lib/web/JsonpChunkLoadingRuntimeModule.js +8 -4
  59. package/package.json +3 -3
  60. package/schemas/WebpackOptions.check.js +1 -1
  61. package/schemas/WebpackOptions.json +25 -0
  62. package/types.d.ts +181 -39
@@ -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++) {
@@ -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 }) {
@@ -189,7 +189,9 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
189
189
  )};`,
190
190
  `${RuntimeGlobals.loadScript}(url, loadingEnded, "chunk-" + chunkId, chunkId);`
191
191
  ]),
192
- "} else installedChunks[chunkId] = 0;"
192
+ hasJsMatcher === true
193
+ ? "}"
194
+ : "} else installedChunks[chunkId] = 0;"
193
195
  ]),
194
196
  "}"
195
197
  ]),
@@ -250,7 +252,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
250
252
  linkPreload.call(
251
253
  Template.asString([
252
254
  "var link = document.createElement('link');",
253
- scriptType
255
+ scriptType && scriptType !== "module"
254
256
  ? `link.type = ${JSON.stringify(scriptType)};`
255
257
  : "",
256
258
  "link.charset = 'utf-8';",
@@ -259,8 +261,10 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
259
261
  `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
260
262
  ),
261
263
  "}",
262
- 'link.rel = "preload";',
263
- 'link.as = "script";',
264
+ scriptType === "module"
265
+ ? 'link.rel = "modulepreload";'
266
+ : 'link.rel = "preload";',
267
+ scriptType === "module" ? "" : 'link.as = "script";',
264
268
  `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
265
269
  crossOriginLoading
266
270
  ? crossOriginLoading === "use-credentials"
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.81.0",
3
+ "version": "5.82.1",
4
4
  "author": "Tobias Koppers @sokra",
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.",
5
+ "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@types/eslint-scope": "^3.7.3",
@@ -14,7 +14,7 @@
14
14
  "acorn-import-assertions": "^1.7.6",
15
15
  "browserslist": "^4.14.5",
16
16
  "chrome-trace-event": "^1.0.2",
17
- "enhanced-resolve": "^5.13.0",
17
+ "enhanced-resolve": "^5.14.0",
18
18
  "es-module-lexer": "^1.2.1",
19
19
  "eslint-scope": "5.1.1",
20
20
  "events": "^3.2.0",