forked from microsoft/vscode-python-environments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchildProcess.apis.ts
More file actions
33 lines (29 loc) · 1.09 KB
/
childProcess.apis.ts
File metadata and controls
33 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import * as cp from 'child_process';
/**
* Spawns a new process using the specified command and arguments.
* This function abstracts cp.spawn to make it easier to mock in tests.
*
* When stdio: 'pipe' is used, returns ChildProcessWithoutNullStreams.
* Otherwise returns the standard ChildProcess.
*/
// Overload for stdio: 'pipe' - guarantees non-null streams
export function spawnProcess(
command: string,
args: string[],
options: cp.SpawnOptions & { stdio: 'pipe' },
): cp.ChildProcessWithoutNullStreams;
// Overload for general case
export function spawnProcess(command: string, args: string[], options?: cp.SpawnOptions): cp.ChildProcess;
// Implementation - delegates to cp.spawn to preserve its typing magic
export function spawnProcess(
command: string,
args: string[],
options?: cp.SpawnOptions,
): cp.ChildProcess | cp.ChildProcessWithoutNullStreams {
// Set PYTHONUTF8=1; user-provided PYTHONUTF8 values take precedence.
const env = {
PYTHONUTF8: '1',
...(options?.env ?? process.env),
};
return cp.spawn(command, args, { ...options, env });
}