diff --git a/src/bootstrap-fork.js b/src/bootstrap-fork.js index 9d760ddf101..6d11c4a57e8 100644 --- a/src/bootstrap-fork.js +++ b/src/bootstrap-fork.js @@ -47,11 +47,13 @@ globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { } }); +// VSCODE_GLOBALS: package/product.json +globalThis._VSCODE_PRODUCT_JSON = require('../product.json'); +globalThis._VSCODE_PACKAGE_JSON = require('../package.json'); // Load AMD entry point require('./bootstrap-amd').load(process.env['VSCODE_AMD_ENTRYPOINT']); - //#region Helpers function pipeLoggingToParent() { diff --git a/src/bootstrap-window.js b/src/bootstrap-window.js index f8b895c2d77..40a2ff21a49 100644 --- a/src/bootstrap-window.js +++ b/src/bootstrap-window.js @@ -122,6 +122,10 @@ } }); + // VSCODE_GLOBALS: package/product.json + globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)(configuration.appRoot + '/product.json'); + globalThis._VSCODE_PACKAGE_JSON = (require.__$__nodeRequire ?? require)(configuration.appRoot + '/package.json'); + const loaderConfig = { baseUrl: `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out`, 'vs/nls': nlsConfig, diff --git a/src/main.js b/src/main.js index 4c43e0923b7..c40595aa75d 100644 --- a/src/main.js +++ b/src/main.js @@ -151,6 +151,10 @@ function startup(codeCachePath, nlsConfig) { } }); + // VSCODE_GLOBALS: package/product.json + globalThis._VSCODE_PRODUCT_JSON = require('../product.json'); + globalThis._VSCODE_PACKAGE_JSON = require('../package.json'); + // Load main in AMD perf.mark('code/willLoadMainBundle'); require('./bootstrap-amd').load('vs/code/electron-main/main', () => { diff --git a/src/typings/vscode-globals.d.ts b/src/typings/vscode-globals.d.ts index f8d32c405bf..35e81033fc1 100644 --- a/src/typings/vscode-globals.d.ts +++ b/src/typings/vscode-globals.d.ts @@ -5,6 +5,15 @@ declare global { + /** + * @deprecated You MUST use `IProductService` whenever possible. + */ + var _VSCODE_PRODUCT_JSON: Record; + /** + * @deprecated You MUST use `IProductService` whenever possible. + */ + var _VSCODE_PACKAGE_JSON: Record; + /** * @deprecated node modules that are in used in a context that * shouldn't have access to node_modules (node-free renderer or diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts index 3f50bef5ca2..ef798fa4699 100644 --- a/src/vs/platform/product/common/product.ts +++ b/src/vs/platform/product/common/product.ts @@ -3,11 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { FileAccess } from 'vs/base/common/network'; import { globals } from 'vs/base/common/platform'; import { env } from 'vs/base/common/process'; import { IProductConfiguration } from 'vs/base/common/product'; -import { dirname, joinPath } from 'vs/base/common/resources'; import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes'; /** @@ -24,14 +22,10 @@ if (typeof globals.vscode !== 'undefined' && typeof globals.vscode.context !== ' throw new Error('Sandbox: unable to resolve product configuration from preload script.'); } } - -// Native node.js environment -else if (typeof require?.__$__nodeRequire === 'function') { - - // Obtain values from product.json and package.json - const rootPath = dirname(FileAccess.asFileUri('')); - - product = require.__$__nodeRequire(joinPath(rootPath, 'product.json').fsPath); +// _VSCODE environment +else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) { + // Obtain values from product.json and package.json-data + product = globalThis._VSCODE_PRODUCT_JSON as IProductConfiguration; // Running out of sources if (env['VSCODE_DEV']) { @@ -47,7 +41,7 @@ else if (typeof require?.__$__nodeRequire === 'function') { // want to have it running out of sources so we // read it from package.json only when we need it. if (!product.version) { - const pkg = require.__$__nodeRequire(joinPath(rootPath, 'package.json').fsPath) as { version: string }; + const pkg = globalThis._VSCODE_PACKAGE_JSON as { version: string }; Object.assign(product, { version: pkg.version diff --git a/test/unit/electron/renderer.js b/test/unit/electron/renderer.js index 3a7cc2fb66e..77a10b3421d 100644 --- a/test/unit/electron/renderer.js +++ b/test/unit/electron/renderer.js @@ -81,6 +81,9 @@ globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { return target[mod]; } }); +// VSCODE_GLOBALS: package/product.json +globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)('../../../product.json'); +globalThis._VSCODE_PACKAGE_JSON = (require.__$__nodeRequire ?? require)('../../../package.json'); const _tests_glob = '**/test/**/*.test.js'; let loader;