nano-spawn-compat 2.0.3 → 2.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nano-spawn-compat",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Tiny process execution for humans — a better child_process",
5
5
  "license": "MIT",
6
6
  "repository": "leonsilicon/nano-spawn-compat",
package/source/result.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import process from 'node:process';
2
- import {once, on} from './once.js';
2
+ import {once} from './once.js';
3
3
 
4
4
  export const getResult = async (nodeChildProcess, {input}, context) => {
5
5
  const instance = await nodeChildProcess;
@@ -12,7 +12,7 @@ export const getResult = async (nodeChildProcess, {input}, context) => {
12
12
  try {
13
13
  await Promise.race([
14
14
  onClose,
15
- ...instance.stdio.filter(Boolean).map(stream => onStreamError(stream)),
15
+ ...[instance.stdin, instance.stdout, instance.stderr].filter(Boolean).map(stream => onStreamError(stream)),
16
16
  ]);
17
17
  checkFailure(context, getErrorOutput(instance));
18
18
  return getOutputs(context);
@@ -22,14 +22,14 @@ export const getResult = async (nodeChildProcess, {input}, context) => {
22
22
  }
23
23
  };
24
24
 
25
- const onStreamError = async stream => {
26
- for await (const [error] of on(stream, 'error')) {
27
- // Ignore errors that are due to closing errors when the subprocesses exit normally, or due to piping
28
- if (!['ERR_STREAM_PREMATURE_CLOSE', 'EPIPE'].includes(error?.code)) {
29
- throw error;
30
- }
31
- }
32
- };
25
+ const onStreamError = stream =>
26
+ new Promise((_resolve, reject) => {
27
+ stream.on('error', error => {
28
+ if (!['ERR_STREAM_PREMATURE_CLOSE', 'EPIPE'].includes(error?.code)) {
29
+ reject(error);
30
+ }
31
+ });
32
+ });
33
33
 
34
34
  const checkFailure = ({command}, {exitCode, signalName}) => {
35
35
  if (signalName !== undefined) {
package/source/spawn.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import {spawn} from 'node:child_process';
2
- import {once} from './once.js';
3
2
  import {applyForceShell} from './windows.js';
4
3
  import {getResultError} from './result.js';
5
4
 
@@ -25,7 +24,9 @@ export const spawnSubprocess = async (file, commandArguments, options, context)
25
24
  // This prevents that.
26
25
  instance.once('error', () => {});
27
26
 
28
- await once(instance, 'spawn');
27
+ /*
28
+ The spawn event isn't emitted.
29
+ await once(instance, 'spawn'); */
29
30
  return instance;
30
31
  } catch (error) {
31
32
  throw getResultError(error, {}, context);