@rspack/cli 2.0.1 → 2.0.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/dist/exit-hook.js CHANGED
@@ -3,11 +3,42 @@ const asyncCallbacks = new Set();
3
3
  const callbacks = new Set();
4
4
  let isCalled = false;
5
5
  let isRegistered = false;
6
+ async function flushStdio() {
7
+ const flush = (stream)=>new Promise((resolve)=>{
8
+ if (!stream || !stream.writable || stream.writableEnded || stream.destroyed) return void resolve();
9
+ const onError = ()=>{
10
+ stream.off('error', onError);
11
+ resolve();
12
+ };
13
+ stream.once('error', onError);
14
+ try {
15
+ stream.write('', ()=>{
16
+ stream.off('error', onError);
17
+ resolve();
18
+ });
19
+ } catch {
20
+ stream.off('error', onError);
21
+ resolve();
22
+ }
23
+ });
24
+ const timeout = new Promise((resolve)=>{
25
+ setTimeout(resolve, 1000);
26
+ });
27
+ await Promise.race([
28
+ Promise.all([
29
+ flush(node_process.stdout),
30
+ flush(node_process.stderr)
31
+ ]),
32
+ timeout
33
+ ]);
34
+ }
6
35
  async function exit(shouldManuallyExit, isSynchronous, signal) {
7
36
  if (isCalled) return;
8
37
  isCalled = true;
9
38
  if (asyncCallbacks.size > 0 && isSynchronous) console.error("SYNCHRONOUS TERMINATION NOTICE: When explicitly exiting the process via process.exit or via a parent process, asynchronous tasks in your exitHooks will not run. Either remove these tasks, use gracefulExit() instead of process.exit(), or ensure your parent process sends a SIGINT to the process running this code.");
10
- const exitCode = 128 + signal;
39
+ let exitCode = 0;
40
+ if (signal > 0) exitCode = 128 + signal;
41
+ else if ('number' == typeof node_process.exitCode || 'string' == typeof node_process.exitCode) exitCode = node_process.exitCode;
11
42
  const done = (force = false)=>{
12
43
  if (true === force || true === shouldManuallyExit) node_process.exit(exitCode);
13
44
  };
@@ -19,11 +50,12 @@ async function exit(shouldManuallyExit, isSynchronous, signal) {
19
50
  forceAfter = Math.max(forceAfter, wait);
20
51
  promises.push(Promise.resolve(callback(exitCode)));
21
52
  }
22
- const asyncTimer = setTimeout(()=>{
53
+ const asyncTimer = forceAfter > 0 ? setTimeout(()=>{
23
54
  done(true);
24
- }, forceAfter);
55
+ }, forceAfter) : void 0;
25
56
  await Promise.all(promises);
26
57
  clearTimeout(asyncTimer);
58
+ await flushStdio();
27
59
  done();
28
60
  }
29
61
  function addHook(options) {