Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/util/vs/base/common/process.ts
13405 views
1
//!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'
2
3
/*---------------------------------------------------------------------------------------------
4
* Copyright (c) Microsoft Corporation. All rights reserved.
5
* Licensed under the MIT License. See License.txt in the project root for license information.
6
*--------------------------------------------------------------------------------------------*/
7
8
import { INodeProcess, isMacintosh, isWindows } from './platform';
9
10
let safeProcess: Omit<INodeProcess, 'arch'> & { arch: string | undefined };
11
declare const process: INodeProcess;
12
13
// Native sandbox environment
14
const vscodeGlobal = (globalThis as { vscode?: { process?: INodeProcess } }).vscode;
15
if (typeof vscodeGlobal !== 'undefined' && typeof vscodeGlobal.process !== 'undefined') {
16
const sandboxProcess: INodeProcess = vscodeGlobal.process;
17
safeProcess = {
18
get platform() { return sandboxProcess.platform; },
19
get arch() { return sandboxProcess.arch; },
20
get env() { return sandboxProcess.env; },
21
cwd() { return sandboxProcess.cwd(); }
22
};
23
}
24
25
// Native node.js environment
26
else if (typeof process !== 'undefined' && typeof process?.versions?.node === 'string') {
27
safeProcess = {
28
get platform() { return process.platform; },
29
get arch() { return process.arch; },
30
get env() { return process.env; },
31
cwd() { return process.env['VSCODE_CWD'] || process.cwd(); }
32
};
33
}
34
35
// Web environment
36
else {
37
safeProcess = {
38
39
// Supported
40
get platform() { return isWindows ? 'win32' : isMacintosh ? 'darwin' : 'linux'; },
41
get arch() { return undefined; /* arch is undefined in web */ },
42
43
// Unsupported
44
get env() { return {}; },
45
cwd() { return '/'; }
46
};
47
}
48
49
/**
50
* Provides safe access to the `cwd` property in node.js, sandboxed or web
51
* environments.
52
*
53
* Note: in web, this property is hardcoded to be `/`.
54
*
55
* @skipMangle
56
*/
57
export const cwd = safeProcess.cwd;
58
59
/**
60
* Provides safe access to the `env` property in node.js, sandboxed or web
61
* environments.
62
*
63
* Note: in web, this property is hardcoded to be `{}`.
64
*/
65
export const env = safeProcess.env;
66
67
/**
68
* Provides safe access to the `platform` property in node.js, sandboxed or web
69
* environments.
70
*/
71
export const platform = safeProcess.platform;
72
73
/**
74
* Provides safe access to the `arch` method in node.js, sandboxed or web
75
* environments.
76
* Note: `arch` is `undefined` in web
77
*/
78
export const arch = safeProcess.arch;
79
80