fix(smartcli): Improve CLI argument parsing, update deps and tests

This commit is contained in:
2025-10-28 06:27:29 +00:00
parent 44296dc57a
commit 6efd6232d1
8 changed files with 12248 additions and 3216 deletions

View File

@@ -1,5 +1,15 @@
# Changelog # Changelog
## 2025-10-27 - 4.0.13 - fix(smartcli)
Improve CLI argument parsing, update deps and tests
- Enhance startParse() to filter runtime executables and script paths (node, deno, bun, tsx, ts-node) so commands are detected correctly across runtimes.
- Switch path import to node:path in plugins for ESM compatibility.
- Bump various dependencies and devDependencies (including @push.rocks/lik, @push.rocks/smartlog, @push.rocks/smartpromise, @push.rocks/smartrx, yargs-parser, @git.zone tooling) and add packageManager field.
- Replace / reorganize tests: add/modify test/test.node+deno+bun.ts, adjust test script to use --verbose.
- Add deno.lock and include many resolved npm dependencies.
- Add LICENSE file (MIT).
## 2025-04-01 - 4.0.12 - fix(docs) ## 2025-04-01 - 4.0.12 - fix(docs)
Update documentation with comprehensive usage examples, improved command alias descriptions, and detailed configuration instructions Update documentation with comprehensive usage examples, improved command alias descriptions, and detailed configuration instructions

7233
deno.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "(tstest test/ --web)", "test": "(tstest test/ --verbose)",
"build": "(tsbuild --web --allowimplicitany)", "build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
@@ -36,19 +36,18 @@
}, },
"homepage": "https://code.foss.global/push.rocks/smartcli", "homepage": "https://code.foss.global/push.rocks/smartcli",
"dependencies": { "dependencies": {
"@push.rocks/lik": "^6.0.15", "@push.rocks/lik": "^6.2.2",
"@push.rocks/smartlog": "^3.0.6", "@push.rocks/smartlog": "^3.1.10",
"@push.rocks/smartobject": "^1.0.12", "@push.rocks/smartobject": "^1.0.12",
"@push.rocks/smartpromise": "^4.0.3", "@push.rocks/smartpromise": "^4.2.3",
"@push.rocks/smartrx": "^3.0.3", "@push.rocks/smartrx": "^3.0.10",
"yargs-parser": "21.1.1" "yargs-parser": "22.0.0"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.80", "@git.zone/tsbuild": "^2.6.8",
"@git.zone/tsrun": "^1.2.42", "@git.zone/tsrun": "^1.6.2",
"@git.zone/tstest": "^1.0.90", "@git.zone/tstest": "^2.7.0",
"@push.rocks/tapbundle": "^5.0.23", "@types/node": "^24.9.1"
"@types/node": "^20.12.12"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@@ -64,5 +63,6 @@
], ],
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
] ],
"packageManager": "pnpm@10.18.1+sha512.77a884a165cbba2d8d1c19e3b4880eee6d2fcabd0d879121e282196b80042351d5eb3ca0935fa599da1dc51265cc68816ad2bddd2a2de5ea9fdf92adbec7cd34"
} }

8179
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
import { tap, expect } from '@push.rocks/tapbundle'; import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as smartrx from '@push.rocks/smartrx'; import * as smartrx from '@push.rocks/smartrx';
import * as smartcli from '../ts/index.js'; import * as smartcli from '../ts/index.js';

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartcli', name: '@push.rocks/smartcli',
version: '4.0.12', version: '4.0.13',
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.'
} }

View File

@@ -123,11 +123,16 @@ export class Smartcli {
* start the process of evaluating commands * start the process of evaluating commands
*/ */
public startParse(): void { public startParse(): void {
const parsedYArgs = plugins.yargsParser(process.argv); const parsedYArgs = plugins.yargsParser([...process.argv]);
// lets handle commands // lets handle commands
// Filter out runtime executable and script path from arguments
// Node.js: ["/path/to/node", "/path/to/script.js", ...args]
// Deno: ["deno", "/path/to/script.ts", ...args]
// Bun: ["/path/to/bun", "/path/to/script.ts", ...args]
let counter = 0; let counter = 0;
let foundCommand = false; let foundCommand = false;
const runtimeNames = ['node', 'deno', 'bun', 'tsx', 'ts-node'];
parsedYArgs._ = parsedYArgs._.filter((commandPartArg) => { parsedYArgs._ = parsedYArgs._.filter((commandPartArg) => {
counter++; counter++;
if (typeof commandPartArg === 'number') { if (typeof commandPartArg === 'number') {
@@ -135,7 +140,10 @@ export class Smartcli {
} }
if (counter <= 2 && !foundCommand) { if (counter <= 2 && !foundCommand) {
const isPath = commandPartArg.startsWith('/'); const isPath = commandPartArg.startsWith('/');
foundCommand = !isPath; const isRuntimeExecutable = runtimeNames.some(name =>
commandPartArg === name || commandPartArg.endsWith(`/${name}`)
);
foundCommand = !isPath && !isRuntimeExecutable;
return foundCommand; return foundCommand;
} else { } else {
return true; return true;

View File

@@ -1,7 +1,7 @@
// @pushrocks scope // @pushrocks scope
import * as smartlog from '@push.rocks/smartlog'; import * as smartlog from '@push.rocks/smartlog';
import * as lik from '@push.rocks/lik'; import * as lik from '@push.rocks/lik';
import * as path from 'path'; import * as path from 'node:path';
import * as smartparam from '@push.rocks/smartobject'; import * as smartparam from '@push.rocks/smartobject';
import * as smartpromise from '@push.rocks/smartpromise'; import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/smartrx'; import * as smartrx from '@push.rocks/smartrx';