From 63f3a834cc207e365e0143669d44031438721476 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 31 Oct 2024 09:07:58 +0000 Subject: [PATCH] Make get-version.ts ESM compatible Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- scripts/get-version.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/get-version.ts b/scripts/get-version.ts index 560e821..74cee84 100755 --- a/scripts/get-version.ts +++ b/scripts/get-version.ts @@ -4,6 +4,8 @@ * Checks for the presence of a webapp, inspects its version and prints it */ +import url from "node:url"; + import { versionFromAsar } from "./set-version.js"; async function main(): Promise { @@ -13,13 +15,16 @@ async function main(): Promise { return 0; } -if (require.main === module) { - main() - .then((ret) => { - process.exit(ret); - }) - .catch((e) => { - console.error(e); - process.exit(1); - }); +if (import.meta.url.startsWith("file:")) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + main() + .then((ret) => { + process.exit(ret); + }) + .catch((e) => { + console.error(e); + process.exit(1); + }); + } }