fix(smartcli): Allow passing argv to startParse and improve getUserArgs Deno/runtime handling; update tests and add license
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-10-28 - 4.0.18 - fix(smartcli)
|
||||||
|
Allow passing argv to startParse and improve getUserArgs Deno/runtime handling; update tests and add license
|
||||||
|
|
||||||
|
- Smartcli.startParse now accepts an optional testArgv parameter to bypass automatic runtime detection (makes testing deterministic).
|
||||||
|
- getUserArgs logic refined: always prefer Deno.args when available (handles Deno run and compiled executables reliably) and improve execPath fallback and slicing behavior for Node/Bun/other launchers.
|
||||||
|
- Tests updated: test/test.node+deno+bun.ts now passes process.argv explicitly to startParse to avoid Deno.args interference in test environments.
|
||||||
|
- Added MIT LICENSE file and a local .claude/settings.local.json for environment/permission settings.
|
||||||
|
|
||||||
## 2025-10-28 - 4.0.17 - fix(license)
|
## 2025-10-28 - 4.0.17 - fix(license)
|
||||||
Add MIT license and local Claude settings
|
Add MIT license and local Claude settings
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ tap.test('should add an command', async (toolsArg) => {
|
|||||||
console.log(process.argv);
|
console.log(process.argv);
|
||||||
process.argv.splice(2, 0, 'awesome');
|
process.argv.splice(2, 0, 'awesome');
|
||||||
console.log(process.argv);
|
console.log(process.argv);
|
||||||
smartCliTestObject.startParse();
|
// Pass process.argv explicitly for testing (bypasses Deno.args in Deno environments)
|
||||||
|
smartCliTestObject.startParse(process.argv);
|
||||||
await done.promise;
|
await done.promise;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartcli',
|
name: '@push.rocks/smartcli',
|
||||||
version: '4.0.17',
|
version: '4.0.18',
|
||||||
description: 'A library that simplifies building reactive command-line applications using observables, with robust support for commands, arguments, options, aliases, and asynchronous operation management.'
|
description: 'A library that simplifies building reactive command-line applications using observables, with robust support for commands, arguments, options, aliases, and asynchronous operation management.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,10 +123,11 @@ export class Smartcli {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* start the process of evaluating commands
|
* start the process of evaluating commands
|
||||||
|
* @param testArgv - Optional argv override for testing (bypasses automatic runtime detection)
|
||||||
*/
|
*/
|
||||||
public startParse(): void {
|
public startParse(testArgv?: string[]): void {
|
||||||
// Get user arguments, properly handling Node.js, Deno (run/compiled), and Bun
|
// Get user arguments, properly handling Node.js, Deno (run/compiled), and Bun
|
||||||
const userArgs = getUserArgs();
|
const userArgs = testArgv ? getUserArgs(testArgv) : getUserArgs();
|
||||||
const parsedYArgs = plugins.yargsParser(userArgs);
|
const parsedYArgs = plugins.yargsParser(userArgs);
|
||||||
const wantedCommand = parsedYArgs._[0];
|
const wantedCommand = parsedYArgs._[0];
|
||||||
|
|
||||||
|
|||||||
@@ -13,19 +13,15 @@ export function getUserArgs(argv?: string[]): string[] {
|
|||||||
|
|
||||||
// Prefer Deno.args when available and no custom argv provided;
|
// Prefer Deno.args when available and no custom argv provided;
|
||||||
// it's the most reliable for Deno run and compiled.
|
// it's the most reliable for Deno run and compiled.
|
||||||
|
// Deno.args is ALWAYS correct in Deno environments - it handles the internal bundle path automatically.
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
const g: any = typeof globalThis !== 'undefined' ? globalThis : {};
|
const g: any = typeof globalThis !== 'undefined' ? globalThis : {};
|
||||||
|
|
||||||
// Check if we should use Deno.args
|
if (!useProvidedArgv && g.Deno && g.Deno.args && Array.isArray(g.Deno.args)) {
|
||||||
// Skip Deno.args if process.argv has been manipulated (test scenario detection)
|
|
||||||
const processArgv = typeof process !== 'undefined' && Array.isArray(process.argv) ? process.argv : [];
|
|
||||||
const argvLooksManipulated = processArgv.length > 2 && g.Deno && g.Deno.args;
|
|
||||||
|
|
||||||
if (!useProvidedArgv && g.Deno && g.Deno.args && Array.isArray(g.Deno.args) && !argvLooksManipulated) {
|
|
||||||
return g.Deno.args.slice();
|
return g.Deno.args.slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
const a = argv ?? processArgv;
|
const a = argv ?? (typeof process !== 'undefined' && Array.isArray(process.argv) ? process.argv : []);
|
||||||
|
|
||||||
if (!Array.isArray(a) || a.length === 0) return [];
|
if (!Array.isArray(a) || a.length === 0) return [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user