fix: normalize windows argv in cli
This commit is contained in:
@@ -51,15 +51,25 @@ export async function runCli(argv: string[] = process.argv) {
|
|||||||
|
|
||||||
function stripWindowsNodeExec(argv: string[]): string[] {
|
function stripWindowsNodeExec(argv: string[]): string[] {
|
||||||
if (process.platform !== "win32") return argv;
|
if (process.platform !== "win32") return argv;
|
||||||
const execPath = process.execPath;
|
const normalizeArg = (value: string): string => value.replace(/^"+|"+$/g, "");
|
||||||
|
const execPath = normalizeArg(process.execPath);
|
||||||
const execPathLower = execPath.toLowerCase();
|
const execPathLower = execPath.toLowerCase();
|
||||||
const execBase = path.basename(execPath).toLowerCase();
|
const execBase = path.basename(execPath).toLowerCase();
|
||||||
return argv.filter((arg, index) => {
|
const isExecPath = (value: string | undefined): boolean => {
|
||||||
if (index === 0) return true;
|
if (!value) return false;
|
||||||
if (!arg) return true;
|
const lower = normalizeArg(value).toLowerCase();
|
||||||
const lower = arg.toLowerCase();
|
return lower === execPathLower || path.basename(lower) === execBase;
|
||||||
return lower !== execPathLower && path.basename(lower) !== execBase;
|
};
|
||||||
});
|
const filtered = argv.filter((arg, index) => index === 0 || !isExecPath(arg));
|
||||||
|
if (filtered.length < 3) return filtered;
|
||||||
|
const cleaned = [...filtered];
|
||||||
|
if (isExecPath(cleaned[1])) {
|
||||||
|
cleaned.splice(1, 1);
|
||||||
|
}
|
||||||
|
if (isExecPath(cleaned[2])) {
|
||||||
|
cleaned.splice(2, 1);
|
||||||
|
}
|
||||||
|
return cleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isCliMainModule(): boolean {
|
export function isCliMainModule(): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user