(rawArgv: string[])
| 35 | } |
| 36 | |
| 37 | export function normalizeCliArgs(rawArgv: string[]): string[] { |
| 38 | if (!Array.isArray(rawArgv) || rawArgv.length === 0) { |
| 39 | return []; |
| 40 | } |
| 41 | |
| 42 | const execPath = process.execPath; |
| 43 | const execBase = basename(execPath); |
| 44 | const bunMain = globalThis.Bun?.main ?? ''; |
| 45 | const dashIndex = rawArgv.indexOf('--'); |
| 46 | let argv = rawArgv.slice(); |
| 47 | if (dashIndex >= 0) { |
| 48 | const preArgs = rawArgv.slice(0, dashIndex); |
| 49 | const postArgs = rawArgv.slice(dashIndex + 1); |
| 50 | argv = hasRuntimeWrapper(preArgs, execPath, execBase, bunMain) |
| 51 | ? postArgs |
| 52 | : [...preArgs, ...postArgs]; |
| 53 | } |
| 54 | |
| 55 | let startIndex = 0; |
| 56 | while (startIndex < argv.length) { |
| 57 | const value = argv[startIndex] || ''; |
| 58 | const nextValue = argv[startIndex + 1] || ''; |
| 59 | if ( |
| 60 | value === 'bun' && |
| 61 | (nextValue === bunMain || nextValue === execPath || nextValue === execBase || isEntrypointPath(nextValue, bunMain)) |
| 62 | ) { |
| 63 | startIndex += 2; |
| 64 | continue; |
| 65 | } |
| 66 | if (value === execPath || value === execBase || isEntrypointPath(value, bunMain)) { |
| 67 | startIndex += 1; |
| 68 | continue; |
| 69 | } |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | return argv.slice(startIndex); |
| 74 | } |
| 75 | |
| 76 | export function getCliArgs(): string[] { |
| 77 | return normalizeCliArgs(resolveRawArgv()); |
no test coverage detected