Skip to content

Commit 1e97d10

Browse files
authored
Enable getExePath to work on Node 16
1 parent 6b60f4a commit 1e97d10

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

_packages/native-preview/lib/getExePath.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,22 @@ export default function getExePath() {
2121
else {
2222
// We're actually running from an installed package.
2323
const platformPackageName = "@typescript/" + expectedPackage;
24-
let packageJson;
2524
try {
2625
// v20.6.0, v18.19.0
27-
packageJson = import.meta.resolve(platformPackageName + "/package.json");
26+
const packageJson = import.meta.resolve(platformPackageName + "/package.json");
27+
const packageJsonPath = fileURLToPath(packageJson);
28+
exeDir = path.join(path.dirname(packageJsonPath), "lib");
2829
}
2930
catch (e) {
30-
throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk.");
31+
// Failed to resolve: this might be due to an older Node version that doesn't support import.meta.resolve.
32+
if (e instanceof TypeError && e.message?.includes("resolve is not a function")) {
33+
// v16.20.1
34+
exeDir = path.resolve(__dirname, "..", "node_modules", platformPackageName, "lib");
35+
} else {
36+
throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk.");
37+
}
3138
}
32-
const packageJsonPath = fileURLToPath(packageJson);
33-
exeDir = path.join(path.dirname(packageJsonPath), "lib");
39+
3440
}
3541

3642
const exe = path.join(exeDir, "tsgo" + (process.platform === "win32" ? ".exe" : ""));
@@ -41,3 +47,4 @@ export default function getExePath() {
4147

4248
return exe;
4349
}
50+

0 commit comments

Comments
 (0)