procband 0.3.0 → 0.3.1

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 CHANGED
@@ -29,9 +29,6 @@ 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
-
35
32
  ## Documentation Map
36
33
 
37
34
  - Concepts and lifecycle: [docs/context.md](docs/context.md)
package/dist/index.d.mts CHANGED
@@ -75,6 +75,15 @@ interface ProcessConfig {
75
75
  * pipe bytes into the child automatically.
76
76
  */
77
77
  stdin?: boolean | Readable;
78
+ /**
79
+ * Signal to send when the parent process is shutting down.
80
+ *
81
+ * When provided, `procband` uses this signal for parent-driven cleanup on
82
+ * `SIGINT`, `SIGTERM`, and `exit` instead of mirroring the parent signal or
83
+ * relying on the platform default. This only affects parent-driven cleanup;
84
+ * `proc.stop()` and `proc.kill()` still use their own explicit signals.
85
+ */
86
+ parentExitSignal?: KillSignal;
78
87
  /**
79
88
  * Automatic restart behavior for terminal child exits.
80
89
  *
package/dist/index.mjs CHANGED
@@ -494,13 +494,13 @@ var ProcbandProcessImpl = class extends EventEmitter {
494
494
  this.restartDisabled = true;
495
495
  this.restart.cancelDelay();
496
496
  const child = this.currentChild;
497
- if (child) killTreeBestEffort(child);
497
+ if (child) killTreeBestEffort(child, this.getParentCleanupSignal());
498
498
  }
499
499
  async cleanupFromSignal(signal) {
500
500
  this.shutdownRequested = true;
501
501
  this.restartDisabled = true;
502
502
  this.restart.cancelDelay();
503
- await this.stopActiveTree(signal, 1e3);
503
+ await this.stopActiveTree(this.getParentCleanupSignal(signal), 1e3);
504
504
  }
505
505
  async stopActiveTree(signal, killAfterMs) {
506
506
  const attempt = this.attempt;
@@ -510,6 +510,9 @@ var ProcbandProcessImpl = class extends EventEmitter {
510
510
  }
511
511
  await stopChildTree(attempt.child, attempt.close, () => attempt.closed, signal, killAfterMs);
512
512
  }
513
+ getParentCleanupSignal(fallback) {
514
+ return this.config.parentExitSignal ?? fallback;
515
+ }
513
516
  spawnAttempt() {
514
517
  this.generation += 1;
515
518
  const child = spawn(this.config.command, this.config.args ?? [], {
package/docs/context.md CHANGED
@@ -7,7 +7,7 @@ The returned `ProcbandProcess` is both:
7
7
  - a `ChildProcess`-compatible handle for the current active child attempt
8
8
  - a thenable wrapper that resolves to a `ProcessResult` when supervision is done
9
9
 
10
- Supervision adds four behaviors on top of raw `spawn()`:
10
+ Supervision adds five behaviors on top of raw `spawn()`:
11
11
 
12
12
  - prefixed `stdout` and `stderr`
13
13
  - line-based matching for future output
@@ -36,7 +36,8 @@ Supervision adds four behaviors on top of raw `spawn()`:
36
36
 
37
37
  - `ProcessConfig`
38
38
  Declares one supervised subprocess plus its label, color, restart policy,
39
- optional stdin behavior, and optional raw `stderr` tee.
39
+ optional stdin behavior, optional parent-exit signal override, and optional
40
+ raw `stderr` tee.
40
41
  - `ProcbandProcess`
41
42
  The live wrapper returned by `supervise()`. It is a `ChildProcess`-compatible
42
43
  handle, a matching surface, a shutdown surface, and a thenable final result.
@@ -89,6 +90,26 @@ Supervision adds four behaviors on top of raw `spawn()`:
89
90
  `restart: true`
90
91
  - Use explicit retry rules:
91
92
  `restart: { when, delayMs, maxFailures, windowMs }`
93
+ - Force a specific signal during parent shutdown:
94
+ `parentExitSignal: 'SIGHUP'`
95
+
96
+ # Recommended Patterns
97
+
98
+ - Use `proc.stop()` for deliberate shutdown initiated by your own script.
99
+ - Reserve `parentExitSignal` for children that expect a specific signal from
100
+ their supervisor during parent-driven cleanup.
101
+ - Await `proc` or call `proc.wait()` when your script intends to own failure
102
+ handling instead of inheriting procband's default parent-exit propagation.
103
+
104
+ # Patterns to Avoid
105
+
106
+ - Do not treat `parentExitSignal` as a replacement for `StopOptions.signal`.
107
+ The former only changes parent-driven cleanup; the latter controls
108
+ explicit `proc.stop()` calls.
109
+ - Do not rely on `kill()` for full shutdown when descendants may still be
110
+ running. `kill()` only targets the current direct child.
111
+ - Do not expect historical log replay from `match()` or `waitFor()`. Matching
112
+ is future-only by design.
92
113
 
93
114
  # Invariants and Constraints
94
115
 
@@ -113,7 +134,9 @@ Supervision adds four behaviors on top of raw `spawn()`:
113
134
  - `kill()` only signals the current direct child. `stop()` disables restart and
114
135
  kills the full process tree.
115
136
  - Parent cleanup installs both `SIGINT` and `SIGTERM` handlers while any live
116
- supervised process exists.
137
+ supervised process exists. Set `ProcessConfig.parentExitSignal` to override
138
+ which signal is sent to the child tree during parent-driven cleanup. This
139
+ does not change the signal used by explicit `proc.stop()` calls.
117
140
  - `stderr` prefixes always use the reserved red, even when a custom process
118
141
  color is configured.
119
142
  - `ProcessConfig.name` is optional. When omitted, it falls back to the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "procband",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Supervise subprocesses from TypeScript: prefix logs, wait for output patterns, and manage lifecycle/restarts.",
5
5
  "license": "MIT",
6
6
  "author": "Alec Larson",