webpack 5.41.0 → 5.43.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.
- package/bin/webpack.js +0 -0
- package/lib/Compiler.js +14 -1
- package/lib/ExternalModule.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +5 -1
- package/lib/NormalModuleFactory.js +13 -2
- package/lib/TemplatedPathPlugin.js +24 -26
- package/lib/WebpackOptionsApply.js +2 -1
- package/lib/asset/AssetGenerator.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +26 -15
- package/lib/config/defaults.js +1 -0
- package/lib/config/normalization.js +1 -0
- package/lib/container/ContainerPlugin.js +4 -1
- package/lib/container/ModuleFederationPlugin.js +1 -0
- package/lib/dependencies/WorkerPlugin.js +1 -1
- package/lib/json/JsonData.js +41 -0
- package/lib/json/JsonGenerator.js +8 -2
- package/lib/json/JsonParser.js +2 -1
- package/lib/optimize/ConcatenatedModule.js +16 -0
- package/lib/optimize/RuntimeChunkPlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +2 -2
- package/lib/runtime/AsyncModuleRuntimeModule.js +8 -4
- package/lib/serialization/BinaryMiddleware.js +50 -35
- package/lib/serialization/FileMiddleware.js +112 -12
- package/lib/util/internalSerializables.js +1 -0
- package/lib/util/makeSerializable.js +0 -1
- package/package.json +7 -7
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +20 -8
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +15 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +2 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +17 -1
- package/types.d.ts +34 -14
@@ -165,12 +165,23 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
165
165
|
};
|
166
166
|
const flush = () => {
|
167
167
|
if (currentBuffer !== null) {
|
168
|
-
buffers.push(
|
168
|
+
buffers.push(
|
169
|
+
Buffer.from(
|
170
|
+
currentBuffer.buffer,
|
171
|
+
currentBuffer.byteOffset,
|
172
|
+
currentPosition
|
173
|
+
)
|
174
|
+
);
|
169
175
|
if (
|
170
176
|
!leftOverBuffer ||
|
171
177
|
leftOverBuffer.length < currentBuffer.length - currentPosition
|
172
|
-
)
|
173
|
-
leftOverBuffer =
|
178
|
+
) {
|
179
|
+
leftOverBuffer = Buffer.from(
|
180
|
+
currentBuffer.buffer,
|
181
|
+
currentBuffer.byteOffset + currentPosition,
|
182
|
+
currentBuffer.byteLength - currentPosition
|
183
|
+
);
|
184
|
+
}
|
174
185
|
currentBuffer = null;
|
175
186
|
buffersTotalLength += currentPosition;
|
176
187
|
currentPosition = 0;
|
@@ -537,12 +548,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
537
548
|
const isInCurrentBuffer = n => {
|
538
549
|
return currentIsBuffer && n + currentPosition <= currentBuffer.length;
|
539
550
|
};
|
540
|
-
|
541
|
-
* Reads n bytes
|
542
|
-
* @param {number} n amount of bytes to read
|
543
|
-
* @returns {Buffer} buffer with bytes
|
544
|
-
*/
|
545
|
-
const read = n => {
|
551
|
+
const ensureBuffer = () => {
|
546
552
|
if (!currentIsBuffer) {
|
547
553
|
throw new Error(
|
548
554
|
currentBuffer === null
|
@@ -550,14 +556,34 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
550
556
|
: "Unexpected lazy element in stream"
|
551
557
|
);
|
552
558
|
}
|
559
|
+
};
|
560
|
+
/**
|
561
|
+
* Reads n bytes
|
562
|
+
* @param {number} n amount of bytes to read
|
563
|
+
* @returns {Buffer} buffer with bytes
|
564
|
+
*/
|
565
|
+
const read = n => {
|
566
|
+
ensureBuffer();
|
553
567
|
const rem = currentBuffer.length - currentPosition;
|
554
568
|
if (rem < n) {
|
555
|
-
|
569
|
+
const buffers = [read(rem)];
|
570
|
+
n -= rem;
|
571
|
+
ensureBuffer();
|
572
|
+
while (currentBuffer.length < n) {
|
573
|
+
const b = /** @type {Buffer} */ (currentBuffer);
|
574
|
+
buffers.push(b);
|
575
|
+
n -= b.length;
|
576
|
+
currentDataItem++;
|
577
|
+
currentBuffer =
|
578
|
+
currentDataItem < data.length ? data[currentDataItem] : null;
|
579
|
+
currentIsBuffer = Buffer.isBuffer(currentBuffer);
|
580
|
+
ensureBuffer();
|
581
|
+
}
|
582
|
+
buffers.push(read(n));
|
583
|
+
return Buffer.concat(buffers);
|
556
584
|
}
|
557
|
-
const
|
558
|
-
|
559
|
-
currentPosition + n
|
560
|
-
);
|
585
|
+
const b = /** @type {Buffer} */ (currentBuffer);
|
586
|
+
const res = Buffer.from(b.buffer, b.byteOffset + currentPosition, n);
|
561
587
|
currentPosition += n;
|
562
588
|
checkOverflow();
|
563
589
|
return res;
|
@@ -568,33 +594,19 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
568
594
|
* @returns {Buffer} buffer with bytes
|
569
595
|
*/
|
570
596
|
const readUpTo = n => {
|
571
|
-
|
572
|
-
throw new Error(
|
573
|
-
currentBuffer === null
|
574
|
-
? "Unexpected end of stream"
|
575
|
-
: "Unexpected lazy element in stream"
|
576
|
-
);
|
577
|
-
}
|
597
|
+
ensureBuffer();
|
578
598
|
const rem = currentBuffer.length - currentPosition;
|
579
599
|
if (rem < n) {
|
580
600
|
n = rem;
|
581
601
|
}
|
582
|
-
const
|
583
|
-
|
584
|
-
currentPosition + n
|
585
|
-
);
|
602
|
+
const b = /** @type {Buffer} */ (currentBuffer);
|
603
|
+
const res = Buffer.from(b.buffer, b.byteOffset + currentPosition, n);
|
586
604
|
currentPosition += n;
|
587
605
|
checkOverflow();
|
588
606
|
return res;
|
589
607
|
};
|
590
608
|
const readU8 = () => {
|
591
|
-
|
592
|
-
throw new Error(
|
593
|
-
currentBuffer === null
|
594
|
-
? "Unexpected end of stream"
|
595
|
-
: "Unexpected lazy element in stream"
|
596
|
-
);
|
597
|
-
}
|
609
|
+
ensureBuffer();
|
598
610
|
/**
|
599
611
|
* There is no need to check remaining buffer size here
|
600
612
|
* since {@link checkOverflow} guarantees at least one byte remaining
|
@@ -735,7 +747,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
735
747
|
case STRING_HEADER:
|
736
748
|
return () => {
|
737
749
|
const len = readU32();
|
738
|
-
if (isInCurrentBuffer(len)) {
|
750
|
+
if (isInCurrentBuffer(len) && currentPosition + len < 0x7fffffff) {
|
739
751
|
result.push(
|
740
752
|
currentBuffer.toString(
|
741
753
|
undefined,
|
@@ -753,7 +765,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
753
765
|
return () => result.push("");
|
754
766
|
case SHORT_STRING_HEADER | 1:
|
755
767
|
return () => {
|
756
|
-
if (currentIsBuffer) {
|
768
|
+
if (currentIsBuffer && currentPosition < 0x7ffffffe) {
|
757
769
|
result.push(
|
758
770
|
currentBuffer.toString(
|
759
771
|
"latin1",
|
@@ -785,7 +797,10 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|
785
797
|
} else if ((header & SHORT_STRING_HEADER) === SHORT_STRING_HEADER) {
|
786
798
|
const len = header & SHORT_STRING_LENGTH_MASK;
|
787
799
|
return () => {
|
788
|
-
if (
|
800
|
+
if (
|
801
|
+
isInCurrentBuffer(len) &&
|
802
|
+
currentPosition + len < 0x7fffffff
|
803
|
+
) {
|
789
804
|
result.push(
|
790
805
|
currentBuffer.toString(
|
791
806
|
"latin1",
|
@@ -5,6 +5,14 @@
|
|
5
5
|
"use strict";
|
6
6
|
|
7
7
|
const { constants } = require("buffer");
|
8
|
+
const { pipeline } = require("stream");
|
9
|
+
const {
|
10
|
+
createBrotliCompress,
|
11
|
+
createBrotliDecompress,
|
12
|
+
createGzip,
|
13
|
+
createGunzip,
|
14
|
+
constants: zConstants
|
15
|
+
} = require("zlib");
|
8
16
|
const createHash = require("../util/createHash");
|
9
17
|
const { dirname, join, mkdirp } = require("../util/fs");
|
10
18
|
const memoize = require("../util/memoize");
|
@@ -37,6 +45,9 @@ const hashForName = buffers => {
|
|
37
45
|
return /** @type {string} */ (hash.digest("hex"));
|
38
46
|
};
|
39
47
|
|
48
|
+
const COMPRESSION_CHUNK_SIZE = 100 * 1024 * 1024;
|
49
|
+
const DECOMPRESSION_CHUNK_SIZE = 100 * 1024 * 1024;
|
50
|
+
|
40
51
|
const writeUInt64LE = Buffer.prototype.writeBigUInt64LE
|
41
52
|
? (buf, value, offset) => {
|
42
53
|
buf.writeBigUInt64LE(BigInt(value), offset);
|
@@ -69,7 +80,7 @@ const readUInt64LE = Buffer.prototype.readBigUInt64LE
|
|
69
80
|
* @param {FileMiddleware} middleware this
|
70
81
|
* @param {BufferSerializableType[] | Promise<BufferSerializableType[]>} data data to be serialized
|
71
82
|
* @param {string | boolean} name file base name
|
72
|
-
* @param {function(string | false, Buffer[]): Promise} writeFile writes a file
|
83
|
+
* @param {function(string | false, Buffer[]): Promise<void>} writeFile writes a file
|
73
84
|
* @returns {Promise<SerializeResult>} resulting file pointer and promise
|
74
85
|
*/
|
75
86
|
const serialize = async (middleware, data, name, writeFile) => {
|
@@ -280,8 +291,16 @@ const deserialize = async (middleware, name, readFile) => {
|
|
280
291
|
}
|
281
292
|
const sectionCount = readUInt32LE();
|
282
293
|
const lengths = [];
|
294
|
+
let lastLengthPositive = false;
|
283
295
|
for (let i = 0; i < sectionCount; i++) {
|
284
|
-
|
296
|
+
const value = readInt32LE();
|
297
|
+
const valuePositive = value >= 0;
|
298
|
+
if (lastLengthPositive && valuePositive) {
|
299
|
+
lengths[lengths.length - 1] += value;
|
300
|
+
} else {
|
301
|
+
lengths.push(value);
|
302
|
+
lastLengthPositive = valuePositive;
|
303
|
+
}
|
285
304
|
}
|
286
305
|
const result = [];
|
287
306
|
for (let length of lengths) {
|
@@ -307,13 +326,24 @@ const deserialize = async (middleware, name, readFile) => {
|
|
307
326
|
} else if (contentPosition !== 0) {
|
308
327
|
if (length <= contentItemLength - contentPosition) {
|
309
328
|
result.push(
|
310
|
-
|
329
|
+
Buffer.from(
|
330
|
+
contentItem.buffer,
|
331
|
+
contentItem.byteOffset + contentPosition,
|
332
|
+
length
|
333
|
+
)
|
311
334
|
);
|
312
335
|
contentPosition += length;
|
313
336
|
length = 0;
|
314
337
|
} else {
|
315
|
-
|
316
|
-
|
338
|
+
const l = contentItemLength - contentPosition;
|
339
|
+
result.push(
|
340
|
+
Buffer.from(
|
341
|
+
contentItem.buffer,
|
342
|
+
contentItem.byteOffset + contentPosition,
|
343
|
+
l
|
344
|
+
)
|
345
|
+
);
|
346
|
+
length -= l;
|
317
347
|
contentPosition = contentItemLength;
|
318
348
|
}
|
319
349
|
} else {
|
@@ -322,7 +352,9 @@ const deserialize = async (middleware, name, readFile) => {
|
|
322
352
|
length -= contentItemLength;
|
323
353
|
contentPosition = contentItemLength;
|
324
354
|
} else {
|
325
|
-
result.push(
|
355
|
+
result.push(
|
356
|
+
Buffer.from(contentItem.buffer, contentItem.byteOffset, length)
|
357
|
+
);
|
326
358
|
contentPosition += length;
|
327
359
|
length = 0;
|
328
360
|
}
|
@@ -334,7 +366,9 @@ const deserialize = async (middleware, name, readFile) => {
|
|
334
366
|
length -= contentItemLength;
|
335
367
|
contentPosition = contentItemLength;
|
336
368
|
} else {
|
337
|
-
result.push(
|
369
|
+
result.push(
|
370
|
+
Buffer.from(contentItem.buffer, contentItem.byteOffset, length)
|
371
|
+
);
|
338
372
|
contentPosition += length;
|
339
373
|
length = 0;
|
340
374
|
}
|
@@ -376,11 +410,37 @@ class FileMiddleware extends SerializerMiddleware {
|
|
376
410
|
? join(this.fs, filename, `../${name}${extension}`)
|
377
411
|
: filename;
|
378
412
|
await new Promise((resolve, reject) => {
|
379
|
-
|
413
|
+
let stream = this.fs.createWriteStream(file + "_");
|
414
|
+
let compression;
|
415
|
+
if (file.endsWith(".gz")) {
|
416
|
+
compression = createGzip({
|
417
|
+
chunkSize: COMPRESSION_CHUNK_SIZE,
|
418
|
+
level: zConstants.Z_BEST_SPEED
|
419
|
+
});
|
420
|
+
} else if (file.endsWith(".br")) {
|
421
|
+
compression = createBrotliCompress({
|
422
|
+
chunkSize: COMPRESSION_CHUNK_SIZE,
|
423
|
+
params: {
|
424
|
+
[zConstants.BROTLI_PARAM_MODE]: zConstants.BROTLI_MODE_TEXT,
|
425
|
+
[zConstants.BROTLI_PARAM_QUALITY]: 2,
|
426
|
+
[zConstants.BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING]: true,
|
427
|
+
[zConstants.BROTLI_PARAM_SIZE_HINT]: content.reduce(
|
428
|
+
(size, b) => size + b.length,
|
429
|
+
0
|
430
|
+
)
|
431
|
+
}
|
432
|
+
});
|
433
|
+
}
|
434
|
+
if (compression) {
|
435
|
+
pipeline(compression, stream, reject);
|
436
|
+
stream = compression;
|
437
|
+
stream.on("finish", () => resolve());
|
438
|
+
} else {
|
439
|
+
stream.on("error", err => reject(err));
|
440
|
+
stream.on("finish", () => resolve());
|
441
|
+
}
|
380
442
|
for (const b of content) stream.write(b);
|
381
443
|
stream.end();
|
382
|
-
stream.on("error", err => reject(err));
|
383
|
-
stream.on("finish", () => resolve());
|
384
444
|
});
|
385
445
|
if (name) allWrittenFiles.add(file);
|
386
446
|
};
|
@@ -447,6 +507,34 @@ class FileMiddleware extends SerializerMiddleware {
|
|
447
507
|
let currentBuffer;
|
448
508
|
let currentBufferUsed;
|
449
509
|
const buf = [];
|
510
|
+
let decompression;
|
511
|
+
if (file.endsWith(".gz")) {
|
512
|
+
decompression = createGunzip({
|
513
|
+
chunkSize: DECOMPRESSION_CHUNK_SIZE
|
514
|
+
});
|
515
|
+
} else if (file.endsWith(".br")) {
|
516
|
+
decompression = createBrotliDecompress({
|
517
|
+
chunkSize: DECOMPRESSION_CHUNK_SIZE
|
518
|
+
});
|
519
|
+
}
|
520
|
+
if (decompression) {
|
521
|
+
let newResolve, newReject;
|
522
|
+
resolve(
|
523
|
+
Promise.all([
|
524
|
+
new Promise((rs, rj) => {
|
525
|
+
newResolve = rs;
|
526
|
+
newReject = rj;
|
527
|
+
}),
|
528
|
+
new Promise((resolve, reject) => {
|
529
|
+
decompression.on("data", chunk => buf.push(chunk));
|
530
|
+
decompression.on("end", () => resolve());
|
531
|
+
decompression.on("error", err => reject(err));
|
532
|
+
})
|
533
|
+
]).then(() => buf)
|
534
|
+
);
|
535
|
+
resolve = newResolve;
|
536
|
+
reject = newReject;
|
537
|
+
}
|
450
538
|
this.fs.open(file, "r", (err, fd) => {
|
451
539
|
if (err) {
|
452
540
|
reject(err);
|
@@ -455,13 +543,18 @@ class FileMiddleware extends SerializerMiddleware {
|
|
455
543
|
const read = () => {
|
456
544
|
if (currentBuffer === undefined) {
|
457
545
|
currentBuffer = Buffer.allocUnsafeSlow(
|
458
|
-
Math.min(
|
546
|
+
Math.min(
|
547
|
+
constants.MAX_LENGTH,
|
548
|
+
remaining,
|
549
|
+
decompression ? DECOMPRESSION_CHUNK_SIZE : Infinity
|
550
|
+
)
|
459
551
|
);
|
460
552
|
currentBufferUsed = 0;
|
461
553
|
}
|
462
554
|
let readBuffer = currentBuffer;
|
463
555
|
let readOffset = currentBufferUsed;
|
464
556
|
let readLength = currentBuffer.length - currentBufferUsed;
|
557
|
+
// values passed to fs.read must be valid int32 values
|
465
558
|
if (readOffset > 0x7fffffff) {
|
466
559
|
readBuffer = currentBuffer.slice(readOffset);
|
467
560
|
readOffset = 0;
|
@@ -485,9 +578,16 @@ class FileMiddleware extends SerializerMiddleware {
|
|
485
578
|
currentBufferUsed += bytesRead;
|
486
579
|
remaining -= bytesRead;
|
487
580
|
if (currentBufferUsed === currentBuffer.length) {
|
488
|
-
|
581
|
+
if (decompression) {
|
582
|
+
decompression.write(currentBuffer);
|
583
|
+
} else {
|
584
|
+
buf.push(currentBuffer);
|
585
|
+
}
|
489
586
|
currentBuffer = undefined;
|
490
587
|
if (remaining === 0) {
|
588
|
+
if (decompression) {
|
589
|
+
decompression.end();
|
590
|
+
}
|
491
591
|
this.fs.close(fd, err => {
|
492
592
|
if (err) {
|
493
593
|
reject(err);
|
@@ -156,6 +156,7 @@ module.exports = {
|
|
156
156
|
require("../dependencies/WebpackIsIncludedDependency"),
|
157
157
|
"dependencies/WorkerDependency": () =>
|
158
158
|
require("../dependencies/WorkerDependency"),
|
159
|
+
"json/JsonData": () => require("../json/JsonData"),
|
159
160
|
"optimize/ConcatenatedModule": () =>
|
160
161
|
require("../optimize/ConcatenatedModule"),
|
161
162
|
DelegatedModule: () => require("../DelegatedModule"),
|
package/package.json
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.43.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
8
|
"@types/eslint-scope": "^3.7.0",
|
9
|
-
"@types/estree": "^0.0.
|
10
|
-
"@webassemblyjs/ast": "1.11.
|
11
|
-
"@webassemblyjs/wasm-edit": "1.11.
|
12
|
-
"@webassemblyjs/wasm-parser": "1.11.
|
13
|
-
"acorn": "^8.
|
9
|
+
"@types/estree": "^0.0.49",
|
10
|
+
"@webassemblyjs/ast": "1.11.1",
|
11
|
+
"@webassemblyjs/wasm-edit": "1.11.1",
|
12
|
+
"@webassemblyjs/wasm-parser": "1.11.1",
|
13
|
+
"acorn": "^8.4.1",
|
14
14
|
"browserslist": "^4.14.5",
|
15
15
|
"chrome-trace-event": "^1.0.2",
|
16
16
|
"enhanced-resolve": "^5.8.0",
|
17
|
-
"es-module-lexer": "^0.
|
17
|
+
"es-module-lexer": "^0.7.1",
|
18
18
|
"eslint-scope": "5.1.1",
|
19
19
|
"events": "^3.2.0",
|
20
20
|
"glob-to-regexp": "^0.4.1",
|