Make get-version.ts ESM compatible

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2024-10-31 09:07:58 +00:00
parent cecea312c6
commit 63f3a834cc
No known key found for this signature in database
GPG Key ID: A2B008A5F49F5D0D

View File

@ -4,6 +4,8 @@
* Checks for the presence of a webapp, inspects its version and prints it * Checks for the presence of a webapp, inspects its version and prints it
*/ */
import url from "node:url";
import { versionFromAsar } from "./set-version.js"; import { versionFromAsar } from "./set-version.js";
async function main(): Promise<number> { async function main(): Promise<number> {
@ -13,13 +15,16 @@ async function main(): Promise<number> {
return 0; return 0;
} }
if (require.main === module) { if (import.meta.url.startsWith("file:")) {
main() const modulePath = url.fileURLToPath(import.meta.url);
.then((ret) => { if (process.argv[1] === modulePath) {
process.exit(ret); main()
}) .then((ret) => {
.catch((e) => { process.exit(ret);
console.error(e); })
process.exit(1); .catch((e) => {
}); console.error(e);
process.exit(1);
});
}
} }