Skip to content

Commit 93c3f32

Browse files
committed
don't use __$__nodeRequire to fetch product configuration
1 parent 0824db3 commit 93c3f32

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

src/bootstrap-fork.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), {
4747
}
4848
});
4949

50+
// VSCODE_GLOBALS: package/product.json
51+
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');
52+
globalThis._VSCODE_PACKAGE_JSON = require('../package.json');
5053

5154
// Load AMD entry point
5255
require('./bootstrap-amd').load(process.env['VSCODE_AMD_ENTRYPOINT']);
5356

54-
5557
//#region Helpers
5658

5759
function pipeLoggingToParent() {

src/bootstrap-window.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
}
123123
});
124124

125+
// VSCODE_GLOBALS: package/product.json
126+
globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)(configuration.appRoot + '/product.json');
127+
globalThis._VSCODE_PACKAGE_JSON = (require.__$__nodeRequire ?? require)(configuration.appRoot + '/package.json');
128+
125129
const loaderConfig = {
126130
baseUrl: `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out`,
127131
'vs/nls': nlsConfig,

src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ function startup(codeCachePath, nlsConfig) {
151151
}
152152
});
153153

154+
// VSCODE_GLOBALS: package/product.json
155+
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');
156+
globalThis._VSCODE_PACKAGE_JSON = require('../package.json');
157+
154158
// Load main in AMD
155159
perf.mark('code/willLoadMainBundle');
156160
require('./bootstrap-amd').load('vs/code/electron-main/main', () => {

src/typings/vscode-globals.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
declare global {
77

8+
/**
9+
* @deprecated You MUST use `IProductService` whenever possible.
10+
*/
11+
var _VSCODE_PRODUCT_JSON: Record<string, any>;
12+
/**
13+
* @deprecated You MUST use `IProductService` whenever possible.
14+
*/
15+
var _VSCODE_PACKAGE_JSON: Record<string, any>;
16+
817
/**
918
* @deprecated node modules that are in used in a context that
1019
* shouldn't have access to node_modules (node-free renderer or

src/vs/platform/product/common/product.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { FileAccess } from 'vs/base/common/network';
76
import { globals } from 'vs/base/common/platform';
87
import { env } from 'vs/base/common/process';
98
import { IProductConfiguration } from 'vs/base/common/product';
10-
import { dirname, joinPath } from 'vs/base/common/resources';
119
import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';
1210

1311
/**
@@ -24,14 +22,10 @@ if (typeof globals.vscode !== 'undefined' && typeof globals.vscode.context !== '
2422
throw new Error('Sandbox: unable to resolve product configuration from preload script.');
2523
}
2624
}
27-
28-
// Native node.js environment
29-
else if (typeof require?.__$__nodeRequire === 'function') {
30-
31-
// Obtain values from product.json and package.json
32-
const rootPath = dirname(FileAccess.asFileUri(''));
33-
34-
product = require.__$__nodeRequire(joinPath(rootPath, 'product.json').fsPath);
25+
// _VSCODE environment
26+
else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) {
27+
// Obtain values from product.json and package.json-data
28+
product = globalThis._VSCODE_PRODUCT_JSON as IProductConfiguration;
3529

3630
// Running out of sources
3731
if (env['VSCODE_DEV']) {
@@ -47,7 +41,7 @@ else if (typeof require?.__$__nodeRequire === 'function') {
4741
// want to have it running out of sources so we
4842
// read it from package.json only when we need it.
4943
if (!product.version) {
50-
const pkg = require.__$__nodeRequire(joinPath(rootPath, 'package.json').fsPath) as { version: string };
44+
const pkg = globalThis._VSCODE_PACKAGE_JSON as { version: string };
5145

5246
Object.assign(product, {
5347
version: pkg.version

test/unit/electron/renderer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), {
8181
return target[mod];
8282
}
8383
});
84+
// VSCODE_GLOBALS: package/product.json
85+
globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)('../../../product.json');
86+
globalThis._VSCODE_PACKAGE_JSON = (require.__$__nodeRequire ?? require)('../../../package.json');
8487

8588
const _tests_glob = '**/test/**/*.test.js';
8689
let loader;

0 commit comments

Comments
 (0)