@@ -3,18 +3,23 @@ import type { Fn, Statistics } from './types';
3
3
4
4
/**
5
5
* The JavaScript runtime environment.
6
+ * @see https://runtime-keys.proposal.wintercg.org/
6
7
*/
7
8
export enum JSRuntime {
8
9
v8 = 'v8' ,
9
10
bun = 'bun' ,
10
11
deno = 'deno' ,
11
12
node = 'node' ,
13
+ netlify = 'netlify' ,
14
+ 'edge-light' = 'edge-light' ,
15
+ lagon = 'lagon' ,
16
+ fastly = 'fastly' ,
12
17
'quickjs-ng' = 'quickjs-ng' ,
13
18
spidermonkey = 'spidermonkey' ,
14
19
hermes = 'hermes' ,
15
20
jsc = 'jsc' ,
16
21
workerd = 'workerd' ,
17
- 'XS Moddable' = 'XS Moddable ' ,
22
+ moddable = 'moddable ' ,
18
23
browser = 'browser' ,
19
24
}
20
25
@@ -35,10 +40,18 @@ const isQuickJsNg = !!(globalThis as any).navigator?.userAgent
35
40
?. toLowerCase ?.( )
36
41
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
37
42
?. includes ?.( 'quickjs-ng' ) ;
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
44
+ const isNetlify = typeof ( globalThis as any ) . Netlify === 'object' ;
45
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
46
+ const isEdgeLight = typeof ( globalThis as any ) . EdgeRuntime === 'string' ;
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
48
+ const isLagon = ! ! ( globalThis as any ) . __lagon__ ;
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
50
+ const isFastly = ! ! ( globalThis as any ) . fastly ;
38
51
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unnecessary-condition
39
52
const isSpiderMonkey = ! ! ( globalThis as any ) . inIon && ! ! ( globalThis as any ) . performance ?. mozMemory ;
40
53
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
41
- const isXsModdable = ! ! ( globalThis as any ) . $262
54
+ const isModdable = ! ! ( globalThis as any ) . $262
42
55
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
43
56
&& ! ! ( globalThis as any ) . lockdown
44
57
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
@@ -52,25 +65,25 @@ const isJsc = !!(globalThis as any).$
52
65
const isBrowser = ! ! ( globalThis as any ) . window && ! ! ( globalThis as any ) . navigator ;
53
66
54
67
export const runtime : JSRuntime | 'unknown' = ( ( ) => {
55
- if ( isV8 ) return JSRuntime . v8 ;
56
- if ( isSpiderMonkey ) return JSRuntime . spidermonkey ;
57
- if ( isQuickJsNg ) return JSRuntime [ 'quickjs-ng' ] ;
58
- if ( isXsModdable ) return JSRuntime [ 'XS Moddable' ] ;
59
- if ( isJsc ) return JSRuntime . jsc ;
60
68
if ( isBun ) return JSRuntime . bun ;
61
69
if ( isDeno ) return JSRuntime . deno ;
62
70
if ( isNode ) return JSRuntime . node ;
63
71
if ( isHermes ) return JSRuntime . hermes ;
72
+ if ( isNetlify ) return JSRuntime . netlify ;
73
+ if ( isEdgeLight ) return JSRuntime [ 'edge-light' ] ;
74
+ if ( isLagon ) return JSRuntime . lagon ;
75
+ if ( isFastly ) return JSRuntime . fastly ;
64
76
if ( isWorkerd ) return JSRuntime . workerd ;
77
+ if ( isQuickJsNg ) return JSRuntime [ 'quickjs-ng' ] ;
78
+ if ( isModdable ) return JSRuntime . moddable ;
79
+ if ( isV8 ) return JSRuntime . v8 ;
80
+ if ( isSpiderMonkey ) return JSRuntime . spidermonkey ;
81
+ if ( isJsc ) return JSRuntime . jsc ;
65
82
if ( isBrowser ) return JSRuntime . browser ;
66
83
return 'unknown' ;
67
84
} ) ( ) ;
68
85
69
86
export const runtimeVersion : string = ( ( ) => {
70
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call,
71
- if ( runtime === JSRuntime . v8 ) return ( globalThis as any ) . version ?.( ) as string ;
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call,
73
- if ( runtime === JSRuntime [ 'quickjs-ng' ] ) return ( globalThis as any ) . navigator ?. userAgent ?. split ?.( '/' ) [ 1 ] as string ;
74
87
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
75
88
if ( runtime === JSRuntime . bun ) return ( globalThis as any ) . Bun ?. version as string ;
76
89
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
@@ -84,6 +97,10 @@ export const runtimeVersion: string = (() => {
84
97
'OSS Release Version'
85
98
] as string ;
86
99
}
100
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call,
101
+ if ( runtime === JSRuntime . v8 ) return ( globalThis as any ) . version ?.( ) as string ;
102
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call,
103
+ if ( runtime === JSRuntime [ 'quickjs-ng' ] ) return ( globalThis as any ) . navigator ?. userAgent ?. split ?.( '/' ) [ 1 ] as string ;
87
104
return 'unknown' ;
88
105
} ) ( ) ;
89
106
0 commit comments