procband 0.3.2 → 0.3.3

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/dist/index.mjs +19 -4
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -111,7 +111,7 @@ var MatchRegistry = class {
111
111
  }
112
112
  waitFor(pattern, options) {
113
113
  if (this.closedError) return Promise.reject(this.closedError);
114
- return new Promise((resolve, reject) => {
114
+ const promise = new Promise((resolve, reject) => {
115
115
  const subscription = {
116
116
  active: true,
117
117
  kind: "promise",
@@ -125,6 +125,9 @@ var MatchRegistry = class {
125
125
  this.unsubscribe(subscription);
126
126
  reject(error);
127
127
  },
128
+ suppressUnhandledRejection: () => {
129
+ promise.catch(() => {});
130
+ },
128
131
  timer: null
129
132
  };
130
133
  if (options?.timeoutMs != null) subscription.timer = setTimeout(() => {
@@ -132,6 +135,7 @@ var MatchRegistry = class {
132
135
  }, options.timeoutMs);
133
136
  this.subscriptions.add(subscription);
134
137
  });
138
+ return promise;
135
139
  }
136
140
  emit(stream, line) {
137
141
  if (this.closedError) return;
@@ -155,11 +159,17 @@ var MatchRegistry = class {
155
159
  subscription.resolve(event);
156
160
  }
157
161
  }
162
+ hasPendingWait() {
163
+ for (const subscription of this.subscriptions) if (subscription.kind === "promise") return true;
164
+ return false;
165
+ }
158
166
  close(error) {
159
167
  if (this.closedError) return;
160
168
  this.closedError = error;
161
- for (const subscription of [...this.subscriptions]) if (subscription.kind === "promise") subscription.reject(error);
162
- else this.unsubscribe(subscription);
169
+ for (const subscription of [...this.subscriptions]) if (subscription.kind === "promise") {
170
+ subscription.suppressUnhandledRejection();
171
+ subscription.reject(error);
172
+ } else this.unsubscribe(subscription);
163
173
  }
164
174
  unsubscribe(subscription) {
165
175
  if (!subscription.active) return;
@@ -639,11 +649,16 @@ var ProcbandProcessImpl = class extends EventEmitter {
639
649
  liveProcesses.delete(this);
640
650
  if (liveProcesses.size === 0) propagatedFailure = false;
641
651
  if (this.shouldPropagateFailure(result)) propagateFailure(result.exitCode);
642
- this.matches.close(/* @__PURE__ */ new Error(`Process "${this.name}" exited before a matching line was observed`));
652
+ this.closeMatches();
643
653
  this.unbindStderrSink();
644
654
  unregisterCleanupTarget(this);
645
655
  this.finalResolve(result);
646
656
  }
657
+ closeMatches() {
658
+ const error = /* @__PURE__ */ new Error(`Process "${this.name}" exited before a matching line was observed`);
659
+ if (this.matches.hasPendingWait()) writePrefixedLine(process.stderr, this.label, stderrColor, error.message, true);
660
+ this.matches.close(error);
661
+ }
647
662
  markTerminalResultObserved() {
648
663
  this.terminalResultObserved = true;
649
664
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "procband",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
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",