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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "invoket",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "description": "TypeScript task runner for Bun - uses type annotations to parse CLI arguments",
6
6
  "bin": {
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({ name, type, required: !hasDefault, isRest: false, flag });
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 { $ } from "bun";
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
- const result = await $`sh -c ${command}`
47
- .cwd(opts.cwd ?? this.cwd)
48
- .nothrow()
49
- .quiet();
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
- if (!opts.hide) {
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
  }