Skip to content

Commit 1a87c18

Browse files
chore: use process.stdin for subprocess
1 parent 72ea3da commit 1a87c18

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

__tests__/command2.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('execAsync', () => {
4040
expect(await command.execAsync({command: 'test', cwd: 'dir', altCommand: 'alt'})).toEqual({stdout: 'stdout', stderr: 'stderr', command: 'alt'});
4141

4242
execCalledWith(mockExec, [
43-
['test', [], {'cwd': 'dir', shell: true}],
43+
'test',
4444
]);
4545
stdoutCalledWith(mockStdout, [
4646
'[command]alt',

__tests__/git-helper.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ describe('GitHelper', () => {
287287
]);
288288

289289
execCalledWith(mockExec, [
290-
['command1', [], {cwd: workDir, shell: true}],
291-
['command2', [], {cwd: workDir, shell: true}],
292-
['command3', [], {cwd: workDir, shell: true}],
290+
'command1',
291+
'command2',
292+
'command3',
293293
]);
294294
});
295295

@@ -329,9 +329,9 @@ describe('GitHelper', () => {
329329
]);
330330

331331
execCalledWith(mockExec, [
332-
['command1', [], {cwd: workDir, shell: true}],
333-
['command2', [], {cwd: workDir, shell: true}],
334-
['command3 > /dev/null 2>&1', [], {cwd: workDir, shell: true}],
332+
'command1',
333+
'command2',
334+
'command3 > /dev/null 2>&1',
335335
]);
336336
});
337337

src/command.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,23 @@ export default class Command {
125125
cwd?: string,
126126
): Promise<{ stdout: string; stderr: string }> => {
127127
return new Promise((resolve, reject) => {
128-
const process = spawn(command, [], {shell: true, cwd});
129-
let stdout = '';
130-
let stderr = '';
131-
process.stdout.on('data', (data) => {
128+
const subProcess = spawn(command, [], {shell: true, cwd, stdio: [process.stdin, 'pipe', 'pipe']});
129+
let stdout = '';
130+
let stderr = '';
131+
subProcess.stdout.on('data', (data) => {
132132
this.outputStdout(data.toString(), quiet, suppressOutput);
133133
stdout += data.toString();
134134
});
135135

136-
process.stderr.on('data', (data) => {
136+
subProcess.stderr.on('data', (data) => {
137137
this.outputStderr(data.toString(), quiet, suppressOutput, stderrToStdout);
138138
stderr += data.toString();
139139
});
140140

141-
process.on('error', (err) => {
141+
subProcess.on('error', (err) => {
142142
reject(err);
143143
});
144-
process.on('close', () => {
144+
subProcess.on('close', () => {
145145
resolve({stdout, stderr});
146146
});
147147
});

0 commit comments

Comments
 (0)