feat: 基于 process.argv 推断命令前缀,修复 bunx 误检测
This commit is contained in:
@@ -2,14 +2,24 @@ import type { RuneConfig } from "../types.ts";
|
||||
|
||||
export const DEFAULT_PREFIX = "bunx @lanyuanxiaoyao/rune";
|
||||
|
||||
export function inferFromEnvironment(
|
||||
execPath: string,
|
||||
userAgent: string | undefined,
|
||||
): string | null {
|
||||
if (execPath.includes("bun")) return "bunx @lanyuanxiaoyao/rune";
|
||||
export function inferFromProcess(argv: string[], userAgent: string | undefined): string | null {
|
||||
const scriptPath = argv[1]?.replace(/\\/g, "/") ?? "";
|
||||
|
||||
if (scriptPath.includes(".bun") && scriptPath.includes("cache")) {
|
||||
return "bunx @lanyuanxiaoyao/rune";
|
||||
}
|
||||
if (scriptPath.includes("_npx") || scriptPath.includes("npm-cache")) {
|
||||
return "npx @lanyuanxiaoyao/rune";
|
||||
}
|
||||
if (scriptPath.includes(".pnpm") || scriptPath.includes("pnpm-store")) {
|
||||
return "pnpx @lanyuanxiaoyao/rune";
|
||||
}
|
||||
|
||||
if (userAgent?.includes("bun")) return "bunx @lanyuanxiaoyao/rune";
|
||||
if (userAgent?.includes("pnpm")) return "pnpx @lanyuanxiaoyao/rune";
|
||||
if (userAgent?.includes("yarn")) return "yarn dlx @lanyuanxiaoyao/rune";
|
||||
if (userAgent?.includes("npm")) return "npx @lanyuanxiaoyao/rune";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -28,9 +38,7 @@ export async function checkCommandAvailable(command: string): Promise<boolean> {
|
||||
}
|
||||
|
||||
export async function detectCommandPrefix(): Promise<string | null> {
|
||||
if (await checkCommandAvailable("rune")) return "rune";
|
||||
|
||||
const inferred = inferFromEnvironment(process.execPath, process.env.npm_config_user_agent);
|
||||
const inferred = inferFromProcess(process.argv, process.env.npm_config_user_agent);
|
||||
if (inferred) return inferred;
|
||||
|
||||
for (const pm of ["bunx", "pnpx", "npx"]) {
|
||||
|
||||
Reference in New Issue
Block a user