File tree 1 file changed +11
-2
lines changed
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,16 @@ class Benchmark {
19
19
this . _time = 0n ;
20
20
21
21
// Use the file name as the name of the benchmark
22
- this . name = require . main . filename . slice ( __dirname . length + 1 ) ;
22
+ // For esm, require.main is undefined so probe filename from error stack
23
+ this . mainfilename = require . main
24
+ ? require . main . filename
25
+ : ( new Error ) . stack . split ( '\n' ) [ 3 ]
26
+ . match ( / ^ .* ( \( | a t ) ( .* ) : [ \d ] * : [ \d ] * .* $ / ) [ 2 ]
27
+ . replace ( / ^ f i l e : \/ \/ / , '' )
28
+
29
+ this . name = require . main
30
+ ? require . main . filename . slice ( __dirname . length + 1 )
31
+ : this . mainfilename . match ( / [ ^ \/ ] * $ / ) [ 0 ]
23
32
24
33
// Execution arguments i.e. flags used to run the jobs
25
34
this . flags = process . env . NODE_BENCHMARK_FLAGS ?. split ( / \s + / ) ?? [ ] ;
@@ -224,7 +233,7 @@ class Benchmark {
224
233
childArgs . push ( `${ key } =${ value } ` ) ;
225
234
}
226
235
227
- const child = child_process . fork ( require . main . filename , childArgs , {
236
+ const child = child_process . fork ( this . mainfilename , childArgs , {
228
237
env : childEnv ,
229
238
execArgv : this . flags . concat ( process . execArgv ) ,
230
239
} ) ;
You can’t perform that action at this time.
0 commit comments