Skip to content

Commit 6dd2726

Browse files
committed
simplify _VSCODE_NODE_MODULES util
1 parent 1595c5b commit 6dd2726

File tree

6 files changed

+8
-48
lines changed

6 files changed

+8
-48
lines changed

src/bootstrap-fork.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ if (process.env['VSCODE_PARENT_PID']) {
3838
}
3939

4040
// VSCODE_GLOBALS: node_modules
41-
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), {
42-
get(target, mod) {
43-
if (!target[mod] && typeof mod === 'string') {
44-
target[mod] = require(mod);
45-
}
46-
return target[mod];
47-
}
48-
});
41+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) });
4942

5043
// VSCODE_GLOBALS: package/product.json
5144
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');

src/bootstrap-window.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,7 @@
113113
window['MonacoEnvironment'] = {};
114114

115115
// VSCODE_GLOBALS: node_modules
116-
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), {
117-
get(target, mod) {
118-
if (!target[mod] && typeof mod === 'string') {
119-
target[mod] = (require.__$__nodeRequire ?? require)(mod);
120-
}
121-
return target[mod];
122-
}
123-
});
116+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => (require.__$__nodeRequire ?? require)(String(mod)) });
124117

125118
// VSCODE_GLOBALS: package/product.json
126119
globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)(configuration.appRoot + '/product.json');

src/main.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,7 @@ function startup(codeCachePath, nlsConfig) {
142142
process.env['VSCODE_CODE_CACHE_PATH'] = codeCachePath || '';
143143

144144
// VSCODE_GLOBALS: node_modules
145-
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), {
146-
get(target, mod) {
147-
if (!target[mod] && typeof mod === 'string') {
148-
target[mod] = require(mod);
149-
}
150-
return target[mod];
151-
}
152-
});
145+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) });
153146

154147
// VSCODE_GLOBALS: package/product.json
155148
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');

src/server-main.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,8 @@ function loadCode() {
259259
const path = require('path');
260260

261261
// VSCODE_GLOBALS: node_modules
262-
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), {
263-
get(target, mod) {
264-
if (!target[mod] && typeof mod === 'string') {
265-
target[mod] = require(mod);
266-
}
267-
return target[mod];
268-
}
269-
});
262+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) });
263+
270264
// VSCODE_GLOBALS: package/product.json
271265
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');
272266
globalThis._VSCODE_PACKAGE_JSON = require('../package.json');

test/unit/electron/renderer.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,8 @@ if (util.inspect && util.inspect['defaultOptions']) {
7373
}
7474

7575
// VSCODE_GLOBALS: node_modules
76-
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), {
77-
get(target, mod) {
78-
if (!target[mod] && typeof mod === 'string') {
79-
target[mod] = (require.__$__nodeRequire ?? require)(mod);
80-
}
81-
return target[mod];
82-
}
83-
});
76+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => (require.__$__nodeRequire ?? require)(String(mod)) });
77+
8478
// VSCODE_GLOBALS: package/product.json
8579
globalThis._VSCODE_PRODUCT_JSON = (require.__$__nodeRequire ?? require)('../../../product.json');
8680
globalThis._VSCODE_PACKAGE_JSON = (require.__$__nodeRequire ?? require)('../../../package.json');

test/unit/node/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,7 @@ if (majorRequiredNodeVersion !== currentMajorNodeVersion) {
5858
function main() {
5959

6060
// VSCODE_GLOBALS: node_modules
61-
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), {
62-
get(target, mod) {
63-
if (!target[mod] && typeof mod === 'string') {
64-
target[mod] = require(mod);
65-
}
66-
return target[mod];
67-
}
68-
});
61+
globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => require(String(mod)) });
6962

7063
// VSCODE_GLOBALS: package/product.json
7164
globalThis._VSCODE_PRODUCT_JSON = require(`${REPO_ROOT}/product.json`);

0 commit comments

Comments
 (0)