fix: harden windows cli launch
This commit is contained in:
19
src/entry.ts
19
src/entry.ts
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
import { spawn } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import process from "node:process";
|
||||
|
||||
import { applyCliProfileEnv, parseCliProfileArgs } from "./cli/profile.js";
|
||||
@@ -56,6 +57,24 @@ function ensureExperimentalWarningSuppressed(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
function normalizeWindowsArgv(argv: string[]): string[] {
|
||||
if (process.platform !== "win32") return argv;
|
||||
if (argv.length < 3) return argv;
|
||||
const execBase = path.basename(process.execPath).toLowerCase();
|
||||
const arg1 = path.basename(argv[1] ?? "").toLowerCase();
|
||||
const arg2 = path.basename(argv[2] ?? "").toLowerCase();
|
||||
const looksLikeEntry = arg1 === "entry.ts" || arg1 === "entry.js";
|
||||
if (arg1 === execBase) {
|
||||
return [argv[0], ...argv.slice(2)];
|
||||
}
|
||||
if (looksLikeEntry && arg2 === execBase) {
|
||||
return [argv[0], argv[1], ...argv.slice(3)];
|
||||
}
|
||||
return argv;
|
||||
}
|
||||
|
||||
process.argv = normalizeWindowsArgv(process.argv);
|
||||
|
||||
if (!ensureExperimentalWarningSuppressed()) {
|
||||
const parsed = parseCliProfileArgs(process.argv);
|
||||
if (!parsed.ok) {
|
||||
|
||||
Reference in New Issue
Block a user