@rspack/core 1.0.0-alpha.5 → 1.0.0-beta.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.
- package/compiled/zod/index.d.ts +138 -52
- package/compiled/zod/index.js +300 -103
- package/compiled/zod/package.json +1 -1
- package/compiled/zod-validation-error/index.js +6 -6
- package/dist/Compilation.d.ts +22 -4
- package/dist/Compilation.js +64 -49
- package/dist/Compiler.d.ts +11 -10
- package/dist/Compiler.js +42 -42
- package/dist/ErrorHelpers.js +2 -4
- package/dist/Module.d.ts +1 -0
- package/dist/Module.js +3 -6
- package/dist/ModuleTypeConstants.d.ts +45 -69
- package/dist/ModuleTypeConstants.js +24 -77
- package/dist/NormalModule.d.ts +1 -0
- package/dist/NormalModule.js +1 -0
- package/dist/Stats.js +4 -6
- package/dist/Template.d.ts +31 -147
- package/dist/Template.js +40 -236
- package/dist/builtin-loader/lightningcss/index.d.ts +89 -0
- package/dist/builtin-loader/lightningcss/index.js +175 -0
- package/dist/builtin-plugin/APIPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +1 -1
- package/dist/builtin-plugin/AssetModulesPlugin.d.ts +1 -1
- package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +1 -1
- package/dist/builtin-plugin/BannerPlugin.d.ts +25 -49
- package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +1 -1
- package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +1 -1
- package/dist/builtin-plugin/CopyRspackPlugin.d.ts +1 -1
- package/dist/builtin-plugin/CssModulesPlugin.d.ts +1 -1
- package/dist/builtin-plugin/DataUriPlugin.d.ts +1 -1
- package/dist/builtin-plugin/DefinePlugin.d.ts +1 -1
- package/dist/builtin-plugin/DefinePlugin.js +9 -13
- package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +1 -1
- package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +1 -1
- package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +1 -1
- package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/EntryPlugin.d.ts +4 -3
- package/dist/builtin-plugin/EntryPlugin.js +1 -0
- package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +1 -1
- package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ExternalsPlugin.d.ts +29 -5
- package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.d.ts +1 -1
- package/dist/builtin-plugin/FileUriPlugin.d.ts +1 -1
- package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +1 -1
- package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +9 -9
- package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +1 -1
- package/dist/builtin-plugin/IgnorePlugin.d.ts +1 -1
- package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +1 -1
- package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +2 -2
- package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +1 -1
- package/dist/builtin-plugin/JsonModulesPlugin.d.ts +1 -1
- package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +1 -1
- package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +4 -1
- package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +1 -1
- package/dist/builtin-plugin/MangleExportsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +1 -1
- package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/NaturalChunkIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/NaturalModuleIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/NodeTargetPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ProgressPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ProvidePlugin.d.ts +1 -1
- package/dist/builtin-plugin/RealContentHashPlugin.d.ts +1 -1
- package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +1 -1
- package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +1 -1
- package/dist/builtin-plugin/RuntimePlugin.d.ts +1 -1
- package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +1 -1
- package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +1 -1
- package/dist/builtin-plugin/SplitChunksPlugin.js +5 -15
- package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +1 -1
- package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +1 -1
- package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +15 -23
- package/dist/builtin-plugin/WarnCaseSensitiveModulesPlugin.d.ts +1 -1
- package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +1 -1
- package/dist/builtin-plugin/base.d.ts +1 -1
- package/dist/builtin-plugin/base.js +1 -3
- package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -3
- package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +17 -66
- package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +2 -0
- package/dist/builtin-plugin/css-extract/hmr/{normalize-url.js → normalizeUrl.js} +15 -24
- package/dist/builtin-plugin/css-extract/loader.d.ts +8 -3
- package/dist/builtin-plugin/css-extract/loader.js +28 -17
- package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +1 -1
- package/dist/config/adapter.d.ts +1 -1
- package/dist/config/adapter.js +39 -25
- package/dist/config/adapterRuleUse.d.ts +5 -5
- package/dist/config/adapterRuleUse.js +23 -1
- package/dist/config/browserslistTargetHandler.d.ts +17 -15
- package/dist/config/browserslistTargetHandler.js +27 -33
- package/dist/config/defaults.js +27 -31
- package/dist/config/normalization.d.ts +8 -3
- package/dist/config/normalization.js +7 -5
- package/dist/config/target.d.ts +48 -109
- package/dist/config/target.js +50 -86
- package/dist/config/zod.d.ts +2660 -2305
- package/dist/config/zod.js +38 -19
- package/dist/container/ContainerPlugin.d.ts +7 -7
- package/dist/container/ContainerReferencePlugin.d.ts +1 -1
- package/dist/container/ModuleFederationRuntimePlugin.d.ts +1 -1
- package/dist/container/options.js +1 -1
- package/dist/exports.d.ts +4 -4
- package/dist/exports.js +2 -2
- package/dist/lib/AbstractMethodError.d.ts +12 -3
- package/dist/lib/AbstractMethodError.js +29 -21
- package/dist/lib/Cache.d.ts +40 -46
- package/dist/lib/Cache.js +43 -78
- package/dist/lib/CacheFacade.d.ts +119 -143
- package/dist/lib/CacheFacade.js +123 -123
- package/dist/lib/EntryOptionPlugin.d.ts +19 -2
- package/dist/lib/EntryOptionPlugin.js +22 -6
- package/dist/lib/EnvironmentPlugin.d.ts +17 -10
- package/dist/lib/EnvironmentPlugin.js +16 -15
- package/dist/lib/HookWebpackError.d.ts +27 -33
- package/dist/lib/HookWebpackError.js +33 -34
- package/dist/lib/IgnoreWarningsPlugin.d.ts +25 -0
- package/dist/lib/{ignoreWarningsPlugin.js → IgnoreWarningsPlugin.js} +17 -0
- package/dist/lib/LoaderOptionsPlugin.d.ts +18 -9
- package/dist/lib/LoaderOptionsPlugin.js +38 -14
- package/dist/lib/LoaderTargetPlugin.d.ts +17 -8
- package/dist/lib/LoaderTargetPlugin.js +17 -15
- package/dist/lib/ModuleFilenameHelpers.d.ts +10 -1
- package/dist/lib/ModuleFilenameHelpers.js +10 -3
- package/dist/lib/NormalModuleReplacementPlugin.d.ts +15 -5
- package/dist/lib/NormalModuleReplacementPlugin.js +15 -5
- package/dist/lib/WebpackError.d.ts +29 -22
- package/dist/lib/WebpackError.js +17 -29
- package/dist/lib/cache/getLazyHashedEtag.d.ts +24 -24
- package/dist/lib/cache/getLazyHashedEtag.js +20 -23
- package/dist/lib/cache/mergeEtags.d.ts +15 -9
- package/dist/lib/cache/mergeEtags.js +23 -22
- package/dist/lib/formatLocation.d.ts +13 -8
- package/dist/lib/formatLocation.js +20 -20
- package/dist/loader-runner/LoaderLoadingError.d.ts +11 -1
- package/dist/loader-runner/LoaderLoadingError.js +3 -5
- package/dist/loader-runner/index.js +7 -9
- package/dist/loader-runner/loadLoader.d.ts +11 -2
- package/dist/loader-runner/loadLoader.js +17 -19
- package/dist/logging/createConsoleLogger.js +2 -6
- package/dist/logging/truncateArgs.js +5 -9
- package/dist/node/nodeConsole.js +1 -3
- package/dist/rspackOptionsApply.js +2 -2
- package/dist/stats/DefaultStatsFactoryPlugin.js +18 -8
- package/dist/stats/DefaultStatsPresetPlugin.js +4 -4
- package/dist/stats/DefaultStatsPrinterPlugin.js +11 -16
- package/dist/stats/StatsFactory.js +13 -17
- package/dist/stats/StatsPrinter.js +7 -9
- package/dist/util/AssetInfo.js +11 -7
- package/dist/util/SplitChunkSize.js +1 -1
- package/dist/util/cleverMerge.d.ts +33 -57
- package/dist/util/cleverMerge.js +89 -145
- package/dist/util/comparators.d.ts +1 -1
- package/dist/util/comparators.js +3 -5
- package/dist/util/createHash.d.ts +4 -3
- package/dist/util/createHash.js +31 -45
- package/dist/util/fs.js +9 -13
- package/dist/util/hash/BatchedHash.d.ts +24 -9
- package/dist/util/hash/BatchedHash.js +16 -13
- package/dist/util/hash/index.d.ts +9 -9
- package/dist/util/hash/index.js +14 -11
- package/dist/util/hash/md4.d.ts +29 -2
- package/dist/util/hash/md4.js +7 -3
- package/dist/util/hash/wasm-hash.d.ts +52 -5
- package/dist/util/hash/wasm-hash.js +19 -22
- package/dist/util/hash/xxhash64.d.ts +29 -2
- package/dist/util/hash/xxhash64.js +7 -3
- package/dist/util/identifier.js +9 -15
- package/dist/util/index.js +1 -1
- package/dist/util/memoize.js +7 -9
- package/package.json +9 -8
- package/compiled/enhanced-resolve/index.js +0 -5566
- package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +0 -2
- package/dist/lib/ignoreWarningsPlugin.d.ts +0 -7
package/dist/util/createHash.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
25
|
+
class BulkUpdateDecorator extends hash_1.default {
|
|
20
26
|
/**
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
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
|
|
40
|
-
* @param
|
|
41
|
-
* @returns
|
|
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
|
|
69
|
-
* @returns
|
|
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
|
|
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
|
|
106
|
-
* @param
|
|
107
|
-
* @returns
|
|
111
|
+
* @param data data
|
|
112
|
+
* @param _inputEncoding data encoding
|
|
113
|
+
* @returns updated hash
|
|
108
114
|
*/
|
|
109
|
-
update(data,
|
|
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
|
|
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
|
|
121
|
-
* @returns
|
|
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
|
|
134
|
-
* @returns
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
162
|
-
crypto = require("node:crypto");
|
|
163
|
-
return new BulkUpdateDecorator(() => crypto.createHash("md4"), "md4");
|
|
151
|
+
return new BulkUpdateDecorator(() => node_crypto_1.default.createHash("md4"), "md4");
|
|
164
152
|
default:
|
|
165
|
-
|
|
166
|
-
crypto = require("node: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
|
@@ -33,7 +33,7 @@ function rmrf(fs, p, callback) {
|
|
|
33
33
|
fs.rmdir(p, callback);
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
|
|
36
|
+
for (const file of files) {
|
|
37
37
|
(0, node_assert_1.default)(typeof file === "string");
|
|
38
38
|
const fullPath = join(fs, p, file);
|
|
39
39
|
rmrf(fs, fullPath, 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
|
-
|
|
62
|
+
if (node_path_1.default.posix.isAbsolute(rootPath)) {
|
|
63
63
|
return node_path_1.default.posix.join(rootPath, filename);
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
if (node_path_1.default.win32.isAbsolute(rootPath)) {
|
|
66
66
|
return node_path_1.default.win32.join(rootPath, filename);
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
throw new Error(`${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system`);
|
|
70
|
-
}
|
|
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
|
-
|
|
74
|
+
if (node_path_1.default.posix.isAbsolute(absPath)) {
|
|
77
75
|
return node_path_1.default.posix.dirname(absPath);
|
|
78
76
|
}
|
|
79
|
-
|
|
77
|
+
if (node_path_1.default.win32.isAbsolute(absPath)) {
|
|
80
78
|
return node_path_1.default.win32.dirname(absPath);
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
throw new Error(`${absPath} is neither a posix nor a windows path, and there is no 'dirname' method defined in the file system`);
|
|
84
|
-
}
|
|
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
|
-
|
|
110
|
+
if (err.code === "EEXIST") {
|
|
115
111
|
callback();
|
|
116
112
|
return;
|
|
117
113
|
}
|
|
@@ -1,15 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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:
|
|
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
|
|
10
|
-
* @param
|
|
11
|
-
* @returns
|
|
19
|
+
* @param data data
|
|
20
|
+
* @param inputEncoding data encoding
|
|
21
|
+
* @returns updated hash
|
|
12
22
|
*/
|
|
13
|
-
update(data: string | Buffer, inputEncoding?: string
|
|
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
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
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
|
|
24
|
-
* @param
|
|
25
|
-
* @returns
|
|
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
|
|
57
|
-
* @returns
|
|
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
|
-
|
|
69
|
+
exports.default = BatchedHash;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
6
|
+
* @param data data
|
|
7
|
+
* @param inputEncoding data encoding
|
|
8
|
+
* @returns updated hash
|
|
9
9
|
*/
|
|
10
|
-
update(data: string | Buffer, inputEncoding?: string
|
|
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
|
|
15
|
-
* @returns
|
|
14
|
+
* @param encoding encoding of the return value
|
|
15
|
+
* @returns digest
|
|
16
16
|
*/
|
|
17
|
-
digest(encoding?: string
|
|
17
|
+
digest(encoding?: string): string | Buffer;
|
|
18
18
|
}
|
package/dist/util/hash/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
17
|
-
* @param
|
|
18
|
-
* @returns
|
|
21
|
+
* @param data data
|
|
22
|
+
* @param inputEncoding data encoding
|
|
23
|
+
* @returns updated hash
|
|
19
24
|
*/
|
|
20
25
|
update(data, inputEncoding) {
|
|
21
|
-
|
|
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
|
|
29
|
-
* @returns
|
|
32
|
+
* @param encoding encoding of the return value
|
|
33
|
+
* @returns digest
|
|
30
34
|
*/
|
|
31
35
|
digest(encoding) {
|
|
32
|
-
|
|
33
|
-
throw new AbstractMethodError();
|
|
36
|
+
throw new AbstractMethodError_1.default();
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
|
-
|
|
39
|
+
exports.default = Hash;
|
package/dist/util/hash/md4.d.ts
CHANGED
|
@@ -1,2 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
package/dist/util/hash/md4.js
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
21
|
+
exports.default = wasm_hash_1.default.bind(null, md4, [], 64, 32);
|
|
@@ -1,6 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
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
|
-
"
|
|
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
|
-
|
|
17
|
+
exports.MAX_SHORT_STRING = Math.floor((65536 - 64) / 4) & ~3;
|
|
16
18
|
class WasmHash {
|
|
17
19
|
/**
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
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 =
|
|
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
|
|
39
|
-
* @param
|
|
40
|
-
* @returns
|
|
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
|
|
109
|
-
* @returns
|
|
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
|
-
|
|
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
|
-
|
|
168
|
-
module.exports.MAX_SHORT_STRING = MAX_SHORT_STRING;
|
|
165
|
+
exports.default = create;
|
|
@@ -1,2 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|