@@ -11,7 +11,7 @@ import {
11
11
type SourceFile ,
12
12
SyntaxKind ,
13
13
} from "@typescript/ast" ;
14
- import fs from "node:fs" ;
14
+ import fs , { existsSync } from "node:fs" ;
15
15
import path from "node:path" ;
16
16
import { fileURLToPath } from "node:url" ;
17
17
import { Bench } from "tinybench" ;
@@ -23,6 +23,12 @@ if (isMain) {
23
23
}
24
24
25
25
export async function runBenchmarks ( singleIteration ?: boolean ) {
26
+ const repoRoot = fileURLToPath ( new URL ( "../../../" , import . meta. url ) . toString ( ) ) ;
27
+ if ( ! existsSync ( path . join ( repoRoot , "_submodules/TypeScript/src/compiler" ) ) ) {
28
+ console . warn ( "Warning: TypeScript submodule is not cloned; skipping benchmarks." ) ;
29
+ return ;
30
+ }
31
+
26
32
const bench = new Bench ( {
27
33
name : "Sync API" ,
28
34
teardown,
@@ -163,14 +169,14 @@ export async function runBenchmarks(singleIteration?: boolean) {
163
169
164
170
function spawnAPI ( ) {
165
171
api = new API ( {
166
- cwd : fileURLToPath ( new URL ( "../../../" , import . meta . url ) . toString ( ) ) ,
172
+ cwd : repoRoot ,
167
173
tsserverPath : fileURLToPath ( new URL ( `../../../built/local/tsgo${ process . platform === "win32" ? ".exe" : "" } ` , import . meta. url ) . toString ( ) ) ,
168
174
} ) ;
169
175
}
170
176
171
177
function spawnAPIHosted ( ) {
172
178
api = new API ( {
173
- cwd : fileURLToPath ( new URL ( "../../../" , import . meta . url ) . toString ( ) ) ,
179
+ cwd : repoRoot ,
174
180
tsserverPath : fileURLToPath ( new URL ( `../../../built/local/tsgo${ process . platform === "win32" ? ".exe" : "" } ` , import . meta. url ) . toString ( ) ) ,
175
181
fs : createNodeFileSystem ( ) ,
176
182
} ) ;
0 commit comments