Skip to content

Commit e9099b5

Browse files
committed
Fix windows paths
1 parent b4a48fe commit e9099b5

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

_packages/api/bench/api.bench.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "@typescript/ast";
1313
import fs from "node:fs";
1414
import path from "node:path";
15+
import { fileURLToPath } from "node:url";
1516
import { Bench } from "tinybench";
1617
import ts from "typescript";
1718

@@ -124,15 +125,15 @@ console.table(bench.table());
124125

125126
function spawnAPI() {
126127
api = new API({
127-
cwd: new URL("../../../", import.meta.url).pathname,
128-
tsserverPath: new URL(`../../../built/local/tsgo${process.platform === "win32" ? ".exe" : ""}`, import.meta.url).pathname,
128+
cwd: fileURLToPath(new URL("../../../", import.meta.url).toString()),
129+
tsserverPath: fileURLToPath(new URL(`../../../built/local/tsgo${process.platform === "win32" ? ".exe" : ""}`, import.meta.url).toString()),
129130
});
130131
}
131132

132133
function spawnAPIHosted() {
133134
api = new API({
134-
cwd: new URL("../../../", import.meta.url).pathname,
135-
tsserverPath: new URL("../../../built/local/tsgo", import.meta.url).pathname,
135+
cwd: fileURLToPath(new URL("../../../", import.meta.url).toString()),
136+
tsserverPath: fileURLToPath(new URL(`../../../built/local/tsgo${process.platform === "win32" ? ".exe" : ""}`, import.meta.url).toString()),
136137
fs: createNodeFileSystem(),
137138
});
138139
}
@@ -142,7 +143,7 @@ function loadProject() {
142143
}
143144

144145
function tsCreateProgram() {
145-
const configFileName = new URL("../../../_submodules/TypeScript/src/compiler/tsconfig.json", import.meta.url).pathname;
146+
const configFileName = fileURLToPath(new URL("../../../_submodules/TypeScript/src/compiler/tsconfig.json", import.meta.url).toString());
146147
const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);
147148
const parsedCommandLine = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configFileName));
148149
const host = ts.createCompilerHost(parsedCommandLine.options);
@@ -172,7 +173,7 @@ function getProgramTS() {
172173
}
173174

174175
function tsGetProgramTS() {
175-
tsFile = tsProgram.getSourceFile(new URL("../../../_submodules/TypeScript/src/compiler/program.ts", import.meta.url).pathname)!;
176+
tsFile = tsProgram.getSourceFile(fileURLToPath(new URL("../../../_submodules/TypeScript/src/compiler/program.ts", import.meta.url).toString()))!;
176177
}
177178

178179
function getCheckerTS() {

_packages/api/test/api.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
describe,
1818
test,
1919
} from "node:test";
20+
import { fileURLToPath } from "node:url";
2021

2122
const defaultFiles = {
2223
"/tsconfig.json": "{}",
@@ -151,8 +152,8 @@ test("Dispose", () => {
151152

152153
function spawnAPI(files: Record<string, string> = defaultFiles) {
153154
return new API({
154-
cwd: new URL("../../../", import.meta.url).pathname,
155-
tsserverPath: new URL(`../../../built/local/tsgo${process.platform === "win32" ? ".exe" : ""}`, import.meta.url).pathname,
155+
cwd: fileURLToPath(new URL("../../../", import.meta.url).toString()),
156+
tsserverPath: fileURLToPath(new URL(`../../../built/local/tsgo${process.platform === "win32" ? ".exe" : ""}`, import.meta.url).toString()),
156157
fs: createVirtualFileSystem(files),
157158
});
158159
}

0 commit comments

Comments
 (0)