File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 1- import { createHash } from 'node:crypto'
1+ import crypto from 'node:crypto'
22import path from 'node:path'
33import type { types } from '@babel/core'
44import * as babel from '@babel/core'
@@ -293,8 +293,17 @@ function isDefineComponentCall(
293293 )
294294}
295295
296+ const hash =
297+ // eslint-disable-next-line n/no-unsupported-features/node-builtins -- crypto.hash is supported in Node 21.7.0+, 20.12.0+
298+ crypto . hash ??
299+ ( (
300+ algorithm : string ,
301+ data : crypto . BinaryLike ,
302+ outputEncoding : crypto . BinaryToTextEncoding ,
303+ ) => crypto . createHash ( algorithm ) . update ( data ) . digest ( outputEncoding ) )
304+
296305function getHash ( text : string ) {
297- return createHash ( 'sha256' ) . update ( text ) . digest ( 'hex' ) . substring ( 0 , 8 )
306+ return hash ( 'sha256' , text , 'hex' ) . substring ( 0 , 8 )
298307}
299308
300309export default vueJsxPlugin
Original file line number Diff line number Diff line change 11import fs from 'node:fs'
22import path from 'node:path'
3- import { createHash } from 'node:crypto'
3+ import crypto from 'node:crypto'
44import type { CompilerError , SFCDescriptor } from 'vue/compiler-sfc'
55import { normalizePath } from 'vite'
66import type { ResolvedOptions , VueQuery } from '../index'
@@ -120,6 +120,15 @@ export function setSrcDescriptor(
120120 cache . set ( filename , entry )
121121}
122122
123+ const hash =
124+ // eslint-disable-next-line n/no-unsupported-features/node-builtins -- crypto.hash is supported in Node 21.7.0+, 20.12.0+
125+ crypto . hash ??
126+ ( (
127+ algorithm : string ,
128+ data : crypto . BinaryLike ,
129+ outputEncoding : crypto . BinaryToTextEncoding ,
130+ ) => crypto . createHash ( algorithm ) . update ( data ) . digest ( outputEncoding ) )
131+
123132function getHash ( text : string ) : string {
124- return createHash ( 'sha256' ) . update ( text ) . digest ( 'hex' ) . substring ( 0 , 8 )
133+ return hash ( 'sha256' , text , 'hex' ) . substring ( 0 , 8 )
125134}
You can’t perform that action at this time.
0 commit comments