feat(format): add check and fix workflows
This commit is contained in:
+36
-1
@@ -88,6 +88,41 @@ const parseRawArgv = (argv: string[]): TArgSource => {
|
||||
return parsedArgv;
|
||||
};
|
||||
|
||||
export const parseCliArgv = parseRawArgv;
|
||||
|
||||
export const getProcessUserArgv = (): string[] => {
|
||||
const rawArgv = process.argv;
|
||||
const argv0Base = (rawArgv[0] || "").split(/[\\/]/).pop()?.toLowerCase();
|
||||
const runtimeNames = new Set([
|
||||
"node",
|
||||
"node.exe",
|
||||
"nodejs",
|
||||
"nodejs.exe",
|
||||
"bun",
|
||||
"bun.exe",
|
||||
"deno",
|
||||
"deno.exe",
|
||||
"tsx",
|
||||
"tsx.exe",
|
||||
"ts-node",
|
||||
"ts-node.exe",
|
||||
]);
|
||||
|
||||
if (!runtimeNames.has(argv0Base || "")) {
|
||||
return rawArgv.slice();
|
||||
}
|
||||
|
||||
const firstUserArg = rawArgv[1] || "";
|
||||
const firstUserArgLooksLikeScript =
|
||||
firstUserArg.includes("/") ||
|
||||
firstUserArg.endsWith(".js") ||
|
||||
firstUserArg.endsWith(".ts") ||
|
||||
firstUserArg.endsWith(".mjs") ||
|
||||
firstUserArg.endsWith(".cjs");
|
||||
|
||||
return rawArgv.slice(firstUserArgLooksLikeScript ? 2 : 1);
|
||||
};
|
||||
|
||||
const normalizeOutputMode = (value: unknown): TCliOutputMode | undefined => {
|
||||
if (value === "human" || value === "plain" || value === "json") {
|
||||
return value;
|
||||
@@ -171,7 +206,7 @@ export const getCliMode = async (
|
||||
|
||||
export const getRawCliMode = async (): Promise<ICliMode> => {
|
||||
const cliConfig = await getCliModeConfig();
|
||||
const rawArgv = parseRawArgv(process.argv.slice(2));
|
||||
const rawArgv = parseRawArgv(getProcessUserArgv());
|
||||
return resolveCliMode(rawArgv, cliConfig);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user