invoket 0.1.5 → 0.1.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/context.ts +22 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "invoket",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "TypeScript task runner for Bun - uses type annotations to parse CLI arguments",
6
6
  "bin": {
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
  }