


















@@ -1,5 +1,3 @@
1-import fs from "node:fs";
2-import path from "node:path";
31import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
4253export function normalizeWindowsArgv(argv: string[]): string[] {
@@ -27,10 +25,11 @@ export function normalizeWindowsArgv(argv: string[]): string[] {
2725.trim();
2826const normalizeCandidate = (value: string): string =>
2927normalizeArg(value).replace(/^\\\\\\?\\/, "");
28+const basename = (value: string): string => value.split(/[\\/]/).pop() ?? value;
30293130const execPath = normalizeCandidate(process.execPath);
3231const execPathLower = normalizeLowercaseStringOrEmpty(execPath);
33-const execBase = normalizeLowercaseStringOrEmpty(path.basename(execPath));
32+const execBase = normalizeLowercaseStringOrEmpty(basename(execPath));
3433const isExecPath = (value: string | undefined): boolean => {
3534if (!value) {
3635return false;
@@ -40,34 +39,35 @@ export function normalizeWindowsArgv(argv: string[]): string[] {
4039return false;
4140}
4241const lower = normalizeLowercaseStringOrEmpty(normalized);
42+const base = basename(lower);
4343return (
4444lower === execPathLower ||
45-path.basename(lower) === execBase ||
45+base === execBase ||
4646lower.endsWith("\\node.exe") ||
4747lower.endsWith("/node.exe") ||
48-lower.includes("node.exe") ||
49-(path.basename(lower) === "node.exe" && fs.existsSync(normalized))
48+base === "node.exe"
5049);
5150};
525152+const argv0IsExecPath = isExecPath(argv[0]);
5353const next = [...argv];
54-for (let i = 1; i <= 3 && i < next.length; ) {
54+let removedLauncherPrefix = false;
55+for (let i = 1; i < next.length; ) {
5556if (isExecPath(next[i])) {
5657next.splice(i, 1);
58+removedLauncherPrefix = true;
5759continue;
5860}
59-i += 1;
61+break;
6062}
61-const filtered = next.filter((arg, index) => index === 0 || !isExecPath(arg));
62-if (filtered.length < 3) {
63-return filtered;
63+if (next.length < 3 || (!argv0IsExecPath && !removedLauncherPrefix)) {
64+return next;
6465}
65-const cleaned = [...filtered];
66+const cleaned = [...next];
6667for (let i = 2; i < cleaned.length; ) {
6768const arg = cleaned[i];
6869if (!arg || arg.startsWith("-")) {
69-i += 1;
70-continue;
70+break;
7171}
7272if (isExecPath(arg)) {
7373cleaned.splice(i, 1);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。