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 {
2
8
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 ( )
6
12
} catch { }
7
13
return undefined
8
14
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"compilerOptions" : {
3
- "target" : " ES2019 " ,
4
- "lib" : [" ES2019 " , " DOM" ],
5
- "module" : " ES2015 " ,
3
+ "target" : " ES2022 " ,
4
+ "lib" : [" ES2022 " , " DOM" ],
5
+ "module" : " ESNext " ,
6
6
"moduleResolution" : " Node" ,
7
7
"resolveJsonModule" : true ,
8
8
"types" : [" node" ],
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const common = defineConfig({
8
8
platform : 'neutral' ,
9
9
target : 'es2022' ,
10
10
splitting : false ,
11
+ external : [ 'node:crypto' ] ,
11
12
} )
12
13
13
14
export default defineConfig ( [
You can’t perform that action at this time.
0 commit comments