webpack 4.46.0 → 4.47.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.
package/bin/webpack.js CHANGED
File without changes
@@ -31,7 +31,9 @@ class SystemMainTemplatePlugin {
31
31
  const { mainTemplate, chunkTemplate } = compilation;
32
32
 
33
33
  const onRenderWithEntry = (source, chunk, hash) => {
34
- const externals = chunk.getModules().filter(m => m.external);
34
+ const externals = chunk
35
+ .getModules()
36
+ .filter(m => m.external && m.externalType === "system");
35
37
 
36
38
  // The name this bundle should be registered as with System
37
39
  const name = this.name
@@ -4,13 +4,13 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const crypto = require("crypto");
8
7
  const SortableSet = require("../util/SortableSet");
9
8
  const GraphHelpers = require("../GraphHelpers");
10
9
  const { isSubset } = require("../util/SetHelpers");
11
10
  const deterministicGrouping = require("../util/deterministicGrouping");
12
11
  const MinMaxSizeWarning = require("./MinMaxSizeWarning");
13
12
  const contextify = require("../util/identifier").contextify;
13
+ const createHash = require("../util/createHash");
14
14
 
15
15
  /** @typedef {import("../Compiler")} Compiler */
16
16
  /** @typedef {import("../Chunk")} Chunk */
@@ -21,8 +21,7 @@ const contextify = require("../util/identifier").contextify;
21
21
  const deterministicGroupingForModules = /** @type {function(DeterministicGroupingOptionsForModule): DeterministicGroupingGroupedItemsForModule[]} */ (deterministicGrouping);
22
22
 
23
23
  const hashFilename = name => {
24
- return crypto
25
- .createHash("md4")
24
+ return createHash("md4")
26
25
  .update(name)
27
26
  .digest("hex")
28
27
  .slice(0, 8);
@@ -29,9 +29,6 @@ class Hash {
29
29
  }
30
30
  }
31
31
 
32
- exports.Hash = Hash;
33
- /** @typedef {typeof Hash} HashConstructor */
34
-
35
32
  class BulkUpdateDecorator extends Hash {
36
33
  /**
37
34
  * @param {Hash} hash hash
@@ -118,6 +115,16 @@ class DebugHash extends Hash {
118
115
  }
119
116
  }
120
117
 
118
+ /** @type {typeof import("crypto") | undefined} */
119
+ let crypto = undefined;
120
+ /** @type {typeof import("./hash/md4") | undefined} */
121
+ let createMd4 = undefined;
122
+ /** @type {typeof import("./hash/BatchedHash") | undefined} */
123
+ let BatchedHash = undefined;
124
+
125
+ /** @type {number} */
126
+ const NODE_MAJOR_VERSION = parseInt(process.versions.node, 10);
127
+
121
128
  /**
122
129
  * Creates a hash by name or function
123
130
  * @param {string | HashConstructor} algorithm the algorithm name or a constructor creating a hash
@@ -127,11 +134,41 @@ module.exports = algorithm => {
127
134
  if (typeof algorithm === "function") {
128
135
  return new BulkUpdateDecorator(new algorithm());
129
136
  }
137
+
130
138
  switch (algorithm) {
131
139
  // TODO add non-cryptographic algorithm here
132
140
  case "debug":
133
141
  return new DebugHash();
142
+ case "md4":
143
+ if (NODE_MAJOR_VERSION >= 18) {
144
+ if (createMd4 === undefined) {
145
+ createMd4 = require("./hash/md4");
146
+ if (BatchedHash === undefined) {
147
+ BatchedHash = require("./hash/BatchedHash");
148
+ }
149
+ }
150
+ return new /** @type {typeof import("./hash/BatchedHash")} */ (BatchedHash)(
151
+ createMd4()
152
+ );
153
+ }
154
+ // If we are on Node.js < 18, fall through to the default case
155
+ // eslint-disable-next-line no-fallthrough
156
+
157
+ case "native-md4":
158
+ if (NODE_MAJOR_VERSION >= 18) {
159
+ if (crypto === undefined) crypto = require("crypto");
160
+ return new BulkUpdateDecorator(
161
+ /** @type {typeof import("crypto")} */ (crypto).createHash("md4")
162
+ );
163
+ }
164
+ // If we are on Node.js < 18, fall through to the default case
165
+ // eslint-disable-next-line no-fallthrough
166
+
134
167
  default:
135
- return new BulkUpdateDecorator(require("crypto").createHash(algorithm));
168
+ if (crypto === undefined) crypto = require("crypto");
169
+ return new BulkUpdateDecorator(crypto.createHash(algorithm));
136
170
  }
137
171
  };
172
+
173
+ module.exports.Hash = Hash;
174
+ /** @typedef {typeof Hash} HashConstructor */
@@ -0,0 +1,71 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ // From Webpack 5
9
+ // https://github.com/webpack/webpack/blob/853bfda35a0080605c09e1bdeb0103bcb9367a10/lib/util/hash/BatchedHash.js
10
+
11
+ const { Hash } = require("../createHash");
12
+ const MAX_SHORT_STRING = require("./wasm-hash").MAX_SHORT_STRING;
13
+
14
+ class BatchedHash extends Hash {
15
+ constructor(hash) {
16
+ super();
17
+ this.string = undefined;
18
+ this.encoding = undefined;
19
+ this.hash = hash;
20
+ }
21
+
22
+ /**
23
+ * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
24
+ * @param {string|Buffer} data data
25
+ * @param {string=} inputEncoding data encoding
26
+ * @returns {this} updated hash
27
+ */
28
+ update(data, inputEncoding) {
29
+ if (this.string !== undefined) {
30
+ if (
31
+ typeof data === "string" &&
32
+ inputEncoding === this.encoding &&
33
+ this.string.length + data.length < MAX_SHORT_STRING
34
+ ) {
35
+ this.string += data;
36
+ return this;
37
+ }
38
+ this.hash.update(this.string, this.encoding);
39
+ this.string = undefined;
40
+ }
41
+ if (typeof data === "string") {
42
+ if (
43
+ data.length < MAX_SHORT_STRING &&
44
+ // base64 encoding is not valid since it may contain padding chars
45
+ (!inputEncoding || !inputEncoding.startsWith("ba"))
46
+ ) {
47
+ this.string = data;
48
+ this.encoding = inputEncoding;
49
+ } else {
50
+ this.hash.update(data, inputEncoding);
51
+ }
52
+ } else {
53
+ this.hash.update(data);
54
+ }
55
+ return this;
56
+ }
57
+
58
+ /**
59
+ * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
60
+ * @param {string=} encoding encoding of the return value
61
+ * @returns {string|Buffer} digest
62
+ */
63
+ digest(encoding) {
64
+ if (this.string !== undefined) {
65
+ this.hash.update(this.string, this.encoding);
66
+ }
67
+ return this.hash.digest(encoding);
68
+ }
69
+ }
70
+
71
+ module.exports = BatchedHash;
@@ -0,0 +1,25 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ // From Webpack 5
9
+ // https://github.com/webpack/webpack/blob/853bfda35a0080605c09e1bdeb0103bcb9367a10/lib/util/hash/md4.js
10
+
11
+ const create = require("./wasm-hash").create;
12
+
13
+ //#region wasm code: md4 (../../../assembly/hash/md4.asm.ts) --initialMemory 1
14
+ // This will only get called on Node 18+
15
+ // eslint-disable-next-line no-undef
16
+ const md4 = new WebAssembly.Module(
17
+ Buffer.from(
18
+ // 2154 bytes
19
+ "AGFzbQEAAAABCAJgAX8AYAAAAwUEAQAAAAUDAQABBhoFfwFBAAt/AUEAC38BQQALfwFBAAt/AUEACwciBARpbml0AAAGdXBkYXRlAAIFZmluYWwAAwZtZW1vcnkCAAqJEAQmAEGBxpS6BiQBQYnXtv5+JAJB/rnrxXkkA0H2qMmBASQEQQAkAAvQCgEZfyMBIQUjAiECIwMhAyMEIQQDQCAAIAFLBEAgASgCBCIOIAQgAyABKAIAIg8gBSAEIAIgAyAEc3FzampBA3ciCCACIANzcXNqakEHdyEJIAEoAgwiBiACIAggASgCCCIQIAMgAiAJIAIgCHNxc2pqQQt3IgogCCAJc3FzampBE3chCyABKAIUIgcgCSAKIAEoAhAiESAIIAkgCyAJIApzcXNqakEDdyIMIAogC3Nxc2pqQQd3IQ0gASgCHCIJIAsgDCABKAIYIgggCiALIA0gCyAMc3FzampBC3ciEiAMIA1zcXNqakETdyETIAEoAiQiFCANIBIgASgCICIVIAwgDSATIA0gEnNxc2pqQQN3IgwgEiATc3FzampBB3chDSABKAIsIgsgEyAMIAEoAigiCiASIBMgDSAMIBNzcXNqakELdyISIAwgDXNxc2pqQRN3IRMgASgCNCIWIA0gEiABKAIwIhcgDCANIBMgDSASc3FzampBA3ciGCASIBNzcXNqakEHdyEZIBggASgCPCINIBMgGCABKAI4IgwgEiATIBkgEyAYc3FzampBC3ciEiAYIBlzcXNqakETdyITIBIgGXJxIBIgG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n9gZqQQl3IgcgBnMgCnNqIAlqQaHX5/YGakELdyIIIAdzIAZzaiANakGh1+f2BmpBD3dqIQIgAyAIaiEDIAQgB2ohBCABQUBrIQEMAQsLIAUkASACJAIgAyQDIAQkBAsNACAAEAEjACAAaiQAC/8EAgN/AX4jACAAaq1CA4YhBCAAQcgAakFAcSICQQhrIQMgACIBQQFqIQAgAUGAAToAAANAIAAgAklBACAAQQdxGwRAIABBADoAACAAQQFqIQAMAQsLA0AgACACSQRAIABCADcDACAAQQhqIQAMAQsLIAMgBDcDACACEAFBACMBrSIEQv//A4MgBEKAgPz/D4NCEIaEIgRC/4GAgPAfgyAEQoD+g4CA4D+DQgiGhCIEQo+AvIDwgcAHg0IIhiAEQvCBwIeAnoD4AINCBIiEIgRChoyYsODAgYMGfEIEiEKBgoSIkKDAgAGDQid+IARCsODAgYOGjJgwhHw3AwBBCCMCrSIEQv//A4MgBEKAgPz/D4NCEIaEIgRC/4GAgPAfgyAEQoD+g4CA4D+DQgiGhCIEQo+AvIDwgcAHg0IIhiAEQvCBwIeAnoD4AINCBIiEIgRChoyYsODAgYMGfEIEiEKBgoSIkKDAgAGDQid+IARCsODAgYOGjJgwhHw3AwBBECMDrSIEQv//A4MgBEKAgPz/D4NCEIaEIgRC/4GAgPAfgyAEQoD+g4CA4D+DQgiGhCIEQo+AvIDwgcAHg0IIhiAEQvCBwIeAnoD4AINCBIiEIgRChoyYsODAgYMGfEIEiEKBgoSIkKDAgAGDQid+IARCsODAgYOGjJgwhHw3AwBBGCMErSIEQv//A4MgBEKAgPz/D4NCEIaEIgRC/4GAgPAfgyAEQoD+g4CA4D+DQgiGhCIEQo+AvIDwgcAHg0IIhiAEQvCBwIeAnoD4AINCBIiEIgRChoyYsODAgYMGfEIEiEKBgoSIkKDAgAGDQid+IARCsODAgYOGjJgwhHw3AwAL",
20
+ "base64"
21
+ )
22
+ );
23
+ //#endregion
24
+
25
+ module.exports = create.bind(null, md4, [], 64, 32);
@@ -0,0 +1,174 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ // From Webpack 5
9
+ // https://github.com/webpack/webpack/blob/853bfda35a0080605c09e1bdeb0103bcb9367a10/lib/util/hash/wasm-hash.js
10
+
11
+ // 65536 is the size of a wasm memory page
12
+ // 64 is the maximum chunk size for every possible wasm hash implementation
13
+ // 4 is the maximum number of bytes per char for string encoding (max is utf-8)
14
+ // ~3 makes sure that it's always a block of 4 chars, so avoid partially encoded bytes for base64
15
+ const MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & ~3;
16
+
17
+ class WasmHash {
18
+ /**
19
+ * @param {WebAssembly.Instance} instance wasm instance
20
+ * @param {WebAssembly.Instance[]} instancesPool pool of instances
21
+ * @param {number} chunkSize size of data chunks passed to wasm
22
+ * @param {number} digestSize size of digest returned by wasm
23
+ */
24
+ constructor(instance, instancesPool, chunkSize, digestSize) {
25
+ const exports = /** @type {any} */ (instance.exports);
26
+ exports.init();
27
+ this.exports = exports;
28
+ this.mem = Buffer.from(exports.memory.buffer, 0, 65536);
29
+ this.buffered = 0;
30
+ this.instancesPool = instancesPool;
31
+ this.chunkSize = chunkSize;
32
+ this.digestSize = digestSize;
33
+ }
34
+
35
+ reset() {
36
+ this.buffered = 0;
37
+ this.exports.init();
38
+ }
39
+
40
+ /**
41
+ * @param {Buffer | string} data data
42
+ * @param {BufferEncoding=} encoding encoding
43
+ * @returns {this} itself
44
+ */
45
+ update(data, encoding) {
46
+ if (typeof data === "string") {
47
+ while (data.length > MAX_SHORT_STRING) {
48
+ this._updateWithShortString(data.slice(0, MAX_SHORT_STRING), encoding);
49
+ data = data.slice(MAX_SHORT_STRING);
50
+ }
51
+ this._updateWithShortString(data, encoding);
52
+ return this;
53
+ }
54
+ this._updateWithBuffer(data);
55
+ return this;
56
+ }
57
+
58
+ /**
59
+ * @param {string} data data
60
+ * @param {BufferEncoding | 'utf-8'} encoding encoding
61
+ * @returns {void}
62
+ */
63
+ _updateWithShortString(data, encoding) {
64
+ const { exports, buffered, mem, chunkSize } = this;
65
+ let endPos;
66
+ if (data.length < 70) {
67
+ if (!encoding || encoding === "utf-8" || encoding === "utf8") {
68
+ endPos = buffered;
69
+ for (let i = 0; i < data.length; i++) {
70
+ const cc = data.charCodeAt(i);
71
+ if (cc < 0x80) mem[endPos++] = cc;
72
+ else if (cc < 0x800) {
73
+ mem[endPos] = (cc >> 6) | 0xc0;
74
+ mem[endPos + 1] = (cc & 0x3f) | 0x80;
75
+ endPos += 2;
76
+ } else {
77
+ // bail-out for weird chars
78
+ const slicedData = data.slice(i);
79
+ endPos += mem.write(
80
+ slicedData,
81
+ endPos,
82
+ slicedData.length,
83
+ encoding
84
+ );
85
+ break;
86
+ }
87
+ }
88
+ } else if (encoding === "latin1") {
89
+ endPos = buffered;
90
+ for (let i = 0; i < data.length; i++) {
91
+ const cc = data.charCodeAt(i);
92
+ mem[endPos++] = cc;
93
+ }
94
+ } else {
95
+ endPos = buffered + mem.write(data, buffered, data.length, encoding);
96
+ }
97
+ } else {
98
+ endPos = buffered + mem.write(data, buffered, data.length, encoding);
99
+ }
100
+ if (endPos < chunkSize) {
101
+ this.buffered = endPos;
102
+ } else {
103
+ const l = endPos & ~(this.chunkSize - 1);
104
+ exports.update(l);
105
+ const newBuffered = endPos - l;
106
+ this.buffered = newBuffered;
107
+ if (newBuffered > 0) mem.copyWithin(0, l, endPos);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * @param {Buffer} data data
113
+ * @returns {void}
114
+ */
115
+ _updateWithBuffer(data) {
116
+ const { exports, buffered, mem } = this;
117
+ const length = data.length;
118
+ if (buffered + length < this.chunkSize) {
119
+ data.copy(mem, buffered, 0, length);
120
+ this.buffered += length;
121
+ } else {
122
+ const l = (buffered + length) & ~(this.chunkSize - 1);
123
+ if (l > 65536) {
124
+ let i = 65536 - buffered;
125
+ data.copy(mem, buffered, 0, i);
126
+ exports.update(65536);
127
+ const stop = l - buffered - 65536;
128
+ while (i < stop) {
129
+ data.copy(mem, 0, i, i + 65536);
130
+ exports.update(65536);
131
+ i += 65536;
132
+ }
133
+ data.copy(mem, 0, i, l - buffered);
134
+ exports.update(l - buffered - i);
135
+ } else {
136
+ data.copy(mem, buffered, 0, l - buffered);
137
+ exports.update(l);
138
+ }
139
+ const newBuffered = length + buffered - l;
140
+ this.buffered = newBuffered;
141
+ if (newBuffered > 0) data.copy(mem, 0, length - newBuffered, length);
142
+ }
143
+ }
144
+
145
+ digest(type) {
146
+ const { exports, buffered, mem, digestSize } = this;
147
+ exports.final(buffered);
148
+ this.instancesPool.push(this);
149
+ const hex = mem.toString("latin1", 0, digestSize);
150
+ if (type === "hex") return hex;
151
+ if (type === "binary" || !type) return Buffer.from(hex, "hex");
152
+ return Buffer.from(hex, "hex").toString(type);
153
+ }
154
+ }
155
+
156
+ const create = (wasmModule, instancesPool, chunkSize, digestSize) => {
157
+ if (instancesPool.length > 0) {
158
+ const old = instancesPool.pop();
159
+ old.reset();
160
+ return old;
161
+ } else {
162
+ return new WasmHash(
163
+ // This will only get called on Node 18+
164
+ // eslint-disable-next-line no-undef
165
+ new WebAssembly.Instance(wasmModule),
166
+ instancesPool,
167
+ chunkSize,
168
+ digestSize
169
+ );
170
+ }
171
+ };
172
+
173
+ module.exports.create = create;
174
+ module.exports.MAX_SHORT_STRING = MAX_SHORT_STRING;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "4.46.0",
3
+ "version": "4.47.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",