Skip to content

Commit 26d8c53

Browse files
fix: not executing on Windows
This has something to do with the guard at the bottom that sees if it is being sourced or executed, but it has flaws. This patch should fix that. Fixes #11: CLI not executing on windows
1 parent 9308015 commit 26d8c53

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/cli.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import chalk from 'chalk';
99
import { hideBin } from 'yargs/helpers';
1010
import { loadPlugins } from '#lib/core/compiler/io';
1111
import path from 'path';
12+
import { pathToFileURL } from 'url';
1213
import pkg from '#package' with { type: 'json' };
1314
import yargs from 'yargs';
1415

@@ -289,12 +290,8 @@ export const cli = yargs(hideBin(process.argv))
289290
});
290291

291292
// If file is being executed instead of sourced:
292-
293-
// eslint-disable-next-line no-console
294-
console.log({ 'import.meta.url': import.meta.url, 'process.argv[1]': process.argv[1] });
295-
const fileIndex = 1;
296-
const startFile = process.argv[fileIndex];
297-
const isNotBeingImported = import.meta.url === `file://${startFile}`;
298-
const npx = startFile.endsWith(path.join('node_modules', '.bin', NAME));
293+
const startFile = pathToFileURL(process.argv[1]).href;
294+
const isNotBeingImported = import.meta.url === startFile;
295+
const npx = startFile.endsWith(`node_modules/.bin/${NAME}`);
299296
const isBeingExecuted = isNotBeingImported || npx;
300297
if (isBeingExecuted) await cli.parse();

0 commit comments

Comments
 (0)