From 1e97d108fd612be16370e28cdb02b92a08bb0ac3 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Wed, 3 Dec 2025 13:43:38 +0200 Subject: [PATCH 1/6] Enable getExePath to work on Node 16 --- _packages/native-preview/lib/getExePath.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/_packages/native-preview/lib/getExePath.js b/_packages/native-preview/lib/getExePath.js index 35faeeada3..cd7e48681b 100644 --- a/_packages/native-preview/lib/getExePath.js +++ b/_packages/native-preview/lib/getExePath.js @@ -21,16 +21,22 @@ export default function getExePath() { else { // We're actually running from an installed package. const platformPackageName = "@typescript/" + expectedPackage; - let packageJson; try { // v20.6.0, v18.19.0 - packageJson = import.meta.resolve(platformPackageName + "/package.json"); + const packageJson = import.meta.resolve(platformPackageName + "/package.json"); + const packageJsonPath = fileURLToPath(packageJson); + exeDir = path.join(path.dirname(packageJsonPath), "lib"); } catch (e) { - throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk."); + // Failed to resolve: this might be due to an older Node version that doesn't support import.meta.resolve. + if (e instanceof TypeError && e.message?.includes("resolve is not a function")) { + // v16.20.1 + exeDir = path.resolve(__dirname, "..", "node_modules", platformPackageName, "lib"); + } else { + throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk."); + } } - const packageJsonPath = fileURLToPath(packageJson); - exeDir = path.join(path.dirname(packageJsonPath), "lib"); + } const exe = path.join(exeDir, "tsgo" + (process.platform === "win32" ? ".exe" : "")); @@ -41,3 +47,4 @@ export default function getExePath() { return exe; } + From ff166783c50d02acfe30e891799b7b271583571e Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Wed, 3 Dec 2025 14:09:02 +0200 Subject: [PATCH 2/6] Check import.meta.resolve, use require.resolve as a fallback --- _packages/native-preview/lib/getExePath.js | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/_packages/native-preview/lib/getExePath.js b/_packages/native-preview/lib/getExePath.js index cd7e48681b..9bf11fb464 100644 --- a/_packages/native-preview/lib/getExePath.js +++ b/_packages/native-preview/lib/getExePath.js @@ -1,4 +1,5 @@ import fs from "node:fs"; +import module from "node:module"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -22,21 +23,21 @@ export default function getExePath() { // We're actually running from an installed package. const platformPackageName = "@typescript/" + expectedPackage; try { - // v20.6.0, v18.19.0 - const packageJson = import.meta.resolve(platformPackageName + "/package.json"); - const packageJsonPath = fileURLToPath(packageJson); - exeDir = path.join(path.dirname(packageJsonPath), "lib"); - } - catch (e) { - // Failed to resolve: this might be due to an older Node version that doesn't support import.meta.resolve. - if (e instanceof TypeError && e.message?.includes("resolve is not a function")) { + if (typeof import.meta.resolve === "undefined") { // v16.20.1 - exeDir = path.resolve(__dirname, "..", "node_modules", platformPackageName, "lib"); + const require = module.createRequire(import.meta.url); + const packageJson = require.resolve(platformPackageName + "/package.json"); + exeDir = path.join(path.dirname(packageJson), "lib"); } else { - throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk."); + // v20.6.0, v18.19.0 + const packageJson = import.meta.resolve(platformPackageName + "/package.json"); + const packageJsonPath = fileURLToPath(packageJson); + exeDir = path.join(path.dirname(packageJsonPath), "lib"); } + } catch (e) { + console.error(e); + throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk."); } - } const exe = path.join(exeDir, "tsgo" + (process.platform === "win32" ? ".exe" : "")); @@ -47,4 +48,3 @@ export default function getExePath() { return exe; } - From b6b815304cae178e9b3b1538ded700a9f26bde30 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Wed, 3 Dec 2025 14:10:16 +0200 Subject: [PATCH 3/6] Remove errant console.error --- _packages/native-preview/lib/getExePath.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_packages/native-preview/lib/getExePath.js b/_packages/native-preview/lib/getExePath.js index 9bf11fb464..234311692e 100644 --- a/_packages/native-preview/lib/getExePath.js +++ b/_packages/native-preview/lib/getExePath.js @@ -35,7 +35,6 @@ export default function getExePath() { exeDir = path.join(path.dirname(packageJsonPath), "lib"); } } catch (e) { - console.error(e); throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk."); } } @@ -48,3 +47,4 @@ export default function getExePath() { return exe; } + From 18a64ae252bc4a8b24886bddf4453d290a24b52d Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Thu, 4 Dec 2025 06:59:24 +0200 Subject: [PATCH 4/6] package.json engines field --- _packages/native-preview/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_packages/native-preview/package.json b/_packages/native-preview/package.json index f80dedced8..ee43459b50 100644 --- a/_packages/native-preview/package.json +++ b/_packages/native-preview/package.json @@ -27,7 +27,7 @@ "type": "module", "preferUnplugged": true, "engines": { - "node": ">=20.6.0" + "node": ">=16.20.0" }, "bin": { "tsgo": "./bin/tsgo.js" From 8e1e43b31e349ab7c219c84d58e2e45e79e0ab35 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Thu, 4 Dec 2025 07:00:37 +0200 Subject: [PATCH 5/6] fmt --- _packages/native-preview/lib/getExePath.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/_packages/native-preview/lib/getExePath.js b/_packages/native-preview/lib/getExePath.js index 234311692e..e799793d01 100644 --- a/_packages/native-preview/lib/getExePath.js +++ b/_packages/native-preview/lib/getExePath.js @@ -28,13 +28,15 @@ export default function getExePath() { const require = module.createRequire(import.meta.url); const packageJson = require.resolve(platformPackageName + "/package.json"); exeDir = path.join(path.dirname(packageJson), "lib"); - } else { + } + else { // v20.6.0, v18.19.0 const packageJson = import.meta.resolve(platformPackageName + "/package.json"); const packageJsonPath = fileURLToPath(packageJson); exeDir = path.join(path.dirname(packageJsonPath), "lib"); } - } catch (e) { + } + catch (e) { throw new Error("Unable to resolve " + platformPackageName + ". Either your platform is unsupported, or you are missing the package on disk."); } } @@ -48,3 +50,4 @@ export default function getExePath() { return exe; } + From 605447dfe7ebd7711a3748d567b8d2ac00e45ace Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Thu, 4 Dec 2025 07:01:49 +0200 Subject: [PATCH 6/6] Remove trailing newline --- _packages/native-preview/lib/getExePath.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/_packages/native-preview/lib/getExePath.js b/_packages/native-preview/lib/getExePath.js index e799793d01..9496321887 100644 --- a/_packages/native-preview/lib/getExePath.js +++ b/_packages/native-preview/lib/getExePath.js @@ -49,5 +49,3 @@ export default function getExePath() { return exe; } - -