mirror of
https://github.com/Microsoft/vscode
synced 2024-10-02 09:18:59 +00:00
* add global for node_modules access
* remove most usages of require.__$__nodeRequire * stop using require.nodeRequire
This commit is contained in:
parent
e7a1278b71
commit
2d6ad4be88
11
src/bootstrap-fork.js
vendored
11
src/bootstrap-fork.js
vendored
|
@ -37,6 +37,17 @@ if (process.env['VSCODE_PARENT_PID']) {
|
|||
terminateWhenParentTerminates();
|
||||
}
|
||||
|
||||
// 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];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Load AMD entry point
|
||||
require('./bootstrap-amd').load(process.env['VSCODE_AMD_ENTRYPOINT']);
|
||||
|
||||
|
|
10
src/bootstrap-window.js
vendored
10
src/bootstrap-window.js
vendored
|
@ -112,6 +112,16 @@
|
|||
|
||||
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];
|
||||
}
|
||||
});
|
||||
|
||||
const loaderConfig = {
|
||||
baseUrl: `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out`,
|
||||
'vs/nls': nlsConfig,
|
||||
|
|
11
src/main.js
11
src/main.js
|
@ -141,6 +141,16 @@ function startup(codeCachePath, nlsConfig) {
|
|||
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(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];
|
||||
}
|
||||
});
|
||||
|
||||
// Load main in AMD
|
||||
perf.mark('code/willLoadMainBundle');
|
||||
require('./bootstrap-amd').load('vs/code/electron-main/main', () => {
|
||||
|
@ -318,6 +328,7 @@ function getArgvConfigPath() {
|
|||
dataFolderName = `${dataFolderName}-dev`;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
return path.join(os.homedir(), dataFolderName, 'argv.json');
|
||||
}
|
||||
|
||||
|
|
28
src/typings/vscode-globals.d.ts
vendored
Normal file
28
src/typings/vscode-globals.d.ts
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare global {
|
||||
|
||||
/**
|
||||
* @deprecated node modules that are in used in a context that
|
||||
* shouldn't have access to node_modules (node-free renderer or
|
||||
* shared process)
|
||||
*/
|
||||
var _VSCODE_NODE_MODULES: {
|
||||
crypto: typeof import('crypto');
|
||||
zlib: typeof import('zlib');
|
||||
net: typeof import('net');
|
||||
os: typeof import('os');
|
||||
module: typeof import('module');
|
||||
['native-watchdog']: typeof import('native-watchdog')
|
||||
perf_hooks: typeof import('perf_hooks');
|
||||
|
||||
['vsda']: any
|
||||
['vscode-encrypt']: any
|
||||
}
|
||||
}
|
||||
|
||||
// fake export to make global work
|
||||
export { }
|
|
@ -78,7 +78,7 @@
|
|||
} else if (typeof process === 'object') {
|
||||
// node.js: use the normal polyfill but add the timeOrigin
|
||||
// from the node perf_hooks API as very first mark
|
||||
const timeOrigin = Math.round((require.nodeRequire || require)('perf_hooks').performance.timeOrigin);
|
||||
const timeOrigin = Math.round((require.__$__nodeRequire || require)('perf_hooks').performance.timeOrigin);
|
||||
return _definePolyfillMarks(timeOrigin);
|
||||
|
||||
} else {
|
||||
|
|
|
@ -20,10 +20,10 @@ import { ChunkStream, Client, ISocket, Protocol, SocketCloseEvent, SocketCloseEv
|
|||
// TODO@bpasero remove me once electron utility process has landed
|
||||
function getNodeDependencies() {
|
||||
return {
|
||||
crypto: (require.__$__nodeRequire('crypto') as any) as typeof import('crypto'),
|
||||
zlib: (require.__$__nodeRequire('zlib') as any) as typeof import('zlib'),
|
||||
net: (require.__$__nodeRequire('net') as any) as typeof import('net'),
|
||||
os: (require.__$__nodeRequire('os') as any) as typeof import('os')
|
||||
crypto: globalThis._VSCODE_NODE_MODULES.crypto,
|
||||
zlib: globalThis._VSCODE_NODE_MODULES.zlib,
|
||||
net: globalThis._VSCODE_NODE_MODULES.net,
|
||||
os: globalThis._VSCODE_NODE_MODULES.os,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ flakySuite('Native Modules (all platforms)', () => {
|
|||
|
||||
test('vscode-encrypt', async () => {
|
||||
try {
|
||||
const vscodeEncrypt: Encryption = require.__$__nodeRequire('vscode-encrypt');
|
||||
const vscodeEncrypt: Encryption = globalThis._VSCODE_NODE_MODULES['vscode-encrypt'];
|
||||
const encrypted = await vscodeEncrypt.encrypt('salt', 'value');
|
||||
const decrypted = await vscodeEncrypt.decrypt('salt', encrypted);
|
||||
|
||||
|
@ -73,7 +73,7 @@ flakySuite('Native Modules (all platforms)', () => {
|
|||
|
||||
test('vsda', async () => {
|
||||
try {
|
||||
const vsda: any = require.__$__nodeRequire('vsda');
|
||||
const vsda: any = globalThis._VSCODE_NODE_MODULES['vsda'];
|
||||
const signer = new vsda.signer();
|
||||
const signed = await signer.sign('value');
|
||||
assert.ok(typeof signed === 'string', testErrorMessage('vsda'));
|
||||
|
|
|
@ -727,7 +727,7 @@ export async function createServer(address: string | net.AddressInfo | null, arg
|
|||
const hasVSDA = fs.existsSync(join(FileAccess.asFileUri('').fsPath, '../node_modules/vsda'));
|
||||
if (hasVSDA) {
|
||||
try {
|
||||
return <typeof vsda>require.__$__nodeRequire('vsda');
|
||||
return <typeof vsda>globalThis._VSCODE_NODE_MODULES['vsda'];
|
||||
} catch (err) {
|
||||
logService.error(err);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class NodeModuleRequireInterceptor extends RequireInterceptor {
|
|||
|
||||
protected _installInterceptor(): void {
|
||||
const that = this;
|
||||
const node_module = <any>require.__$__nodeRequire('module');
|
||||
const node_module = <any>globalThis._VSCODE_NODE_MODULES.module;
|
||||
const originalLoad = node_module._load;
|
||||
node_module._load = function load(request: string, parent: { filename: string }, isMain: boolean) {
|
||||
request = applyAlternatives(request);
|
||||
|
|
|
@ -81,7 +81,7 @@ const args = minimist(process.argv.slice(2), {
|
|||
// happening we essentially blocklist this module from getting loaded in any
|
||||
// extension by patching the node require() function.
|
||||
(function () {
|
||||
const Module = require.__$__nodeRequire('module') as any;
|
||||
const Module = globalThis._VSCODE_NODE_MODULES.module as any;
|
||||
const originalLoad = Module._load;
|
||||
|
||||
Module._load = function (request: string) {
|
||||
|
@ -325,7 +325,7 @@ function connectToRenderer(protocol: IMessagePassingProtocol): Promise<IRenderer
|
|||
// So also use the native node module to do it from a separate thread
|
||||
let watchdog: typeof nativeWatchdog;
|
||||
try {
|
||||
watchdog = require.__$__nodeRequire('native-watchdog');
|
||||
watchdog = globalThis._VSCODE_NODE_MODULES['native-watchdog'];
|
||||
watchdog.start(initData.parentPid);
|
||||
} catch (err) {
|
||||
// no problem...
|
||||
|
|
|
@ -97,7 +97,7 @@ const modulesCache = new Map<IExtensionDescription | undefined, { http?: typeof
|
|||
function configureModuleLoading(extensionService: ExtHostExtensionService, lookup: ReturnType<typeof createPatchedModules>): Promise<void> {
|
||||
return extensionService.getExtensionPathIndex()
|
||||
.then(extensionPaths => {
|
||||
const node_module = <any>require.__$__nodeRequire('module');
|
||||
const node_module = <any>globalThis._VSCODE_NODE_MODULES.module;
|
||||
const original = node_module._load;
|
||||
node_module._load = function load(request: string, parent: { filename: string }, isMain: boolean) {
|
||||
if (request === 'tls') {
|
||||
|
|
|
@ -72,6 +72,16 @@ if (util.inspect && util.inspect['defaultOptions']) {
|
|||
util.inspect['defaultOptions'].customInspect = false;
|
||||
}
|
||||
|
||||
// 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];
|
||||
}
|
||||
});
|
||||
|
||||
const _tests_glob = '**/test/**/*.test.js';
|
||||
let loader;
|
||||
let _out;
|
||||
|
|
Loading…
Reference in a new issue