Skip to content

Commit 76bd382

Browse files
committedFeb 20, 2025·
build: minify dist/crypto/node
1 parent d9273a3 commit 76bd382

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
 

‎build.config.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ export default defineBuildConfig({
88
opts.plugins.push({
99
name: "selective-minify",
1010
async transform(code, id) {
11-
if (id.includes("crypto/js") || id.includes("serialize")) {
11+
if (id.includes("crypto") || id.includes("serialize")) {
1212
const res = await transform(code, { minify: true });
13-
return res.code.replace("=function(){", "=/*@__PURE__*/function(){");
13+
return res.code.replace(
14+
"=function(){",
15+
"=/*@__PURE__*/function(){",
16+
);
1417
}
1518
},
1619
});

‎src/crypto/node/index.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { createHash } from "node:crypto";
55
const fastHash = /*@__PURE__*/ (() =>
66
globalThis.process?.getBuiltinModule?.("crypto")?.hash)();
77

8+
const algorithm = "sha256";
9+
const encoding = "base64url";
10+
811
/**
912
* Hashes a string using the SHA-256 algorithm and encodes it in Base64URL format.
1013
*
@@ -14,14 +17,14 @@ const fastHash = /*@__PURE__*/ (() =>
1417
*/
1518
export function digest(data: string): string {
1619
if (fastHash) {
17-
return fastHash("sha256", data, "base64url");
20+
return fastHash(algorithm, data, encoding);
1821
}
1922

20-
const h = createHash("sha256").update(data);
23+
const h = createHash(algorithm).update(data);
2124

2225
// Use digest().toString("base64url") as workaround for stackblitz
2326
// https://github.com/unjs/ohash/issues/115
2427
return globalThis.process?.versions?.webcontainer
25-
? h.digest().toString("base64url")
26-
: h.digest("base64url");
28+
? h.digest().toString(encoding)
29+
: h.digest(encoding);
2730
}

0 commit comments

Comments
 (0)
Please sign in to comment.