fix: running with npx

This commit is contained in:
2025-09-30 23:55:59 +03:00
parent d007e6ae76
commit 42f087eb5a

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
import { writeFile } from 'node:fs/promises'; import { writeFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { Octokit } from 'octokit'; import { Octokit } from 'octokit';
import yargs from 'yargs'; import yargs from 'yargs';
import { hideBin } from 'yargs/helpers'; import { hideBin } from 'yargs/helpers';
@@ -114,7 +115,12 @@ export async function main(): Promise<number> {
} }
// Only run if this is the main module (not imported for testing) // Only run if this is the main module (not imported for testing)
if (import.meta.url === `file://${process.argv[1]}`) { const modulePath = fileURLToPath(import.meta.url);
const isMainModule =
process.argv[1] &&
(modulePath === process.argv[1] || modulePath === fileURLToPath(`file://${process.argv[1]}`));
if (isMainModule) {
main().then((exitCode) => { main().then((exitCode) => {
process.exit(exitCode); process.exit(exitCode);
}); });