8000 perf: use `hash` to replace `createHash` · unplugin/unplugin-vue@fb75070 · GitHub
[go: up one dir, main page]

Skip to content

Commit fb75070

Browse files
committed
perf: use hash to replace createHash
ref: vitejs/vite-plugin-vue@de88394
1 parent 739d78b commit fb75070

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/core/utils/descriptorCache.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createHash } from 'node:crypto'
1+
import crypto from 'node:crypto'
22
import fs from 'node:fs'
33
import path from 'node:path'
44
import { normalizePath } from 'vite'
@@ -121,6 +121,14 @@ export function setSrcDescriptor(
121121
cache.set(filename, entry)
122122
}
123123

124+
const hash =
125+
crypto.hash ??
126+
((
127+
algorithm: string,
128+
data: crypto.BinaryLike,
129+
outputEncoding: crypto.BinaryToTextEncoding,
130+
) => crypto.createHash(algorithm).update(data).digest(outputEncoding))
131+
124132
function getHash(text: string): string {
125-
return createHash('sha256').update(text).digest('hex').slice(0, 8)
133+
return hash('sha256', text, 'hex').slice(0, 8)
126134
}

0 commit comments

Comments
 (0)
0