@dbx-tools/core 0.9.58 → 0.9.61
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/index.ts +3 -3
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -2
- package/lib/src/bin.d.ts +13 -4
- package/lib/src/bin.js +153 -44
- package/lib/src/exec.d.ts +9 -1
- package/lib/src/exec.js +9 -2
- package/package.json +2 -2
- package/src/bin.ts +169 -45
- package/src/exec.ts +18 -2
package/src/exec.ts
CHANGED
|
@@ -62,15 +62,25 @@ export type ExecStdio = "inherit" | "pipe" | "ignore";
|
|
|
62
62
|
/** Invoked once per output line when a fd is piped. */
|
|
63
63
|
export type LineHandler = (line: string) => void;
|
|
64
64
|
|
|
65
|
+
/** Stream lines to a handler with optional result capture. */
|
|
66
|
+
export interface LineOutputOptions {
|
|
67
|
+
/** Invoked once per output line. */
|
|
68
|
+
onLine: LineHandler;
|
|
69
|
+
/** Retain lines in the completed result. Defaults to `true`. */
|
|
70
|
+
capture?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
/**
|
|
66
74
|
* Stdio config for one fd.
|
|
67
75
|
*
|
|
68
76
|
* - `"inherit"` / `"pipe"` / `"ignore"` — pass through to `spawn`
|
|
69
77
|
* - `"capture"` — pipe the fd and append each line to the result
|
|
70
78
|
* - {@link LineHandler} — pipe and invoke the handler per line (lines are still captured)
|
|
79
|
+
* - {@link LineOutputOptions} — pipe and invoke the handler, with optional capture
|
|
71
80
|
* - `(LineHandler | "capture")[]` — pipe; `"capture"` is a no-op marker, handlers run per line
|
|
72
81
|
*/
|
|
73
|
-
export type StdioOption =
|
|
82
|
+
export type StdioOption =
|
|
83
|
+
ExecStdio | LineHandler | LineOutputOptions | "capture" | (LineHandler | "capture")[];
|
|
74
84
|
|
|
75
85
|
/** Outcome of {@link spawn} / {@link spawnSync}: exit code, captured output, and line views. */
|
|
76
86
|
export type ExecResult = {
|
|
@@ -341,9 +351,14 @@ function lineHandlers(option: StdioOption): LineHandler[] {
|
|
|
341
351
|
if (Array.isArray(option)) {
|
|
342
352
|
return option.filter((item): item is LineHandler => item !== "capture");
|
|
343
353
|
}
|
|
354
|
+
if (typeof option === "object") return [option.onLine];
|
|
344
355
|
return [];
|
|
345
356
|
}
|
|
346
357
|
|
|
358
|
+
function capturesLines(option: StdioOption): boolean {
|
|
359
|
+
return typeof option !== "object" || Array.isArray(option) || option.capture !== false;
|
|
360
|
+
}
|
|
361
|
+
|
|
347
362
|
/**
|
|
348
363
|
* True when a stdio option is a string spawn mode rather than capture/handlers.
|
|
349
364
|
*
|
|
@@ -382,10 +397,11 @@ function resolveStdio(
|
|
|
382
397
|
if (isPassthroughMode(option) && option !== "pipe") return { mode: option };
|
|
383
398
|
|
|
384
399
|
const handlers = lineHandlers(option);
|
|
400
|
+
const capture = capturesLines(option);
|
|
385
401
|
return {
|
|
386
402
|
mode: "pipe",
|
|
387
403
|
onLine: (line) => {
|
|
388
|
-
lines.push(line);
|
|
404
|
+
if (capture) lines.push(line);
|
|
389
405
|
for (const handler of handlers) handler(line);
|
|
390
406
|
},
|
|
391
407
|
};
|