workkit-core 0.86.0 → 0.87.1
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/test/lib/spawn.js +10 -3
package/package.json
CHANGED
package/test/lib/spawn.js
CHANGED
|
@@ -98,13 +98,14 @@ export const run = (cmd, args, { cwd, env, input, deadline = SPAWN_DEADLINE } =
|
|
|
98
98
|
* group, else the child alone; on Windows one `taskkill` tree end, which reaches no grandchild once a detached leader
|
|
99
99
|
* has exited. A signal off the ladder rejects; a child that never spawned ends at once, `done` rejecting with the error.
|
|
100
100
|
* A refused rung rejects `end: signal refused for pid <N> (EPERM)`; alive END_GRACE after SIGKILL, `end: pid <N> survived SIGKILL`.
|
|
101
|
+
* With `input`, stdin is a pipe the string is written to, then closed; without it, stdin is ignored.
|
|
101
102
|
* @param {string} cmd
|
|
102
103
|
* @param {string[]} args
|
|
103
|
-
* @param {{cwd?: string, env?: object, deadline?: number, detached?: boolean}} [opts]
|
|
104
|
+
* @param {{cwd?: string, env?: object, input?: string, deadline?: number, detached?: boolean}} [opts]
|
|
104
105
|
* @returns {{child: object, pid: number, output: Function, stdout: Function, stderr: Function, done: Promise, end: Function}}
|
|
105
106
|
*/
|
|
106
|
-
export const start = (cmd, args, { cwd, env, deadline = SPAWN_DEADLINE, detached = false } = {}) => {
|
|
107
|
-
const child = spawn(cmd, args, { cwd, env, detached, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
107
|
+
export const start = (cmd, args, { cwd, env, input, deadline = SPAWN_DEADLINE, detached = false } = {}) => {
|
|
108
|
+
const child = spawn(cmd, args, { cwd, env, detached, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'] });
|
|
108
109
|
let out = '';
|
|
109
110
|
let err = '';
|
|
110
111
|
let all = '';
|
|
@@ -129,6 +130,12 @@ export const start = (cmd, args, { cwd, env, deadline = SPAWN_DEADLINE, detached
|
|
|
129
130
|
});
|
|
130
131
|
const { promise: done, resolve: settleDone, reject: failDone } = Promise.withResolvers();
|
|
131
132
|
child.once('error', failDone);
|
|
133
|
+
if (input !== undefined) {
|
|
134
|
+
// A child that exits without reading it all leaves the write unfinished: its exit answers, the broken pipe
|
|
135
|
+
// (EPIPE, or EOF on Windows) does not.
|
|
136
|
+
child.stdin.on('error', (error) => { if (error.code !== 'EPIPE' && error.code !== 'EOF') failDone(error); });
|
|
137
|
+
child.stdin.end(input);
|
|
138
|
+
}
|
|
132
139
|
child.once('close', () => settleDone({ ...exit, timedOut }));
|
|
133
140
|
// `done` still rejects for whoever awaits it; a caller that only awaits
|
|
134
141
|
// `end()` must not die of the unhandled rejection.
|