invoket 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli.ts +10 -2
- package/src/context.ts +22 -8
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -179,13 +179,15 @@ function parseParams(
|
|
|
179
179
|
return params;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
// Updated regex to handle union types with null (e.g., string | null)
|
|
182
183
|
const paramPattern =
|
|
183
|
-
/(\w+)\s*:\s*(\w+\[\]|Record<[^>]+>|\{[^}]*\}|string|number|boolean|\w+)(?:\s*=\s*[^,)]+)?/g;
|
|
184
|
+
/(\w+)\s*:\s*(\w+\[\]|Record<[^>]+>|\{[^}]*\}|string|number|boolean|\w+)(?:\s*\|\s*null)?(?:\s*=\s*[^,)]+)?/g;
|
|
184
185
|
let paramMatch;
|
|
185
186
|
|
|
186
187
|
while ((paramMatch = paramPattern.exec(paramsStr)) !== null) {
|
|
187
188
|
const [fullMatch, name, rawType] = paramMatch;
|
|
188
189
|
const hasDefault = fullMatch.includes("=");
|
|
190
|
+
const isNullable = fullMatch.includes("| null");
|
|
189
191
|
|
|
190
192
|
let type: ParamType;
|
|
191
193
|
if (rawType === "string") {
|
|
@@ -208,7 +210,13 @@ function parseParams(
|
|
|
208
210
|
aliases: annotation?.aliases,
|
|
209
211
|
};
|
|
210
212
|
|
|
211
|
-
params.push({
|
|
213
|
+
params.push({
|
|
214
|
+
name,
|
|
215
|
+
type,
|
|
216
|
+
required: !hasDefault && !isNullable,
|
|
217
|
+
isRest: false,
|
|
218
|
+
flag,
|
|
219
|
+
});
|
|
212
220
|
}
|
|
213
221
|
|
|
214
222
|
return params;
|
package/src/context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $, spawn } from "bun";
|
|
2
2
|
import { resolve } from "path";
|
|
3
3
|
|
|
4
4
|
export interface RunResult {
|
|
@@ -13,6 +13,7 @@ export interface RunOptions {
|
|
|
13
13
|
echo?: boolean;
|
|
14
14
|
warn?: boolean;
|
|
15
15
|
hide?: boolean;
|
|
16
|
+
stream?: boolean;
|
|
16
17
|
cwd?: string;
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -43,14 +44,26 @@ export class Context {
|
|
|
43
44
|
console.log(`$ ${command}`);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.
|
|
49
|
-
|
|
47
|
+
let result;
|
|
48
|
+
if (opts.stream) {
|
|
49
|
+
// Stream output in real-time using Bun.spawn with inherited stdio
|
|
50
|
+
const proc = spawn(["sh", "-c", command], {
|
|
51
|
+
cwd: opts.cwd ?? this.cwd,
|
|
52
|
+
stdout: "inherit",
|
|
53
|
+
stderr: "inherit",
|
|
54
|
+
});
|
|
55
|
+
const exitCode = await proc.exited;
|
|
56
|
+
result = { exitCode, stdout: Buffer.from(""), stderr: Buffer.from("") };
|
|
57
|
+
} else {
|
|
58
|
+
result = await $`sh -c ${command}`
|
|
59
|
+
.cwd(opts.cwd ?? this.cwd)
|
|
60
|
+
.nothrow()
|
|
61
|
+
.quiet();
|
|
62
|
+
}
|
|
50
63
|
|
|
51
64
|
const runResult: RunResult = {
|
|
52
|
-
stdout: result.stdout.toString(),
|
|
53
|
-
stderr: result.stderr.toString(),
|
|
65
|
+
stdout: opts.stream ? "" : result.stdout.toString(),
|
|
66
|
+
stderr: opts.stream ? "" : result.stderr.toString(),
|
|
54
67
|
code: result.exitCode,
|
|
55
68
|
ok: result.exitCode === 0,
|
|
56
69
|
failed: result.exitCode !== 0,
|
|
@@ -64,7 +77,8 @@ export class Context {
|
|
|
64
77
|
throw error;
|
|
65
78
|
}
|
|
66
79
|
|
|
67
|
-
|
|
80
|
+
// When streaming, output already went to terminal; otherwise write captured output
|
|
81
|
+
if (!opts.stream && !opts.hide) {
|
|
68
82
|
if (runResult.stdout) process.stdout.write(runResult.stdout);
|
|
69
83
|
if (runResult.stderr) process.stderr.write(runResult.stderr);
|
|
70
84
|
}
|