Skip to content

Commit 9740d4b

Browse files
authored
Merge pull request microsoft#166590 from microsoft/joh/representative-canidae
joh/representative canidae
2 parents 1ac5ea4 + 6dd2726 commit 9740d4b

File tree

18 files changed

+123
-25
lines changed

18 files changed

+123
-25
lines changed

src/bootstrap-fork.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ if (process.env['VSCODE_PARENT_PID']) {
3737
terminateWhenParentTerminates();
3838
}
3939

40+
// VSCODE_GLOBALS: node_modules
41+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) });
42+
43+
// VSCODE_GLOBALS: package/product.json
44+
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');
45+
globalThis._VSCODE_PACKAGE_JSON = require('../package.json');
46+
4047
// Load AMD entry point
4148
require('./bootstrap-amd').load(process.env['VSCODE_AMD_ENTRYPOINT']);
4249

43-
4450
//#region Helpers
4551

4652
function pipeLoggingToParent() {

src/bootstrap-window.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@
112112

113113
window['MonacoEnvironment'] = {};
114114

115+
// VSCODE_GLOBALS: node_modules
116+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => (require.__$__nodeRequire ?? require)(String(mod)) });
117+
118+
// VSCODE_GLOBALS: package/product.json
119+
globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)(configuration.appRoot + '/product.json');
120+
globalThis._VSCODE_PACKAGE_JSON = (require.__$__nodeRequire ?? require)(configuration.appRoot + '/package.json');
121+
115122
const loaderConfig = {
116123
baseUrl: `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out`,
117124
'vs/nls': nlsConfig,

src/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ function startup(codeCachePath, nlsConfig) {
141141
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig);
142142
process.env['VSCODE_CODE_CACHE_PATH'] = codeCachePath || '';
143143

144+
// VSCODE_GLOBALS: node_modules
145+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) });
146+
147+
// VSCODE_GLOBALS: package/product.json
148+
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');
149+
globalThis._VSCODE_PACKAGE_JSON = require('../package.json');
150+
144151
// Load main in AMD
145152
perf.mark('code/willLoadMainBundle');
146153
require('./bootstrap-amd').load('vs/code/electron-main/main', () => {
@@ -318,6 +325,7 @@ function getArgvConfigPath() {
318325
dataFolderName = `${dataFolderName}-dev`;
319326
}
320327

328+
// @ts-ignore
321329
return path.join(os.homedir(), dataFolderName, 'argv.json');
322330
}
323331

src/server-main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ function loadCode() {
258258
return new Promise((resolve, reject) => {
259259
const path = require('path');
260260

261+
// VSCODE_GLOBALS: node_modules
262+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) });
263+
264+
// VSCODE_GLOBALS: package/product.json
265+
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');
266+
globalThis._VSCODE_PACKAGE_JSON = require('../package.json');
267+
261268
delete process.env['ELECTRON_RUN_AS_NODE']; // Keep bootstrap-amd.js from redefining 'fs'.
262269

263270
// See https://github.com/microsoft/vscode-remote-release/issues/6543

src/tsconfig.monaco.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"include": [
1919
"typings/require.d.ts",
2020
"typings/thenable.d.ts",
21+
"typings/vscode-globals-product.d.ts",
2122
"vs/loader.d.ts",
2223
"vs/monaco.d.ts",
2324
"vs/editor/*",

src/typings/require.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ interface NodeRequire {
4545
* @deprecated use `FileAccess.asFileUri()` for node.js contexts or `FileAccess.asBrowserUri` for browser contexts.
4646
*/
4747
toUrl(path: string): string;
48+
49+
/**
50+
* @deprecated MUST not be used anymore
51+
*
52+
* With the move from AMD to ESM we cannot use this anymore. There will be NO MORE node require like this.
53+
*/
54+
__$__nodeRequire<T>(moduleName: string): T;
55+
4856
(dependencies: string[], callback: (...args: any[]) => any, errorback?: (err: any) => void): any;
4957
config(data: any): any;
5058
onError: Function;
51-
__$__nodeRequire<T>(moduleName: string): T;
5259
getStats?(): ReadonlyArray<LoaderEvent>;
5360
hasDependencyCycle?(): boolean;
5461
define(amdModuleId: string, dependencies: string[], callback: (...args: any[]) => any): any;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*---------------------------------------------------------------------------------------------
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+
// AMD2ESM mirgation relevant
7+
8+
declare global {
9+
10+
/**
11+
* @deprecated node modules that are in used in a context that
12+
* shouldn't have access to node_modules (node-free renderer or
13+
* shared process)
14+
*/
15+
var _VSCODE_NODE_MODULES: {
16+
crypto: typeof import('crypto');
17+
zlib: typeof import('zlib');
18+
net: typeof import('net');
19+
os: typeof import('os');
20+
module: typeof import('module');
21+
['native-watchdog']: typeof import('native-watchdog')
22+
perf_hooks: typeof import('perf_hooks');
23+
24+
['vsda']: any
25+
['vscode-encrypt']: any
26+
}
27+
}
28+
29+
// fake export to make global work
30+
export { }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------------------------------------------------------------------------------
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+
// AMD2ESM mirgation relevant
7+
8+
declare global {
9+
10+
/**
11+
* @deprecated You MUST use `IProductService` whenever possible.
12+
*/
13+
var _VSCODE_PRODUCT_JSON: Record<string, any>;
14+
/**
15+
* @deprecated You MUST use `IProductService` whenever possible.
16+
*/
17+
var _VSCODE_PACKAGE_JSON: Record<string, any>;
18+
19+
}
20+
21+
// fake export to make global work
22+
export { }

src/vs/base/common/performance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
} else if (typeof process === 'object') {
7979
// node.js: use the normal polyfill but add the timeOrigin
8080
// from the node perf_hooks API as very first mark
81-
const timeOrigin = Math.round((require.nodeRequire || require)('perf_hooks').performance.timeOrigin);
81+
const timeOrigin = Math.round((require.__$__nodeRequire || require)('perf_hooks').performance.timeOrigin);
8282
return _definePolyfillMarks(timeOrigin);
8383

8484
} else {

src/vs/base/parts/ipc/node/ipc.net.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import { ChunkStream, Client, ISocket, Protocol, SocketCloseEvent, SocketCloseEv
2020
// TODO@bpasero remove me once electron utility process has landed
2121
function getNodeDependencies() {
2222
return {
23-
crypto: (require.__$__nodeRequire('crypto') as any) as typeof import('crypto'),
24-
zlib: (require.__$__nodeRequire('zlib') as any) as typeof import('zlib'),
25-
net: (require.__$__nodeRequire('net') as any) as typeof import('net'),
26-
os: (require.__$__nodeRequire('os') as any) as typeof import('os')
23+
crypto: globalThis._VSCODE_NODE_MODULES.crypto,
24+
zlib: globalThis._VSCODE_NODE_MODULES.zlib,
25+
net: globalThis._VSCODE_NODE_MODULES.net,
26+
os: globalThis._VSCODE_NODE_MODULES.os,
2727
};
2828
}
2929

0 commit comments

Comments
 (0)