Skip to content

Commit 33fe47d

Browse files
authored
fix: Enable getExePath to work on Node 16 (#2191)
1 parent 41e1964 commit 33fe47d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

_packages/native-preview/lib/getExePath.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from "node:fs";
2+
import module from "node:module";
23
import path from "node:path";
34
import { fileURLToPath } from "node:url";
45

@@ -21,16 +22,23 @@ export default function getExePath() {
2122
else {
2223
// We're actually running from an installed package.
2324
const platformPackageName = "@typescript/" + expectedPackage;
24-
let packageJson;
2525
try {
26-
// v20.6.0, v18.19.0
27-
packageJson = import.meta.resolve(platformPackageName + "/package.json");
26+
if (typeof import.meta.resolve === "undefined") {
27+
// v16.20.1
28+
const require = module.createRequire(import.meta.url);
29+
const packageJson = require.resolve(platformPackageName + "/package.json");
30+
exeDir = path.join(path.dirname(packageJson), "lib");
31+
}
32+
else {
33+
// v20.6.0, v18.19.0
34+
const packageJson = import.meta.resolve(platformPackageName + "/package.json");
35+
const packageJsonPath = fileURLToPath(packageJson);
36+
exeDir = path.join(path.dirname(packageJsonPath), "lib");
37+
}
2838
}
2939
catch (e) {
3040
throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk.");
3141
}
32-
const packageJsonPath = fileURLToPath(packageJson);
33-
exeDir = path.join(path.dirname(packageJsonPath), "lib");
3442
}
3543

3644
const exe = path.join(exeDir, "tsgo" + (process.platform === "win32" ? ".exe" : ""));

_packages/native-preview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"type": "module",
2828
"preferUnplugged": true,
2929
"engines": {
30-
"node": ">=20.6.0"
30+
"node": ">=16.20.0"
3131
},
3232
"bin": {
3333
"tsgo": "./bin/tsgo.js"

0 commit comments

Comments
 (0)