Skip to content

Commit 5efde45

Browse files
committed
Skip benchmarks when submodule isn’t cloned
1 parent 15600c8 commit 5efde45

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

_packages/api/test/api.bench.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
type SourceFile,
1212
SyntaxKind,
1313
} from "@typescript/ast";
14-
import fs from "node:fs";
14+
import fs, { existsSync } from "node:fs";
1515
import path from "node:path";
1616
import { fileURLToPath } from "node:url";
1717
import { Bench } from "tinybench";
@@ -23,6 +23,12 @@ if (isMain) {
2323
}
2424

2525
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+
2632
const bench = new Bench({
2733
name: "Sync API",
2834
teardown,
@@ -163,14 +169,14 @@ export async function runBenchmarks(singleIteration?: boolean) {
163169

164170
function spawnAPI() {
165171
api = new API({
166-
cwd: fileURLToPath(new URL("../../../", import.meta.url).toString()),
172+
cwd: repoRoot,
167173
tsserverPath: fileURLToPath(new URL(`../../../built/local/tsgo${process.platform === "win32" ? ".exe" : ""}`, import.meta.url).toString()),
168174
});
169175
}
170176

171177
function spawnAPIHosted() {
172178
api = new API({
173-
cwd: fileURLToPath(new URL("../../../", import.meta.url).toString()),
179+
cwd: repoRoot,
174180
tsserverPath: fileURLToPath(new URL(`../../../built/local/tsgo${process.platform === "win32" ? ".exe" : ""}`, import.meta.url).toString()),
175181
fs: createNodeFileSystem(),
176182
});

0 commit comments

Comments
 (0)