File tree 2 files changed +22
-4
lines changed
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'
2
2
import path from 'node:path'
3
3
import type { types } from '@babel/core'
4
4
import * as babel from '@babel/core'
@@ -293,8 +293,17 @@ function isDefineComponentCall(
293
293
)
294
294
}
295
295
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
+
296
305
function getHash ( text : string ) {
297
- return createHash ( 'sha256' ) . update ( text ) . digest ( 'hex' ) . substring ( 0 , 8 )
306
+ return hash ( 'sha256' , text , 'hex' ) . substring ( 0 , 8 )
298
307
}
299
308
300
309
export default vueJsxPlugin
Original file line number Diff line number Diff line change 1
1
import fs from 'node:fs'
2
2
import path from 'node:path'
3
- import { createHash } from 'node:crypto'
3
+ import crypto from 'node:crypto'
4
4
import type { CompilerError , SFCDescriptor } from 'vue/compiler-sfc'
5
5
import { normalizePath } from 'vite'
6
6
import type { ResolvedOptions , VueQuery } from '../index'
@@ -120,6 +120,15 @@ export function setSrcDescriptor(
120
120
cache . set ( filename , entry )
121
121
}
122
122
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
+
123
132
function getHash ( text : string ) : string {
124
- return createHash ( 'sha256' ) . update ( text ) . digest ( 'hex' ) . substring ( 0 , 8 )
133
+ return hash ( 'sha256' , text , 'hex' ) . substring ( 0 , 8 )
125
134
}
You can’t perform that action at this time.
0 commit comments