From d555777b1a4ce1449bb5e183dac52f851e1c31f5 Mon Sep 17 00:00:00 2001 From: Johannes Date: Thu, 17 Nov 2022 17:58:51 +0100 Subject: [PATCH] simplify `_VSCODE_NODE_MODULES` util --- src/bootstrap-fork.js | 9 +-------- src/bootstrap-window.js | 9 +-------- src/main.js | 9 +-------- src/server-main.js | 10 ++-------- test/unit/electron/renderer.js | 10 ++-------- test/unit/node/index.js | 9 +-------- 6 files changed, 8 insertions(+), 48 deletions(-) diff --git a/src/bootstrap-fork.js b/src/bootstrap-fork.js index 6d11c4a57e8..00bf5ed7451 100644 --- a/src/bootstrap-fork.js +++ b/src/bootstrap-fork.js @@ -38,14 +38,7 @@ if (process.env['VSCODE_PARENT_PID']) { } // VSCODE_GLOBALS: node_modules -globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { - get(target, mod) { - if (!target[mod] && typeof mod === 'string') { - target[mod] = require(mod); - } - return target[mod]; - } -}); +globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) }); // VSCODE_GLOBALS: package/product.json globalThis._VSCODE_PRODUCT_JSON = require('../product.json'); diff --git a/src/bootstrap-window.js b/src/bootstrap-window.js index 40a2ff21a49..e4218117b7d 100644 --- a/src/bootstrap-window.js +++ b/src/bootstrap-window.js @@ -113,14 +113,7 @@ window['MonacoEnvironment'] = {}; // VSCODE_GLOBALS: node_modules - globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { - get(target, mod) { - if (!target[mod] && typeof mod === 'string') { - target[mod] = (require.__$__nodeRequire ?? require)(mod); - } - return target[mod]; - } - }); + globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => (require.__$__nodeRequire ?? require)(String(mod)) }); // VSCODE_GLOBALS: package/product.json globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)(configuration.appRoot + '/product.json'); diff --git a/src/main.js b/src/main.js index c40595aa75d..eebc049c6f5 100644 --- a/src/main.js +++ b/src/main.js @@ -142,14 +142,7 @@ function startup(codeCachePath, nlsConfig) { process.env['VSCODE_CODE_CACHE_PATH'] = codeCachePath || ''; // VSCODE_GLOBALS: node_modules - globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { - get(target, mod) { - if (!target[mod] && typeof mod === 'string') { - target[mod] = require(mod); - } - return target[mod]; - } - }); + globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) }); // VSCODE_GLOBALS: package/product.json globalThis._VSCODE_PRODUCT_JSON = require('../product.json'); diff --git a/src/server-main.js b/src/server-main.js index 04a3161c825..156387b1cc3 100644 --- a/src/server-main.js +++ b/src/server-main.js @@ -260,14 +260,8 @@ function loadCode() { const path = require('path'); // VSCODE_GLOBALS: node_modules - globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { - get(target, mod) { - if (!target[mod] && typeof mod === 'string') { - target[mod] = require(mod); - } - return target[mod]; - } - }); + globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) }); + // VSCODE_GLOBALS: package/product.json globalThis._VSCODE_PRODUCT_JSON = require('../product.json'); globalThis._VSCODE_PACKAGE_JSON = require('../package.json'); diff --git a/test/unit/electron/renderer.js b/test/unit/electron/renderer.js index 77a10b3421d..a91725887a5 100644 --- a/test/unit/electron/renderer.js +++ b/test/unit/electron/renderer.js @@ -73,14 +73,8 @@ if (util.inspect && util.inspect['defaultOptions']) { } // VSCODE_GLOBALS: node_modules -globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { - get(target, mod) { - if (!target[mod] && typeof mod === 'string') { - target[mod] = (require.__$__nodeRequire ?? require)(mod); - } - return target[mod]; - } -}); +globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => (require.__$__nodeRequire ?? require)(String(mod)) }); + // VSCODE_GLOBALS: package/product.json globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)('../../../product.json'); globalThis._VSCODE_PACKAGE_JSON = (require.__$__nodeRequire ?? require)('../../../package.json'); diff --git a/test/unit/node/index.js b/test/unit/node/index.js index cea515286a0..c6474162dfc 100644 --- a/test/unit/node/index.js +++ b/test/unit/node/index.js @@ -58,14 +58,7 @@ if (majorRequiredNodeVersion !== currentMajorNodeVersion) { function main() { // VSCODE_GLOBALS: node_modules - globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { - get(target, mod) { - if (!target[mod] && typeof mod === 'string') { - target[mod] = require(mod); - } - return target[mod]; - } - }); + globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) }); // VSCODE_GLOBALS: package/product.json globalThis._VSCODE_PRODUCT_JSON = require(`${REPO_ROOT}/product.json`);