procband 0.2.1 → 0.2.2
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/README.md +3 -0
- package/dist/index.d.mts +9 -1
- package/dist/index.mjs +15 -2
- package/docs/context.md +14 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,9 @@ const result = await proc
|
|
|
29
29
|
console.log(result)
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
`stdin` is disabled by default. Set `stdin: true` to write to `proc.stdin`, or
|
|
33
|
+
pass a readable stream to `stdin` to pipe input automatically.
|
|
34
|
+
|
|
32
35
|
## Documentation Map
|
|
33
36
|
|
|
34
37
|
- Concepts and lifecycle: [docs/context.md](docs/context.md)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChildProcess } from "node:child_process";
|
|
2
|
-
import { Writable } from "node:stream";
|
|
2
|
+
import { Readable, Writable } from "node:stream";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
/**
|
|
@@ -67,6 +67,14 @@ interface ProcessConfig {
|
|
|
67
67
|
* `process.stderr`.
|
|
68
68
|
*/
|
|
69
69
|
stderr?: Writable;
|
|
70
|
+
/**
|
|
71
|
+
* Child stdin behavior.
|
|
72
|
+
*
|
|
73
|
+
* Defaults to `false`, which connects the child stdin to the null device.
|
|
74
|
+
* Use `true` to expose a writable `proc.stdin`, or pass a readable stream to
|
|
75
|
+
* pipe bytes into the child automatically.
|
|
76
|
+
*/
|
|
77
|
+
stdin?: boolean | Readable;
|
|
70
78
|
/**
|
|
71
79
|
* Automatic restart behavior for terminal child exits.
|
|
72
80
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -516,7 +516,7 @@ var ProcbandProcessImpl = class extends EventEmitter {
|
|
|
516
516
|
cwd: this.config.cwd,
|
|
517
517
|
env: this.config.env,
|
|
518
518
|
stdio: [
|
|
519
|
-
"pipe",
|
|
519
|
+
this.config.stdin ? "pipe" : "ignore",
|
|
520
520
|
"pipe",
|
|
521
521
|
"pipe"
|
|
522
522
|
]
|
|
@@ -537,13 +537,15 @@ var ProcbandProcessImpl = class extends EventEmitter {
|
|
|
537
537
|
text: "",
|
|
538
538
|
flushed: false
|
|
539
539
|
},
|
|
540
|
-
closed: false
|
|
540
|
+
closed: false,
|
|
541
|
+
stdinCleanup: null
|
|
541
542
|
};
|
|
542
543
|
this.attempt = attempt;
|
|
543
544
|
this.attachAttempt(attempt);
|
|
544
545
|
}
|
|
545
546
|
attachAttempt(attempt) {
|
|
546
547
|
const { child } = attempt;
|
|
548
|
+
attempt.stdinCleanup = this.bindAttemptStdin(attempt);
|
|
547
549
|
child.on("spawn", () => {
|
|
548
550
|
if (this.attempt === attempt) this.emit("spawn");
|
|
549
551
|
});
|
|
@@ -556,6 +558,8 @@ var ProcbandProcessImpl = class extends EventEmitter {
|
|
|
556
558
|
child.on("close", (code, signal) => {
|
|
557
559
|
if (this.attempt !== attempt) return;
|
|
558
560
|
attempt.closed = true;
|
|
561
|
+
attempt.stdinCleanup?.();
|
|
562
|
+
attempt.stdinCleanup = null;
|
|
559
563
|
this.flushLineBuffer(attempt, "stdout");
|
|
560
564
|
this.flushLineBuffer(attempt, "stderr");
|
|
561
565
|
attempt.settleClose({
|
|
@@ -682,6 +686,15 @@ var ProcbandProcessImpl = class extends EventEmitter {
|
|
|
682
686
|
buffer.text = "";
|
|
683
687
|
this.handleLine(stream, line, false);
|
|
684
688
|
}
|
|
689
|
+
bindAttemptStdin(attempt) {
|
|
690
|
+
const source = this.config.stdin;
|
|
691
|
+
const destination = attempt.child.stdin;
|
|
692
|
+
if (!destination || typeof source !== "object") return null;
|
|
693
|
+
source.pipe(destination);
|
|
694
|
+
return () => {
|
|
695
|
+
source.unpipe(destination);
|
|
696
|
+
};
|
|
697
|
+
}
|
|
685
698
|
};
|
|
686
699
|
const liveProcesses = /* @__PURE__ */ new Set();
|
|
687
700
|
let propagatedFailure = false;
|
package/docs/context.md
CHANGED
|
@@ -35,8 +35,8 @@ Supervision adds four behaviors on top of raw `spawn()`:
|
|
|
35
35
|
# Core Abstractions
|
|
36
36
|
|
|
37
37
|
- `ProcessConfig`
|
|
38
|
-
Declares one supervised subprocess plus its label, color, restart policy,
|
|
39
|
-
optional raw `stderr` tee.
|
|
38
|
+
Declares one supervised subprocess plus its label, color, restart policy,
|
|
39
|
+
optional stdin behavior, and optional raw `stderr` tee.
|
|
40
40
|
- `ProcbandProcess`
|
|
41
41
|
The live wrapper returned by `supervise()`. It is a `ChildProcess`-compatible
|
|
42
42
|
handle, a matching surface, a shutdown surface, and a thenable final result.
|
|
@@ -52,14 +52,17 @@ Supervision adds four behaviors on top of raw `spawn()`:
|
|
|
52
52
|
3. Each line is prefixed and written to the parent `process.stdout` or
|
|
53
53
|
`process.stderr`.
|
|
54
54
|
4. `stderr` can also be tee'd as raw bytes to `ProcessConfig.stderr`.
|
|
55
|
-
5.
|
|
55
|
+
5. `stdin` is disconnected by default. Set `ProcessConfig.stdin` to `true` for
|
|
56
|
+
a writable child stdin, or pass a readable stream to pipe input into the
|
|
57
|
+
child automatically.
|
|
58
|
+
6. Future matching lines are delivered through `match()` callbacks or
|
|
56
59
|
`waitFor()`.
|
|
57
|
-
|
|
60
|
+
7. When a child exits, `procband` either finalizes or starts a new attempt,
|
|
58
61
|
depending on the restart policy.
|
|
59
|
-
|
|
62
|
+
8. A terminal failed exit that nobody observed through `await proc` or
|
|
60
63
|
`proc.wait()` sets `process.exitCode` and begins
|
|
61
64
|
stopping any other live `procband` processes in the same parent script.
|
|
62
|
-
|
|
65
|
+
9. `await proc` or `await proc.wait()` resolves only after the process is
|
|
63
66
|
terminal and no further restart will happen.
|
|
64
67
|
|
|
65
68
|
# Common Tasks -> Recommended APIs
|
|
@@ -78,6 +81,10 @@ Supervision adds four behaviors on top of raw `spawn()`:
|
|
|
78
81
|
Do not call `wait()` or await the thenable result
|
|
79
82
|
- Capture raw child `stderr` in a file or custom stream:
|
|
80
83
|
`ProcessConfig.stderr`
|
|
84
|
+
- Write to child stdin manually:
|
|
85
|
+
`stdin: true`, then `proc.stdin?.write(...)`
|
|
86
|
+
- Pipe a custom input stream into the child:
|
|
87
|
+
`stdin: readable`
|
|
81
88
|
- Retry failed exits with sane defaults:
|
|
82
89
|
`restart: true`
|
|
83
90
|
- Use explicit retry rules:
|
|
@@ -102,7 +109,7 @@ Supervision adds four behaviors on top of raw `spawn()`:
|
|
|
102
109
|
processes in the same parent script.
|
|
103
110
|
- The wrapper survives restarts, but inherited `pid`, `stdin`, `stdout`,
|
|
104
111
|
`stderr`, and related `ChildProcess` fields always refer to the current active
|
|
105
|
-
child attempt.
|
|
112
|
+
child attempt. `stdin` is `null` unless `ProcessConfig.stdin` is enabled.
|
|
106
113
|
- `kill()` only signals the current direct child. `stop()` disables restart and
|
|
107
114
|
kills the full process tree.
|
|
108
115
|
- Parent cleanup installs both `SIGINT` and `SIGTERM` handlers while any live
|
package/package.json
CHANGED