1
>
/*---------------------------------------------------------------------------------------------
processes.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { IProcessEnvironment, isLinux } from './platform.js';
7
>
8
>
/**
9
>
* Options to be passed to the external program or shell.
10
>
*/
11
>
export interface CommandOptions {
12
>
/**
13
>
* The current working directory of the executed program or shell.
14
>
* If omitted VSCode's current workspace root is used.
15
>
*/
16
>
cwd?: string;
17
>
18
>
/**
19
>
* The environment of the executed program or shell. If omitted
20
>
* the parent process' environment is used.
21
>
*/
22
>
env?: { [key: string]: string };
23
>
}
24
>
25
>
export interface Executable {
26
>
/**
27
>
* The command to be executed. Can be an external program or a shell
28
>
* command.
29
>
*/
30
>
command: string;
31
>
32
>
/**
33
>
* Specifies whether the command is a shell command and therefore must
34
>
* be executed in a shell interpreter (e.g. cmd.exe, bash, ...).
35
>
*/
36
>
isShellCommand: boolean;
37
>
38
>
/**
39
>
* The arguments passed to the command.
40
>
*/
41
>
args: string[];
42
>
43
>
/**
44
>
* The command options used when the command is executed. Can be omitted.
45
>
*/
46
>
options?: CommandOptions;
47
>
}
48
>
49
>
export interface ForkOptions extends CommandOptions {
50
>
execArgv?: string[];
51
>
}
52
>
53
>
export const enum Source {
54
>
stdout,
55
>
stderr
56
>
}
57
>
58
>
/**
59
>
* The data send via a success callback
60
>
*/
61
>
export interface SuccessData {
62
>
error?: Error;
63
>
cmdCode?: number;
64
>
terminated?: boolean;
65
>
}
66
>
67
>
/**
68
>
* The data send via a error callback
69
>
*/
70
>
export interface ErrorData {
71
>
error?: Error;
72
>
terminated?: boolean;
73
>
stdout?: string;
74
>
stderr?: string;
75
>
}
76
>
77
>
export interface TerminateResponse {
78
>
success: boolean;
79
>
code?: TerminateResponseCode;
80
>
error?: any;
81
>
}
82
>
83
>
export const enum TerminateResponseCode {
84
>
Success = 0,
85
>
Unknown = 1,
86
>
AccessDenied = 2,
87
>
ProcessNotFound = 3,
88
>
}
89
>
90
>
export interface ProcessItem {
91
>
name: string;
92
>
cmd: string;
93
>
pid: number;
94
>
ppid: number;
95
>
load: number;
96
>
mem: number;
97
>
98
>
children?: ProcessItem[];
99
>
}
100
>
101
>
/**
102
>
* Sanitizes a VS Code process environment by removing all Electron/VS Code-related values.
103
>
*/
104
>
export function sanitizeProcessEnvironment(env: IProcessEnvironment, ...preserve: string[]): void {
105
const set = preserve.reduce<Record<string, boolean>>((set, key) => {
106
set[key] = true;