@rspack/core 1.0.0-alpha.4 → 1.0.0-beta.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.
Files changed (102) hide show
  1. package/compiled/zod/index.d.ts +138 -52
  2. package/compiled/zod/index.js +300 -103
  3. package/compiled/zod/package.json +1 -1
  4. package/compiled/zod-validation-error/index.js +6 -6
  5. package/dist/Compilation.d.ts +21 -3
  6. package/dist/Compilation.js +64 -49
  7. package/dist/Compiler.js +28 -28
  8. package/dist/ErrorHelpers.js +2 -4
  9. package/dist/FileSystem.js +6 -6
  10. package/dist/Module.js +2 -6
  11. package/dist/ModuleTypeConstants.d.ts +45 -69
  12. package/dist/ModuleTypeConstants.js +24 -77
  13. package/dist/NormalModule.js +6 -6
  14. package/dist/Stats.js +4 -6
  15. package/dist/Template.d.ts +31 -147
  16. package/dist/Template.js +40 -236
  17. package/dist/Watching.js +2 -2
  18. package/dist/builtin-loader/lightningcss/index.d.ts +89 -0
  19. package/dist/builtin-loader/lightningcss/index.js +175 -0
  20. package/dist/builtin-plugin/BannerPlugin.d.ts +24 -48
  21. package/dist/builtin-plugin/DefinePlugin.js +9 -13
  22. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  23. package/dist/builtin-plugin/ExternalsPlugin.d.ts +24 -0
  24. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +8 -8
  25. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +2 -2
  26. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +10 -3
  27. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +4 -1
  28. package/dist/builtin-plugin/SplitChunksPlugin.js +7 -17
  29. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +15 -23
  30. package/dist/builtin-plugin/base.js +1 -3
  31. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -3
  32. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +17 -66
  33. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +2 -0
  34. package/dist/builtin-plugin/css-extract/hmr/{normalize-url.js → normalizeUrl.js} +15 -24
  35. package/dist/builtin-plugin/css-extract/loader.js +6 -6
  36. package/dist/builtin-plugin/css-extract/utils.js +3 -3
  37. package/dist/builtin-plugin/lazy-compilation/backend.d.ts +3 -3
  38. package/dist/builtin-plugin/lazy-compilation/backend.js +1 -1
  39. package/dist/config/adapter.d.ts +1 -1
  40. package/dist/config/adapter.js +31 -30
  41. package/dist/config/adapterRuleUse.d.ts +5 -5
  42. package/dist/config/adapterRuleUse.js +23 -1
  43. package/dist/config/browserslistTargetHandler.d.ts +17 -15
  44. package/dist/config/browserslistTargetHandler.js +27 -33
  45. package/dist/config/defaults.js +27 -28
  46. package/dist/config/normalization.d.ts +2 -0
  47. package/dist/config/normalization.js +5 -5
  48. package/dist/config/target.d.ts +48 -109
  49. package/dist/config/target.js +50 -86
  50. package/dist/config/zod.d.ts +2398 -2212
  51. package/dist/config/zod.js +29 -19
  52. package/dist/container/ContainerPlugin.d.ts +7 -7
  53. package/dist/container/options.js +1 -1
  54. package/dist/exports.d.ts +4 -4
  55. package/dist/exports.js +2 -2
  56. package/dist/lib/CacheFacade.js +1 -0
  57. package/dist/lib/EntryOptionPlugin.js +2 -2
  58. package/dist/lib/ModuleFilenameHelpers.js +1 -3
  59. package/dist/lib/WebpackError.js +1 -1
  60. package/dist/lib/cache/mergeEtags.js +5 -11
  61. package/dist/lib/formatLocation.js +3 -5
  62. package/dist/loader-runner/LoaderLoadingError.d.ts +11 -1
  63. package/dist/loader-runner/LoaderLoadingError.js +3 -5
  64. package/dist/loader-runner/index.js +23 -25
  65. package/dist/loader-runner/loadLoader.d.ts +11 -2
  66. package/dist/loader-runner/loadLoader.js +18 -20
  67. package/dist/logging/createConsoleLogger.js +2 -6
  68. package/dist/logging/truncateArgs.js +5 -9
  69. package/dist/node/NodeWatchFileSystem.js +5 -5
  70. package/dist/node/nodeConsole.js +2 -4
  71. package/dist/rspack.js +6 -6
  72. package/dist/rspackOptionsApply.js +3 -3
  73. package/dist/stats/DefaultStatsFactoryPlugin.js +65 -20
  74. package/dist/stats/DefaultStatsPresetPlugin.js +4 -4
  75. package/dist/stats/DefaultStatsPrinterPlugin.js +12 -17
  76. package/dist/stats/StatsFactory.js +13 -17
  77. package/dist/stats/StatsPrinter.js +7 -9
  78. package/dist/stats/statsFactoryUtils.d.ts +9 -10
  79. package/dist/util/AssetInfo.js +11 -7
  80. package/dist/util/SplitChunkSize.js +1 -1
  81. package/dist/util/bindingVersionCheck.js +6 -6
  82. package/dist/util/cleverMerge.d.ts +33 -57
  83. package/dist/util/cleverMerge.js +89 -145
  84. package/dist/util/comparators.js +3 -5
  85. package/dist/util/createHash.d.ts +4 -3
  86. package/dist/util/createHash.js +31 -45
  87. package/dist/util/fs.js +16 -20
  88. package/dist/util/hash/BatchedHash.d.ts +24 -9
  89. package/dist/util/hash/BatchedHash.js +16 -13
  90. package/dist/util/hash/index.d.ts +9 -9
  91. package/dist/util/hash/index.js +14 -11
  92. package/dist/util/hash/md4.d.ts +29 -2
  93. package/dist/util/hash/md4.js +7 -3
  94. package/dist/util/hash/wasm-hash.d.ts +52 -5
  95. package/dist/util/hash/wasm-hash.js +19 -22
  96. package/dist/util/hash/xxhash64.d.ts +29 -2
  97. package/dist/util/hash/xxhash64.js +7 -3
  98. package/dist/util/identifier.js +13 -19
  99. package/dist/util/index.js +1 -1
  100. package/dist/util/memoize.js +7 -9
  101. package/package.json +9 -8
  102. package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +0 -2
@@ -8,18 +8,24 @@
8
8
  * Copyright (c) JS Foundation and other contributors
9
9
  * https://github.com/webpack/webpack/blob/main/LICENSE
10
10
  */
11
- //@ts-nocheck
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
12
14
  Object.defineProperty(exports, "__esModule", { value: true });
13
15
  exports.createHash = void 0;
14
- const Hash = require("./hash");
16
+ const node_crypto_1 = __importDefault(require("node:crypto"));
17
+ const hash_1 = __importDefault(require("./hash"));
18
+ const BatchedHash_1 = __importDefault(require("./hash/BatchedHash"));
19
+ const md4_1 = __importDefault(require("./hash/md4"));
20
+ const xxhash64_1 = __importDefault(require("./hash/xxhash64"));
15
21
  const BULK_SIZE = 2000;
16
22
  // We are using an object instead of a Map as this will stay static during the runtime
17
23
  // so access to it can be optimized by v8
18
24
  const digestCaches = {};
19
- class BulkUpdateDecorator extends Hash {
25
+ class BulkUpdateDecorator extends hash_1.default {
20
26
  /**
21
- * @param {Hash | function(): Hash} hashOrFactory function to create a hash
22
- * @param {string=} hashKey key for caching
27
+ * @param hashOrFactory function to create a hash
28
+ * @param hashKey key for caching
23
29
  */
24
30
  constructor(hashOrFactory, hashKey) {
25
31
  super();
@@ -36,9 +42,9 @@ class BulkUpdateDecorator extends Hash {
36
42
  }
37
43
  /**
38
44
  * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
39
- * @param {string|Buffer} data data
40
- * @param {string=} inputEncoding data encoding
41
- * @returns {this} updated hash
45
+ * @param data data
46
+ * @param inputEncoding data encoding
47
+ * @returns updated hash
42
48
  */
43
49
  update(data, inputEncoding) {
44
50
  if (inputEncoding !== undefined ||
@@ -65,8 +71,8 @@ class BulkUpdateDecorator extends Hash {
65
71
  }
66
72
  /**
67
73
  * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
68
- * @param {string=} encoding encoding of the return value
69
- * @returns {string|Buffer} digest
74
+ * @param encoding encoding of the return value
75
+ * @returns digest
70
76
  */
71
77
  digest(encoding) {
72
78
  let digestCache;
@@ -95,45 +101,41 @@ class BulkUpdateDecorator extends Hash {
95
101
  }
96
102
  }
97
103
  /* istanbul ignore next */
98
- class DebugHash extends Hash {
104
+ class DebugHash extends hash_1.default {
99
105
  constructor() {
100
106
  super();
101
107
  this.string = "";
102
108
  }
103
109
  /**
104
110
  * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
105
- * @param {string|Buffer} data data
106
- * @param {string=} inputEncoding data encoding
107
- * @returns {this} updated hash
111
+ * @param data data
112
+ * @param _inputEncoding data encoding
113
+ * @returns updated hash
108
114
  */
109
- update(data, inputEncoding) {
115
+ update(data, _inputEncoding) {
110
116
  if (typeof data !== "string")
111
117
  data = data.toString("utf-8");
112
118
  if (data.startsWith("debug-digest-")) {
113
119
  data = Buffer.from(data.slice("debug-digest-".length), "hex").toString();
114
120
  }
115
- this.string += `[${data}](${new Error().stack.split("\n", 3)[2]})\n`;
121
+ this.string += `[${data}](${new Error().stack?.split("\n", 3)[2]})\n`;
116
122
  return this;
117
123
  }
118
124
  /**
119
125
  * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
120
- * @param {string=} encoding encoding of the return value
121
- * @returns {string|Buffer} digest
126
+ * @param encoding encoding of the return value
127
+ * @returns digest
122
128
  */
123
129
  digest(encoding) {
124
130
  return ("debug-digest-" + Buffer.from(this.string).toString(encoding || "hex"));
125
131
  }
126
132
  }
127
- let crypto = undefined;
128
- let createXXHash64 = undefined;
129
- let createMd4 = undefined;
130
- let BatchedHash = undefined;
131
133
  /**
132
134
  * Creates a hash by name or function
133
- * @param {string | typeof Hash} algorithm the algorithm name or a constructor creating a hash
134
- * @returns {Hash} the hash
135
+ * @param algorithm the algorithm name or a constructor creating a hash
136
+ * @returns the hash
135
137
  */
136
- const createHash = algorithm => {
138
+ const createHash = (algorithm) => {
137
139
  if (typeof algorithm === "function") {
138
140
  return new BulkUpdateDecorator(() => new algorithm());
139
141
  }
@@ -142,29 +144,13 @@ const createHash = algorithm => {
142
144
  case "debug":
143
145
  return new DebugHash();
144
146
  case "xxhash64":
145
- if (createXXHash64 === undefined) {
146
- createXXHash64 = require("./hash/xxhash64");
147
- if (BatchedHash === undefined) {
148
- BatchedHash = require("./hash/BatchedHash");
149
- }
150
- }
151
- return new BatchedHash(createXXHash64());
147
+ return new BatchedHash_1.default((0, xxhash64_1.default)());
152
148
  case "md4":
153
- if (createMd4 === undefined) {
154
- createMd4 = require("./hash/md4");
155
- if (BatchedHash === undefined) {
156
- BatchedHash = require("./hash/BatchedHash");
157
- }
158
- }
159
- return new BatchedHash(createMd4());
149
+ return new BatchedHash_1.default((0, md4_1.default)());
160
150
  case "native-md4":
161
- if (crypto === undefined)
162
- crypto = require("crypto");
163
- return new BulkUpdateDecorator(() => crypto.createHash("md4"), "md4");
151
+ return new BulkUpdateDecorator(() => node_crypto_1.default.createHash("md4"), "md4");
164
152
  default:
165
- if (crypto === undefined)
166
- crypto = require("crypto");
167
- return new BulkUpdateDecorator(() => crypto.createHash(algorithm), algorithm);
153
+ return new BulkUpdateDecorator(() => node_crypto_1.default.createHash(algorithm), algorithm);
168
154
  }
169
155
  };
170
156
  exports.createHash = createHash;
package/dist/util/fs.js CHANGED
@@ -13,8 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.mkdirp = exports.rmrf = void 0;
16
- const assert_1 = __importDefault(require("assert"));
17
- const path_1 = __importDefault(require("path"));
16
+ const node_assert_1 = __importDefault(require("node:assert"));
17
+ const node_path_1 = __importDefault(require("node:path"));
18
18
  function rmrf(fs, p, callback) {
19
19
  fs.stat(p, (err, stats) => {
20
20
  if (err) {
@@ -33,8 +33,8 @@ function rmrf(fs, p, callback) {
33
33
  fs.rmdir(p, callback);
34
34
  }
35
35
  else {
36
- files.forEach(file => {
37
- (0, assert_1.default)(typeof file === "string");
36
+ for (const file of files) {
37
+ (0, node_assert_1.default)(typeof file === "string");
38
38
  const fullPath = join(fs, p, file);
39
39
  rmrf(fs, fullPath, err => {
40
40
  if (err) {
@@ -45,7 +45,7 @@ function rmrf(fs, p, callback) {
45
45
  fs.rmdir(p, callback);
46
46
  }
47
47
  });
48
- });
48
+ }
49
49
  }
50
50
  });
51
51
  }
@@ -59,29 +59,25 @@ const join = (fs, rootPath, filename) => {
59
59
  if (fs && fs.join) {
60
60
  return fs.join(rootPath, filename);
61
61
  }
62
- else if (path_1.default.posix.isAbsolute(rootPath)) {
63
- return path_1.default.posix.join(rootPath, filename);
62
+ if (node_path_1.default.posix.isAbsolute(rootPath)) {
63
+ return node_path_1.default.posix.join(rootPath, filename);
64
64
  }
65
- else if (path_1.default.win32.isAbsolute(rootPath)) {
66
- return path_1.default.win32.join(rootPath, filename);
67
- }
68
- else {
69
- throw new Error(`${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system`);
65
+ if (node_path_1.default.win32.isAbsolute(rootPath)) {
66
+ return node_path_1.default.win32.join(rootPath, filename);
70
67
  }
68
+ throw new Error(`${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system`);
71
69
  };
72
70
  const dirname = (fs, absPath) => {
73
71
  if (fs && fs.dirname) {
74
72
  return fs.dirname(absPath);
75
73
  }
76
- else if (path_1.default.posix.isAbsolute(absPath)) {
77
- return path_1.default.posix.dirname(absPath);
78
- }
79
- else if (path_1.default.win32.isAbsolute(absPath)) {
80
- return path_1.default.win32.dirname(absPath);
74
+ if (node_path_1.default.posix.isAbsolute(absPath)) {
75
+ return node_path_1.default.posix.dirname(absPath);
81
76
  }
82
- else {
83
- throw new Error(`${absPath} is neither a posix nor a windows path, and there is no 'dirname' method defined in the file system`);
77
+ if (node_path_1.default.win32.isAbsolute(absPath)) {
78
+ return node_path_1.default.win32.dirname(absPath);
84
79
  }
80
+ throw new Error(`${absPath} is neither a posix nor a windows path, and there is no 'dirname' method defined in the file system`);
85
81
  };
86
82
  const mkdirp = (fs, p, callback) => {
87
83
  fs.mkdir(p, err => {
@@ -111,7 +107,7 @@ const mkdirp = (fs, p, callback) => {
111
107
  });
112
108
  return;
113
109
  }
114
- else if (err.code === "EEXIST") {
110
+ if (err.code === "EEXIST") {
115
111
  callback();
116
112
  return;
117
113
  }
@@ -1,15 +1,30 @@
1
- export = BatchedHash;
2
- declare class BatchedHash extends Hash {
3
- constructor(hash: any);
1
+ /// <reference types="node" />
2
+ /**
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/hash/BatchedHash.js
5
+ *
6
+ * MIT Licensed
7
+ * Author Tobias Koppers @sokra
8
+ * Copyright (c) JS Foundation and other contributors
9
+ * https://github.com/webpack/webpack/blob/main/LICENSE
10
+ */
11
+ import Hash from ".";
12
+ export default class BatchedHash extends Hash {
4
13
  string: string | undefined;
5
14
  encoding: string | undefined;
6
- hash: any;
15
+ hash: Hash;
16
+ constructor(hash: Hash);
7
17
  /**
8
18
  * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
9
- * @param {string|Buffer} data data
10
- * @param {string=} inputEncoding data encoding
11
- * @returns {this} updated hash
19
+ * @param data data
20
+ * @param inputEncoding data encoding
21
+ * @returns updated hash
12
22
  */
13
- update(data: string | Buffer, inputEncoding?: string | undefined): this;
23
+ update(data: string | Buffer, inputEncoding?: string): this;
24
+ /**
25
+ * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
26
+ * @param encoding encoding of the return value
27
+ * @returns digest
28
+ */
29
+ digest(encoding?: string): string | Buffer;
14
30
  }
15
- import Hash = require(".");
@@ -1,3 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
1
6
  /**
2
7
  * The following code is modified based on
3
8
  * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/hash/BatchedHash.js
@@ -7,11 +12,9 @@
7
12
  * Copyright (c) JS Foundation and other contributors
8
13
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
14
  */
10
- "use strict";
11
- const Hash = require(".");
12
- const MAX_SHORT_STRING = require("./wasm-hash").MAX_SHORT_STRING;
13
- class BatchedHash extends Hash {
14
- // @ts-expect-error
15
+ const _1 = __importDefault(require("."));
16
+ const wasm_hash_1 = require("./wasm-hash");
17
+ class BatchedHash extends _1.default {
15
18
  constructor(hash) {
16
19
  super();
17
20
  this.string = undefined;
@@ -20,15 +23,15 @@ class BatchedHash extends Hash {
20
23
  }
21
24
  /**
22
25
  * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
23
- * @param {string|Buffer} data data
24
- * @param {string=} inputEncoding data encoding
25
- * @returns {this} updated hash
26
+ * @param data data
27
+ * @param inputEncoding data encoding
28
+ * @returns updated hash
26
29
  */
27
30
  update(data, inputEncoding) {
28
31
  if (this.string !== undefined) {
29
32
  if (typeof data === "string" &&
30
33
  inputEncoding === this.encoding &&
31
- this.string.length + data.length < MAX_SHORT_STRING) {
34
+ this.string.length + data.length < wasm_hash_1.MAX_SHORT_STRING) {
32
35
  this.string += data;
33
36
  return this;
34
37
  }
@@ -36,7 +39,7 @@ class BatchedHash extends Hash {
36
39
  this.string = undefined;
37
40
  }
38
41
  if (typeof data === "string") {
39
- if (data.length < MAX_SHORT_STRING &&
42
+ if (data.length < wasm_hash_1.MAX_SHORT_STRING &&
40
43
  // base64 encoding is not valid since it may contain padding chars
41
44
  (!inputEncoding || !inputEncoding.startsWith("ba"))) {
42
45
  this.string = data;
@@ -53,8 +56,8 @@ class BatchedHash extends Hash {
53
56
  }
54
57
  /**
55
58
  * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
56
- * @param {string=} encoding encoding of the return value
57
- * @returns {string|Buffer} digest
59
+ * @param encoding encoding of the return value
60
+ * @returns digest
58
61
  */
59
62
  digest(encoding) {
60
63
  if (this.string !== undefined) {
@@ -63,4 +66,4 @@ class BatchedHash extends Hash {
63
66
  return this.hash.digest(encoding);
64
67
  }
65
68
  }
66
- module.exports = BatchedHash;
69
+ exports.default = BatchedHash;
@@ -1,18 +1,18 @@
1
- export = Hash;
2
- declare class Hash {
1
+ /// <reference types="node" />
2
+ export default class Hash {
3
3
  /**
4
4
  * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
5
5
  * @abstract
6
- * @param {string|Buffer} data data
7
- * @param {string=} inputEncoding data encoding
8
- * @returns {this} updated hash
6
+ * @param data data
7
+ * @param inputEncoding data encoding
8
+ * @returns updated hash
9
9
  */
10
- update(data: string | Buffer, inputEncoding?: string | undefined): this;
10
+ update(data: string | Buffer, inputEncoding?: string): this;
11
11
  /**
12
12
  * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
13
13
  * @abstract
14
- * @param {string=} encoding encoding of the return value
15
- * @returns {string|Buffer} digest
14
+ * @param encoding encoding of the return value
15
+ * @returns digest
16
16
  */
17
- digest(encoding?: string | undefined): string | Buffer;
17
+ digest(encoding?: string): string | Buffer;
18
18
  }
@@ -1,3 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
1
6
  /**
2
7
  * The following code is modified based on
3
8
  * https://github.com/webpack/webpack/tree/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/util/hash
@@ -7,30 +12,28 @@
7
12
  * Copyright (c) JS Foundation and other contributors
8
13
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
14
  */
10
- "use strict";
15
+ const AbstractMethodError_1 = __importDefault(require("../../lib/AbstractMethodError"));
11
16
  class Hash {
12
17
  /* istanbul ignore next */
13
18
  /**
14
19
  * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
15
20
  * @abstract
16
- * @param {string|Buffer} data data
17
- * @param {string=} inputEncoding data encoding
18
- * @returns {this} updated hash
21
+ * @param data data
22
+ * @param inputEncoding data encoding
23
+ * @returns updated hash
19
24
  */
20
25
  update(data, inputEncoding) {
21
- const AbstractMethodError = require("../../lib/AbstractMethodError");
22
- throw new AbstractMethodError();
26
+ throw new AbstractMethodError_1.default();
23
27
  }
24
28
  /* istanbul ignore next */
25
29
  /**
26
30
  * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
27
31
  * @abstract
28
- * @param {string=} encoding encoding of the return value
29
- * @returns {string|Buffer} digest
32
+ * @param encoding encoding of the return value
33
+ * @returns digest
30
34
  */
31
35
  digest(encoding) {
32
- const AbstractMethodError = require("../../lib/AbstractMethodError");
33
- throw new AbstractMethodError();
36
+ throw new AbstractMethodError_1.default();
34
37
  }
35
38
  }
36
- module.exports = Hash;
39
+ exports.default = Hash;
@@ -1,2 +1,29 @@
1
- declare const _exports: () => any;
2
- export = _exports;
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/hash/md4.js
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack/blob/main/LICENSE
9
+ */
10
+ /// <reference types="node" />
11
+ declare const _default: () => {
12
+ exports: WebAssembly.Exports & {
13
+ init: () => void;
14
+ update: (b: number) => void;
15
+ memory: WebAssembly.Memory;
16
+ final: (b: number) => void;
17
+ };
18
+ instancesPool: WebAssembly.Instance[];
19
+ buffered: number;
20
+ mem: Buffer;
21
+ chunkSize: number;
22
+ digestSize: number;
23
+ reset(): void;
24
+ update(data: string | Buffer, encoding?: BufferEncoding | undefined): any;
25
+ _updateWithShortString(data: string, encoding?: BufferEncoding | undefined): void;
26
+ _updateWithBuffer(data: Buffer): void;
27
+ digest(type: BufferEncoding): string | Buffer;
28
+ };
29
+ export default _default;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * The following code is modified based on
3
4
  * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/hash/md4.js
@@ -7,11 +8,14 @@
7
8
  * Copyright (c) JS Foundation and other contributors
8
9
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
10
  */
10
- "use strict";
11
- const create = require("./wasm-hash");
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const wasm_hash_1 = __importDefault(require("./wasm-hash"));
12
16
  //#region wasm code: md4 (../../../assembly/hash/md4.asm.ts) --initialMemory 1
13
17
  const md4 = new WebAssembly.Module(Buffer.from(
14
18
  // 2156 bytes
15
19
  "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", "base64"));
16
20
  //#endregion
17
- module.exports = create.bind(null, md4, [], 64, 32);
21
+ exports.default = wasm_hash_1.default.bind(null, md4, [], 64, 32);
@@ -1,6 +1,53 @@
1
- export = create;
2
- declare function create(wasmModule: any, instancesPool: any, chunkSize: any, digestSize: any): any;
3
- declare namespace create {
4
- export { MAX_SHORT_STRING };
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/hash/wasm-hash.js
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack/blob/main/LICENSE
9
+ */
10
+ /// <reference types="node" />
11
+ export declare const MAX_SHORT_STRING: number;
12
+ type Exports = WebAssembly.Instance["exports"] & {
13
+ init: () => void;
14
+ update: (b: number) => void;
15
+ memory: WebAssembly.Memory;
16
+ final: (b: number) => void;
17
+ };
18
+ declare class WasmHash {
19
+ exports: Exports;
20
+ instancesPool: WebAssembly.Instance[];
21
+ buffered: number;
22
+ mem: Buffer;
23
+ chunkSize: number;
24
+ digestSize: number;
25
+ /**
26
+ * @param instance wasm instance
27
+ * @param instancesPool pool of instances
28
+ * @param chunkSize size of data chunks passed to wasm
29
+ * @param digestSize size of digest returned by wasm
30
+ */
31
+ constructor(instance: WebAssembly.Instance, instancesPool: WebAssembly.Instance[], chunkSize: number, digestSize: number);
32
+ reset(): void;
33
+ /**
34
+ * @param data data
35
+ * @param encoding encoding
36
+ * @returns itself
37
+ */
38
+ update(data: Buffer | string, encoding?: BufferEncoding): this;
39
+ /**
40
+ * @param {string} data data
41
+ * @param {BufferEncoding=} encoding encoding
42
+ * @returns {void}
43
+ */
44
+ _updateWithShortString(data: string, encoding?: BufferEncoding): void;
45
+ /**
46
+ * @param data data
47
+ * @returns
48
+ */
49
+ _updateWithBuffer(data: Buffer): void;
50
+ digest(type: BufferEncoding): string | Buffer;
5
51
  }
6
- declare const MAX_SHORT_STRING: number;
52
+ declare const create: (wasmModule: WebAssembly.Module, instancesPool: WasmHash[], chunkSize: number, digestSize: number) => WasmHash;
53
+ export default create;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * The following code is modified based on
3
4
  * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/hash/wasm-hash.js
@@ -7,21 +8,22 @@
7
8
  * Copyright (c) JS Foundation and other contributors
8
9
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
10
  */
10
- "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MAX_SHORT_STRING = void 0;
11
13
  // 65536 is the size of a wasm memory page
12
14
  // 64 is the maximum chunk size for every possible wasm hash implementation
13
15
  // 4 is the maximum number of bytes per char for string encoding (max is utf-8)
14
16
  // ~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;
17
+ exports.MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & ~3;
16
18
  class WasmHash {
17
19
  /**
18
- * @param {WebAssembly.Instance} instance wasm instance
19
- * @param {WebAssembly.Instance[]} instancesPool pool of instances
20
- * @param {number} chunkSize size of data chunks passed to wasm
21
- * @param {number} digestSize size of digest returned by wasm
20
+ * @param instance wasm instance
21
+ * @param instancesPool pool of instances
22
+ * @param chunkSize size of data chunks passed to wasm
23
+ * @param digestSize size of digest returned by wasm
22
24
  */
23
25
  constructor(instance, instancesPool, chunkSize, digestSize) {
24
- const exports = /** @type {any} */ (instance.exports);
26
+ const exports = instance.exports;
25
27
  exports.init();
26
28
  this.exports = exports;
27
29
  this.mem = Buffer.from(exports.memory.buffer, 0, 65536);
@@ -35,15 +37,15 @@ class WasmHash {
35
37
  this.exports.init();
36
38
  }
37
39
  /**
38
- * @param {Buffer | string} data data
39
- * @param {BufferEncoding=} encoding encoding
40
- * @returns {this} itself
40
+ * @param data data
41
+ * @param encoding encoding
42
+ * @returns itself
41
43
  */
42
44
  update(data, encoding) {
43
45
  if (typeof data === "string") {
44
- while (data.length > MAX_SHORT_STRING) {
45
- this._updateWithShortString(data.slice(0, MAX_SHORT_STRING), encoding);
46
- data = data.slice(MAX_SHORT_STRING);
46
+ while (data.length > exports.MAX_SHORT_STRING) {
47
+ this._updateWithShortString(data.slice(0, exports.MAX_SHORT_STRING), encoding);
48
+ data = data.slice(exports.MAX_SHORT_STRING);
47
49
  }
48
50
  this._updateWithShortString(data, encoding);
49
51
  return this;
@@ -105,8 +107,8 @@ class WasmHash {
105
107
  }
106
108
  }
107
109
  /**
108
- * @param {Buffer} data data
109
- * @returns {void}
110
+ * @param data data
111
+ * @returns
110
112
  */
111
113
  _updateWithBuffer(data) {
112
114
  const { exports, buffered, mem } = this;
@@ -140,7 +142,6 @@ class WasmHash {
140
142
  data.copy(mem, 0, length - newBuffered, length);
141
143
  }
142
144
  }
143
- // @ts-expect-error
144
145
  digest(type) {
145
146
  const { exports, buffered, mem, digestSize } = this;
146
147
  exports.final(buffered);
@@ -153,16 +154,12 @@ class WasmHash {
153
154
  return Buffer.from(hex, "hex").toString(type);
154
155
  }
155
156
  }
156
- // @ts-expect-error
157
157
  const create = (wasmModule, instancesPool, chunkSize, digestSize) => {
158
158
  if (instancesPool.length > 0) {
159
159
  const old = instancesPool.pop();
160
160
  old.reset();
161
161
  return old;
162
162
  }
163
- else {
164
- return new WasmHash(new WebAssembly.Instance(wasmModule), instancesPool, chunkSize, digestSize);
165
- }
163
+ return new WasmHash(new WebAssembly.Instance(wasmModule), instancesPool, chunkSize, digestSize);
166
164
  };
167
- module.exports = create;
168
- module.exports.MAX_SHORT_STRING = MAX_SHORT_STRING;
165
+ exports.default = create;
@@ -1,2 +1,29 @@
1
- declare const _exports: () => any;
2
- export = _exports;
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/hash/xxhash64.js
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack/blob/main/LICENSE
9
+ */
10
+ /// <reference types="node" />
11
+ declare const _default: () => {
12
+ exports: WebAssembly.Exports & {
13
+ init: () => void;
14
+ update: (b: number) => void;
15
+ memory: WebAssembly.Memory;
16
+ final: (b: number) => void;
17
+ };
18
+ instancesPool: WebAssembly.Instance[];
19
+ buffered: number;
20
+ mem: Buffer;
21
+ chunkSize: number;
22
+ digestSize: number;
23
+ reset(): void;
24
+ update(data: string | Buffer, encoding?: BufferEncoding | undefined): any;
25
+ _updateWithShortString(data: string, encoding?: BufferEncoding | undefined): void;
26
+ _updateWithBuffer(data: Buffer): void;
27
+ digest(type: BufferEncoding): string | Buffer;
28
+ };
29
+ export default _default;