webpack 5.68.0 → 5.69.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.

@@ -509,7 +509,7 @@ class HttpUriPlugin {
509
509
 
510
510
  /**
511
511
  * @param {string} url URL
512
- * @param {FetchResult} cachedResult result from cache
512
+ * @param {FetchResult | RedirectFetchResult} cachedResult result from cache
513
513
  * @param {function((Error | null)=, FetchResult=): void} callback callback
514
514
  * @returns {void}
515
515
  */
@@ -603,9 +603,30 @@ class HttpUriPlugin {
603
603
  res.statusCode >= 301 &&
604
604
  res.statusCode <= 308
605
605
  ) {
606
- return finishWith({
606
+ const result = {
607
607
  location: new URL(location, url).href
608
- });
608
+ };
609
+ if (
610
+ !cachedResult ||
611
+ !("location" in cachedResult) ||
612
+ cachedResult.location !== result.location ||
613
+ cachedResult.validUntil < validUntil ||
614
+ cachedResult.storeLock !== storeLock ||
615
+ cachedResult.storeCache !== storeCache ||
616
+ cachedResult.etag !== etag
617
+ ) {
618
+ return finishWith(result);
619
+ } else {
620
+ logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
621
+ return callback(null, {
622
+ ...result,
623
+ fresh: true,
624
+ storeLock,
625
+ storeCache,
626
+ validUntil,
627
+ etag
628
+ });
629
+ }
609
630
  }
610
631
  const contentType = res.headers["content-type"] || "";
611
632
  const bufferArr = [];
@@ -40,6 +40,8 @@ Section -> Buffer
40
40
 
41
41
  // "wpc" + 1 in little-endian
42
42
  const VERSION = 0x01637077;
43
+ const WRITE_LIMIT_TOTAL = 0x7fff0000;
44
+ const WRITE_LIMIT_CHUNK = 511 * 1024 * 1024;
43
45
 
44
46
  /**
45
47
  * @param {Buffer[]} buffers buffers
@@ -87,7 +89,7 @@ const readUInt64LE = Buffer.prototype.readBigUInt64LE
87
89
  * @param {FileMiddleware} middleware this
88
90
  * @param {BufferSerializableType[] | Promise<BufferSerializableType[]>} data data to be serialized
89
91
  * @param {string | boolean} name file base name
90
- * @param {function(string | false, Buffer[]): Promise<void>} writeFile writes a file
92
+ * @param {function(string | false, Buffer[], number): Promise<void>} writeFile writes a file
91
93
  * @param {string | Hash} hashFunction hash function to use
92
94
  * @returns {Promise<SerializeResult>} resulting file pointer and promise
93
95
  */
@@ -212,9 +214,9 @@ const serialize = async (
212
214
  if (name === true) {
213
215
  name = hashForName(buf, hashFunction);
214
216
  }
215
- backgroundJobs.push(writeFile(name, buf));
216
217
  let size = 0;
217
218
  for (const b of buf) size += b.length;
219
+ backgroundJobs.push(writeFile(name, buf, size));
218
220
  return {
219
221
  size,
220
222
  name,
@@ -422,7 +424,7 @@ class FileMiddleware extends SerializerMiddleware {
422
424
  // It's important that we don't touch existing files during serialization
423
425
  // because serialize may read existing files (when deserializing)
424
426
  const allWrittenFiles = new Set();
425
- const writeFile = async (name, content) => {
427
+ const writeFile = async (name, content, size) => {
426
428
  const file = name
427
429
  ? join(this.fs, filename, `../${name}${extension}`)
428
430
  : filename;
@@ -441,10 +443,7 @@ class FileMiddleware extends SerializerMiddleware {
441
443
  [zConstants.BROTLI_PARAM_MODE]: zConstants.BROTLI_MODE_TEXT,
442
444
  [zConstants.BROTLI_PARAM_QUALITY]: 2,
443
445
  [zConstants.BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING]: true,
444
- [zConstants.BROTLI_PARAM_SIZE_HINT]: content.reduce(
445
- (size, b) => size + b.length,
446
- 0
447
- )
446
+ [zConstants.BROTLI_PARAM_SIZE_HINT]: size
448
447
  }
449
448
  });
450
449
  }
@@ -456,8 +455,44 @@ class FileMiddleware extends SerializerMiddleware {
456
455
  stream.on("error", err => reject(err));
457
456
  stream.on("finish", () => resolve());
458
457
  }
459
- for (const b of content) stream.write(b);
460
- stream.end();
458
+ // split into chunks for WRITE_LIMIT_CHUNK size
459
+ const chunks = [];
460
+ for (const b of content) {
461
+ if (b.length < WRITE_LIMIT_CHUNK) {
462
+ chunks.push(b);
463
+ } else {
464
+ for (let i = 0; i < b.length; i += WRITE_LIMIT_CHUNK) {
465
+ chunks.push(b.slice(i, i + WRITE_LIMIT_CHUNK));
466
+ }
467
+ }
468
+ }
469
+
470
+ const len = chunks.length;
471
+ let i = 0;
472
+ const batchWrite = err => {
473
+ // will be handled in "on" error handler
474
+ if (err) return;
475
+
476
+ if (i === len) {
477
+ stream.end();
478
+ return;
479
+ }
480
+
481
+ // queue up a batch of chunks up to the write limit
482
+ // end is exclusive
483
+ let end = i;
484
+ let sum = chunks[end++].length;
485
+ while (end < len) {
486
+ sum += chunks[end].length;
487
+ if (sum > WRITE_LIMIT_TOTAL) break;
488
+ end++;
489
+ }
490
+ while (i < end - 1) {
491
+ stream.write(chunks[i++]);
492
+ }
493
+ stream.write(chunks[i++], batchWrite);
494
+ };
495
+ batchWrite();
461
496
  });
462
497
  if (name) allWrittenFiles.add(file);
463
498
  };
@@ -18,7 +18,7 @@ const toSimpleString = str => {
18
18
 
19
19
  /**
20
20
  * @param {Record<string|number, boolean>} map value map
21
- * @returns {true|false|function(string): string} true/false, when unconditionally true/false, or a template function to determine the value at runtime
21
+ * @returns {boolean|(function(string): string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime
22
22
  */
23
23
  const compileBooleanMatcher = map => {
24
24
  const positiveItems = Object.keys(map).filter(i => map[i]);
@@ -498,7 +498,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
498
498
 
499
499
  // return the results
500
500
  return result.map(group => {
501
- /** @type {GroupedItems} */
501
+ /** @type {GroupedItems<T>} */
502
502
  return {
503
503
  key: group.key,
504
504
  items: group.nodes.map(node => node.item),
@@ -81,7 +81,49 @@ const requestToAbsolute = (context, relativePath) => {
81
81
  return relativePath;
82
82
  };
83
83
 
84
- const makeCacheable = fn => {
84
+ const makeCacheable = realFn => {
85
+ /** @type {WeakMap<object, Map<string, ParsedResource>>} */
86
+ const cache = new WeakMap();
87
+
88
+ const getCache = associatedObjectForCache => {
89
+ const entry = cache.get(associatedObjectForCache);
90
+ if (entry !== undefined) return entry;
91
+ /** @type {Map<string, ParsedResource>} */
92
+ const map = new Map();
93
+ cache.set(associatedObjectForCache, map);
94
+ return map;
95
+ };
96
+
97
+ /**
98
+ * @param {string} str the path with query and fragment
99
+ * @param {Object=} associatedObjectForCache an object to which the cache will be attached
100
+ * @returns {ParsedResource} parsed parts
101
+ */
102
+ const fn = (str, associatedObjectForCache) => {
103
+ if (!associatedObjectForCache) return realFn(str);
104
+ const cache = getCache(associatedObjectForCache);
105
+ const entry = cache.get(str);
106
+ if (entry !== undefined) return entry;
107
+ const result = realFn(str);
108
+ cache.set(str, result);
109
+ return result;
110
+ };
111
+
112
+ fn.bindCache = associatedObjectForCache => {
113
+ const cache = getCache(associatedObjectForCache);
114
+ return str => {
115
+ const entry = cache.get(str);
116
+ if (entry !== undefined) return entry;
117
+ const result = realFn(str);
118
+ cache.set(str, result);
119
+ return result;
120
+ };
121
+ };
122
+
123
+ return fn;
124
+ };
125
+
126
+ const makeCacheableWithContext = fn => {
85
127
  /** @type {WeakMap<object, Map<string, Map<string, string>>>} */
86
128
  const cache = new WeakMap();
87
129
 
@@ -215,7 +257,7 @@ const _makePathsRelative = (context, identifier) => {
215
257
  .join("");
216
258
  };
217
259
 
218
- exports.makePathsRelative = makeCacheable(_makePathsRelative);
260
+ exports.makePathsRelative = makeCacheableWithContext(_makePathsRelative);
219
261
 
220
262
  /**
221
263
  *
@@ -230,7 +272,7 @@ const _makePathsAbsolute = (context, identifier) => {
230
272
  .join("");
231
273
  };
232
274
 
233
- exports.makePathsAbsolute = makeCacheable(_makePathsAbsolute);
275
+ exports.makePathsAbsolute = makeCacheableWithContext(_makePathsAbsolute);
234
276
 
235
277
  /**
236
278
  * @param {string} context absolute context path
@@ -244,7 +286,7 @@ const _contextify = (context, request) => {
244
286
  .join("!");
245
287
  };
246
288
 
247
- const contextify = makeCacheable(_contextify);
289
+ const contextify = makeCacheableWithContext(_contextify);
248
290
  exports.contextify = contextify;
249
291
 
250
292
  /**
@@ -259,13 +301,15 @@ const _absolutify = (context, request) => {
259
301
  .join("!");
260
302
  };
261
303
 
262
- const absolutify = makeCacheable(_absolutify);
304
+ const absolutify = makeCacheableWithContext(_absolutify);
263
305
  exports.absolutify = absolutify;
264
306
 
265
307
  const PATH_QUERY_FRAGMENT_REGEXP =
266
308
  /^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
309
+ const PATH_QUERY_REGEXP = /^((?:\0.|[^?\0])*)(\?.*)?$/;
267
310
 
268
311
  /** @typedef {{ resource: string, path: string, query: string, fragment: string }} ParsedResource */
312
+ /** @typedef {{ resource: string, path: string, query: string }} ParsedResourceWithoutFragment */
269
313
 
270
314
  /**
271
315
  * @param {string} str the path with query and fragment
@@ -280,47 +324,24 @@ const _parseResource = str => {
280
324
  fragment: match[3] || ""
281
325
  };
282
326
  };
283
- exports.parseResource = (realFn => {
284
- /** @type {WeakMap<object, Map<string, ParsedResource>>} */
285
- const cache = new WeakMap();
327
+ exports.parseResource = makeCacheable(_parseResource);
286
328
 
287
- const getCache = associatedObjectForCache => {
288
- const entry = cache.get(associatedObjectForCache);
289
- if (entry !== undefined) return entry;
290
- /** @type {Map<string, ParsedResource>} */
291
- const map = new Map();
292
- cache.set(associatedObjectForCache, map);
293
- return map;
294
- };
295
-
296
- /**
297
- * @param {string} str the path with query and fragment
298
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
299
- * @returns {ParsedResource} parsed parts
300
- */
301
- const fn = (str, associatedObjectForCache) => {
302
- if (!associatedObjectForCache) return realFn(str);
303
- const cache = getCache(associatedObjectForCache);
304
- const entry = cache.get(str);
305
- if (entry !== undefined) return entry;
306
- const result = realFn(str);
307
- cache.set(str, result);
308
- return result;
309
- };
310
-
311
- fn.bindCache = associatedObjectForCache => {
312
- const cache = getCache(associatedObjectForCache);
313
- return str => {
314
- const entry = cache.get(str);
315
- if (entry !== undefined) return entry;
316
- const result = realFn(str);
317
- cache.set(str, result);
318
- return result;
319
- };
329
+ /**
330
+ * Parse resource, skips fragment part
331
+ * @param {string} str the path with query and fragment
332
+ * @returns {ParsedResourceWithoutFragment} parsed parts
333
+ */
334
+ const _parseResourceWithoutFragment = str => {
335
+ const match = PATH_QUERY_REGEXP.exec(str);
336
+ return {
337
+ resource: str,
338
+ path: match[1].replace(/\0(.)/g, "$1"),
339
+ query: match[2] ? match[2].replace(/\0(.)/g, "$1") : ""
320
340
  };
321
-
322
- return fn;
323
- })(_parseResource);
341
+ };
342
+ exports.parseResourceWithoutFragment = makeCacheable(
343
+ _parseResourceWithoutFragment
344
+ );
324
345
 
325
346
  /**
326
347
  * @param {string} filename the filename which should be undone
@@ -0,0 +1,22 @@
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 A_CODE = "a".charCodeAt(0);
9
+
10
+ /**
11
+ * @param {string} hash hash
12
+ * @param {number} hashLength hash length
13
+ * @returns {string} returns hash that has at least one non numeric char
14
+ */
15
+ module.exports = (hash, hashLength) => {
16
+ if (hashLength < 1) return "";
17
+ const slice = hash.slice(0, hashLength);
18
+ if (slice.match(/[^\d]/)) return slice;
19
+ return `${String.fromCharCode(
20
+ A_CODE + (parseInt(hash[0], 10) % 6)
21
+ )}${slice.slice(1)}`;
22
+ };
@@ -89,7 +89,9 @@ exports.versionLt = versionLt;
89
89
  */
90
90
  exports.parseRange = str => {
91
91
  const splitAndConvert = str => {
92
- return str.split(".").map(item => (`${+item}` === item ? +item : item));
92
+ return str
93
+ .split(".")
94
+ .map(item => (item !== "NaN" && `${+item}` === item ? +item : item));
93
95
  };
94
96
  // see https://docs.npmjs.com/misc/semver#range-grammar for grammar
95
97
  const parsePartial = str => {
@@ -131,13 +133,15 @@ exports.parseRange = str => {
131
133
  return [-range[0] - 1, ...range.slice(1)];
132
134
  };
133
135
  const parseSimple = str => {
134
- // simple ::= primitive | partial | tilde | caret
135
- // primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
136
- // tilde ::= '~' partial
137
- // caret ::= '^' partial
136
+ // simple ::= primitive | partial | tilde | caret
137
+ // primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | '!' ) ( ' ' ) * partial
138
+ // tilde ::= '~' ( ' ' ) * partial
139
+ // caret ::= '^' ( ' ' ) * partial
138
140
  const match = /^(\^|~|<=|<|>=|>|=|v|!)/.exec(str);
139
141
  const start = match ? match[0] : "";
140
- const remainder = parsePartial(str.slice(start.length));
142
+ const remainder = parsePartial(
143
+ start.length ? str.slice(start.length).trim() : str.trim()
144
+ );
141
145
  switch (start) {
142
146
  case "^":
143
147
  if (remainder.length > 1 && remainder[1] === 0) {
@@ -191,11 +195,14 @@ exports.parseRange = str => {
191
195
  return [, ...arr, ...items.slice(1).map(() => fn)];
192
196
  };
193
197
  const parseRange = str => {
194
- // range ::= hyphen | simple ( ' ' simple ) * | ''
195
- // hyphen ::= partial ' - ' partial
196
- const items = str.split(" - ");
198
+ // range ::= hyphen | simple ( ' ' ( ' ' ) * simple ) * | ''
199
+ // hyphen ::= partial ( ' ' ) * ' - ' ( ' ' ) * partial
200
+ const items = str.split(/\s+-\s+/);
197
201
  if (items.length === 1) {
198
- const items = str.trim().split(/\s+/g).map(parseSimple);
202
+ const items = str
203
+ .trim()
204
+ .split(/(?<=[-0-9A-Za-z])\s+/g)
205
+ .map(parseSimple);
199
206
  return combine(items, 2);
200
207
  }
201
208
  const a = parsePartial(items[0]);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.68.0",
3
+ "version": "5.69.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",
7
7
  "dependencies": {
8
- "@types/eslint-scope": "^3.7.0",
9
- "@types/estree": "^0.0.50",
8
+ "@types/eslint-scope": "^3.7.3",
9
+ "@types/estree": "^0.0.51",
10
10
  "@webassemblyjs/ast": "1.11.1",
11
11
  "@webassemblyjs/wasm-edit": "1.11.1",
12
12
  "@webassemblyjs/wasm-parser": "1.11.1",
@@ -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.8.3",
17
+ "enhanced-resolve": "^5.9.0",
18
18
  "es-module-lexer": "^0.9.0",
19
19
  "eslint-scope": "5.1.1",
20
20
  "events": "^3.2.0",
@@ -39,8 +39,8 @@
39
39
  "@babel/core": "^7.11.1",
40
40
  "@babel/preset-react": "^7.10.4",
41
41
  "@types/es-module-lexer": "^0.4.1",
42
- "@types/jest": "^27.0.2",
43
- "@types/node": "^15.0.1",
42
+ "@types/jest": "^27.4.0",
43
+ "@types/node": "^17.0.16",
44
44
  "assemblyscript": "^0.19.16",
45
45
  "babel-loader": "^8.1.0",
46
46
  "benchmark": "^2.1.4",
@@ -56,7 +56,7 @@
56
56
  "es6-promise-polyfill": "^1.2.0",
57
57
  "eslint": "^7.14.0",
58
58
  "eslint-config-prettier": "^8.1.0",
59
- "eslint-plugin-jest": "^24.3.6",
59
+ "eslint-plugin-jest": "^24.7.0",
60
60
  "eslint-plugin-jsdoc": "^33.0.0",
61
61
  "eslint-plugin-node": "^11.0.0",
62
62
  "eslint-plugin-prettier": "^4.0.0",
@@ -66,10 +66,10 @@
66
66
  "husky": "^6.0.0",
67
67
  "is-ci": "^3.0.0",
68
68
  "istanbul": "^0.4.5",
69
- "jest": "^27.3.1",
70
- "jest-circus": "^27.3.1",
71
- "jest-cli": "^27.3.1",
72
- "jest-diff": "^27.3.1",
69
+ "jest": "^27.5.0",
70
+ "jest-circus": "^27.5.0",
71
+ "jest-cli": "^27.5.0",
72
+ "jest-diff": "^27.5.0",
73
73
  "jest-junit": "^13.0.0",
74
74
  "json-loader": "^0.5.7",
75
75
  "json5": "^2.1.3",
@@ -98,9 +98,9 @@
98
98
  "style-loader": "^2.0.0",
99
99
  "terser": "^5.7.0",
100
100
  "toml": "^3.0.0",
101
- "tooling": "webpack/tooling#v1.20.1",
101
+ "tooling": "webpack/tooling#v1.21.0",
102
102
  "ts-loader": "^8.0.2",
103
- "typescript": "^4.2.0-beta",
103
+ "typescript": "^4.5.5",
104
104
  "url-loader": "^4.1.0",
105
105
  "wast-loader": "^1.11.0",
106
106
  "webassembly-feature": "1.3.0",