@invarn/cli 0.2.7 → 0.2.9

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.
@@ -15,6 +15,26 @@ function send(msg) {
15
15
  process.send(msg);
16
16
  }
17
17
  }
18
+ async function drainStdioThenExit(code) {
19
+ const drainOne = (stream) => new Promise((resolve2) => {
20
+ try {
21
+ stream.write("", () => resolve2());
22
+ } catch {
23
+ resolve2();
24
+ }
25
+ });
26
+ const timeoutPromise = new Promise((resolve2) => {
27
+ const handle = setTimeout(resolve2, 200);
28
+ handle.unref();
29
+ });
30
+ await Promise.race([
31
+ Promise.all([drainOne(process.stdout), drainOne(process.stderr)]).then(
32
+ () => void 0
33
+ ),
34
+ timeoutPromise
35
+ ]);
36
+ process.exit(code);
37
+ }
18
38
  async function main() {
19
39
  send({ type: "started" });
20
40
  let cibuildLib;
@@ -25,7 +45,8 @@ async function main() {
25
45
  type: "crashed",
26
46
  error: `failed to load @invarn/cibuild/lib: ${err?.message ?? String(err)}`
27
47
  });
28
- process.exit(2);
48
+ await drainStdioThenExit(2);
49
+ return;
29
50
  }
30
51
  const {
31
52
  loadYAMLPipeline,
@@ -43,7 +64,8 @@ async function main() {
43
64
  exitCode: 1,
44
65
  failureReason: `Pipeline YAML load failed: ${err?.message ?? String(err)}`
45
66
  });
46
- process.exit(1);
67
+ await drainStdioThenExit(1);
68
+ return;
47
69
  }
48
70
  const config = loadConfig();
49
71
  config.local = true;
@@ -64,13 +86,14 @@ async function main() {
64
86
  exitCode: 1,
65
87
  failureReason: `Pipeline definition error: ${err?.message ?? String(err)}`
66
88
  });
67
- process.exit(1);
89
+ await drainStdioThenExit(1);
90
+ return;
68
91
  }
69
92
  const runner = new PipelineRunner(config);
70
93
  try {
71
94
  await runner.runPipeline(pipeline, warnings, skippedSteps);
72
95
  send({ type: "completed", exitCode: 0 });
73
- process.exit(0);
96
+ await drainStdioThenExit(0);
74
97
  } catch (err) {
75
98
  const message = err?.message ?? String(err);
76
99
  const stepMatch = /Step\s+"([^"]+)"\s+failed/i.exec(message);
@@ -81,13 +104,13 @@ async function main() {
81
104
  failureReason: message,
82
105
  failedStepName
83
106
  });
84
- process.exit(1);
107
+ await drainStdioThenExit(1);
85
108
  }
86
109
  }
87
- main().catch((err) => {
110
+ main().catch(async (err) => {
88
111
  send({
89
112
  type: "crashed",
90
113
  error: `worker uncaught: ${err?.message ?? String(err)}`
91
114
  });
92
- process.exit(2);
115
+ await drainStdioThenExit(2);
93
116
  });