nano-spawn-compat 2.0.2 → 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 +1 -1
- package/source/result.js +10 -10
- package/source/spawn.js +9 -11
package/package.json
CHANGED
package/source/result.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
-
import {once
|
|
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.
|
|
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 =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -45,14 +46,11 @@ const concatenateShell = (file, commandArguments, options) => options.shell && c
|
|
|
45
46
|
: [file, commandArguments, options];
|
|
46
47
|
|
|
47
48
|
const bufferOutput = (stream, {state}, streamName) => {
|
|
48
|
-
if (stream) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
state
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
state.output += chunk;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
49
|
+
if (stream && !state.isIterating[streamName]) {
|
|
50
|
+
state.isIterating[streamName] = false;
|
|
51
|
+
stream.on('data', chunk => {
|
|
52
|
+
state[streamName] += chunk;
|
|
53
|
+
state.output += chunk;
|
|
54
|
+
});
|
|
57
55
|
}
|
|
58
56
|
};
|