procband 0.2.0 → 0.2.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
@@ -20,7 +20,6 @@ import process from 'node:process'
20
20
  import { supervise } from 'procband'
21
21
 
22
22
  const proc = supervise({
23
- name: 'api',
24
23
  command: process.execPath,
25
24
  args: ['-e', 'console.log("ready")'],
26
25
  })
package/dist/index.d.mts CHANGED
@@ -27,8 +27,10 @@ type MatchStream = 'stdout' | 'stderr' | 'both';
27
27
  interface ProcessConfig {
28
28
  /**
29
29
  * Stable identifier used in prefixed output and emitted match events.
30
+ *
31
+ * Defaults to the trailing `/[-\w]+$/` match from `command`.
30
32
  */
31
- name: string;
33
+ name?: string;
32
34
  /**
33
35
  * Executable or shell-free command name passed to `spawn()`.
34
36
  */
@@ -271,8 +273,8 @@ interface ProcbandProcess extends ChildProcess, PromiseLike<ProcessResult> {
271
273
  *
272
274
  * @param config The subprocess configuration to supervise.
273
275
  * @returns A `ChildProcess`-compatible wrapper with procband-specific helpers.
274
- * @throws When `config` is invalid, such as a missing `name`, missing
275
- * `command`, or an invalid reserved color.
276
+ * @throws When `config` is invalid, such as a missing `command`, a `command`
277
+ * that does not produce a fallback `name`, or an invalid reserved color.
276
278
  * @example
277
279
  * ```ts
278
280
  * import process from 'node:process'
package/dist/index.mjs CHANGED
@@ -352,8 +352,8 @@ function isMissingProcessError(error) {
352
352
  *
353
353
  * @param config The subprocess configuration to supervise.
354
354
  * @returns A `ChildProcess`-compatible wrapper with procband-specific helpers.
355
- * @throws When `config` is invalid, such as a missing `name`, missing
356
- * `command`, or an invalid reserved color.
355
+ * @throws When `config` is invalid, such as a missing `command`, a `command`
356
+ * that does not produce a fallback `name`, or an invalid reserved color.
357
357
  * @example
358
358
  * ```ts
359
359
  * import process from 'node:process'
@@ -395,10 +395,10 @@ var ProcbandProcessImpl = class extends EventEmitter {
395
395
  terminalResultObserved = false;
396
396
  constructor(config) {
397
397
  super();
398
- validateProcessConfig(config);
398
+ const name = validateProcessConfig(config);
399
399
  this.config = config;
400
- this.name = config.name;
401
- this.label = config.label ?? config.name;
400
+ this.name = name;
401
+ this.label = config.label ?? name;
402
402
  this.color = resolveProcessColor(config.color);
403
403
  this.matches = new MatchRegistry(this.name);
404
404
  this.restart = new RestartController(config.restart);
@@ -686,9 +686,14 @@ var ProcbandProcessImpl = class extends EventEmitter {
686
686
  const liveProcesses = /* @__PURE__ */ new Set();
687
687
  let propagatedFailure = false;
688
688
  function validateProcessConfig(config) {
689
- if (!config.name) throw new Error("ProcessConfig.name is required");
690
689
  if (!config.command) throw new Error("ProcessConfig.command is required");
691
690
  validateProcessColor(config.color);
691
+ const name = config.name || inferProcessName(config.command);
692
+ if (!name) throw new Error("ProcessConfig.name is required when command does not match /[-\\w]+$/");
693
+ return name;
694
+ }
695
+ function inferProcessName(command) {
696
+ return command.match(/[-\w]+$/)?.[0];
692
697
  }
693
698
  function getResultExitCode(code, signal) {
694
699
  if (code != null) return code;
package/docs/context.md CHANGED
@@ -109,11 +109,14 @@ Supervision adds four behaviors on top of raw `spawn()`:
109
109
  supervised process exists.
110
110
  - `stderr` prefixes always use the reserved red, even when a custom process
111
111
  color is configured.
112
+ - `ProcessConfig.name` is optional. When omitted, it falls back to the
113
+ trailing `/[-\w]+$/` match from `command`.
112
114
 
113
115
  # Error Model
114
116
 
115
- - `supervise()` throws synchronously for invalid config such as missing `name`,
116
- missing `command`, or an invalid reserved color.
117
+ - `supervise()` throws synchronously for invalid config such as missing
118
+ `command`, a `command` that does not produce a fallback `name`, or an
119
+ invalid reserved color.
117
120
  - `waitFor()` rejects on timeout or terminal exit before a future match.
118
121
  - A thrown `match()` callback only unsubscribes that callback.
119
122
  - Errors from `ProcessConfig.stderr` stop teeing to that sink but do not stop
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "procband",
3
- "version": "0.2.0",
3
+ "version": "0.2.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",