1.4 KiB
1.4 KiB
Cross-Runtime Compatibility
CLI Argument Parsing
The module uses a robust cross-runtime approach for parsing command-line arguments:
Key Implementation:
getUserArgs()utility (ints/smartcli.helpers.ts) handles process.argv differences across Node.js, Deno, and Bun- Uses
process.execPathbasename detection instead of content-based heuristics - Prefers
Deno.argswhen available (for Deno run/compiled), unless argv is explicitly provided
Runtime Differences:
- Node.js:
process.argv = ["/path/to/node", "/path/to/script.js", ...userArgs] - Deno (run):
process.argv = ["deno", "/path/to/script.ts", ...userArgs](butDeno.argsis preferred) - Deno (compiled):
process.argv = ["/path/to/executable", ...userArgs](custom executable name) - Bun:
process.argv = ["/path/to/bun", "/path/to/script.ts", ...userArgs]
How it works:
- If
Deno.argsexists and no custom argv provided, use it directly - Otherwise, detect runtime by checking
process.execPathbasename - If basename is a known launcher (node, deno, bun, tsx, ts-node), skip 2 args
- If basename is unknown (compiled executable), skip only 1 arg
- Safety check: if offset would skip everything, don't skip anything (handles test edge cases)
This approach works correctly with:
- Standard runtime execution
- Compiled executables (Deno compile, Node pkg, etc.)
- Custom-named executables
- Test environments with unusual argv setups