File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed
Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change 1- export const generateUUID = ( ) : string | undefined => {
1+ let _crypto : any
2+ import ( 'node:crypto' )
3+ . then ( ( c ) => ( _crypto = c ) )
4+ // eslint-disable-next-line unicorn/prefer-top-level-await
5+ . catch ( ( ) => null )
6+
7+ export function generateUUID ( ) : string | undefined {
28 try {
3- if ( ( globalThis as any ) . crypto ?. randomUUID ) {
4- return globalThis . crypto . randomUUID ( )
5- }
9+ const crypto : Crypto | undefined = ( globalThis as any ) . crypto || _crypto
10+ if ( ! crypto ) return undefined
11+ return crypto . randomUUID ( )
612 } catch { }
713 return undefined
814}
Original file line number Diff line number Diff line change 11{
22 "compilerOptions" : {
3- "target" : " ES2019 " ,
4- "lib" : [" ES2019 " , " DOM" ],
5- "module" : " ES2015 " ,
3+ "target" : " ES2022 " ,
4+ "lib" : [" ES2022 " , " DOM" ],
5+ "module" : " ESNext " ,
66 "moduleResolution" : " Node" ,
77 "resolveJsonModule" : true ,
88 "types" : [" node" ],
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const common = defineConfig({
88 platform : 'neutral' ,
99 target : 'es2022' ,
1010 splitting : false ,
11+ external : [ 'node:crypto' ] ,
1112} )
1213
1314export default defineConfig ( [
You can’t perform that action at this time.
0 commit comments