diff --git a/src/bootstrap-window.js b/src/bootstrap-window.js index 963337bd873..d5c0091a504 100644 --- a/src/bootstrap-window.js +++ b/src/bootstrap-window.js @@ -3,6 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +/// + //@ts-check 'use strict'; @@ -19,10 +21,10 @@ globalThis.MonacoBootstrapWindow = factory(); } }(this, function () { - const path = require('path'); - const webFrame = require('electron').webFrame; - const ipc = require('electron').ipcRenderer; - const bootstrap = globalThis.MonacoBootstrap || require('./bootstrap'); + const path = require.__$__nodeRequire('path'); + const webFrame = require.__$__nodeRequire('electron').webFrame; + const ipc = require.__$__nodeRequire('electron').ipcRenderer; + const bootstrap = globalThis.MonacoBootstrap; /** * @param {string[]} modulePaths @@ -83,17 +85,11 @@ window.document.documentElement.setAttribute('lang', locale); - // Load the loader - const amdLoader = require(`${configuration.appRoot}/out/vs/loader.js`); - const amdRequire = amdLoader.require; - const amdDefine = amdLoader.require.define; - const nodeRequire = amdLoader.require.nodeRequire; - - window['nodeRequire'] = nodeRequire; - window['require'] = amdRequire; + // do not advertise AMD to avoid confusing UMD modules loaded with nodejs + window['define'] = undefined; // replace the patched electron fs with the original node fs for all AMD code - amdDefine('fs', ['original-fs'], function (originalFS) { return originalFS; }); + require.define('fs', ['original-fs'], function (originalFS) { return originalFS; }); window['MonacoEnvironment'] = {}; @@ -115,10 +111,10 @@ options.beforeLoaderConfig(configuration, loaderConfig); } - amdRequire.config(loaderConfig); + require.config(loaderConfig); if (nlsConfig.pseudo) { - amdRequire(['vs/nls'], function (nlsPlugin) { + require(['vs/nls'], function (nlsPlugin) { nlsPlugin.setPseudoTranslation(nlsConfig.pseudo); }); } @@ -127,7 +123,7 @@ options.beforeRequire(); } - amdRequire(modulePaths, result => { + require(modulePaths, result => { try { const callbackResult = resultCallback(result, configuration); if (callbackResult && typeof callbackResult.then === 'function') { @@ -199,7 +195,7 @@ /** * @param {string | Error} error - * @param {boolean} enableDeveloperTools + * @param {boolean} [enableDeveloperTools] */ function onUnexpectedError(error, enableDeveloperTools) { if (enableDeveloperTools) { diff --git a/src/typings/require.d.ts b/src/typings/require.d.ts index dfffac43e56..cc4a4043ce1 100644 --- a/src/typings/require.d.ts +++ b/src/typings/require.d.ts @@ -47,6 +47,7 @@ interface NodeRequire { onError: Function; __$__nodeRequire(moduleName: string): T; getStats(): ReadonlyArray; + define(amdModuleId: string, dependencies: string[], callback: (...args: any[]) => any): any; } declare var require: NodeRequire; diff --git a/src/vs/code/electron-browser/issue/issueReporter.html b/src/vs/code/electron-browser/issue/issueReporter.html index f1509aa0dc5..3a0cb4be742 100644 --- a/src/vs/code/electron-browser/issue/issueReporter.html +++ b/src/vs/code/electron-browser/issue/issueReporter.html @@ -15,6 +15,7 @@ + diff --git a/src/vs/code/electron-browser/processExplorer/processExplorer.html b/src/vs/code/electron-browser/processExplorer/processExplorer.html index 0b7304cfd96..517805abdb7 100644 --- a/src/vs/code/electron-browser/processExplorer/processExplorer.html +++ b/src/vs/code/electron-browser/processExplorer/processExplorer.html @@ -11,6 +11,7 @@ + diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcess.html b/src/vs/code/electron-browser/sharedProcess/sharedProcess.html index 26890a9fc6b..07fd9bd0478 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcess.html +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcess.html @@ -11,7 +11,12 @@ Shared Process + + + + + - \ No newline at end of file + diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcess.js b/src/vs/code/electron-browser/sharedProcess/sharedProcess.js index 2ecd5f650a8..54815a8ed1b 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcess.js +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcess.js @@ -6,8 +6,21 @@ //@ts-check 'use strict'; -const bootstrap = require('../../../../bootstrap'); -const bootstrapWindow = require('../../../../bootstrap-window'); +/** + * @type {{ load: (modules: string[], resultCallback: (result, configuration: object) => any, options?: object) => unknown }} + */ +const bootstrapWindow = (() => { + // @ts-ignore (defined in bootstrap-window.js) + return window.MonacoBootstrapWindow; +})(); + +/** + * @type {{ avoidMonkeyPatchFromAppInsights: () => void; }} + */ +const bootstrap = (() => { + // @ts-ignore (defined in bootstrap.js) + return window.MonacoBootstrap; +})(); // Avoid Monkey Patches from Application Insights bootstrap.avoidMonkeyPatchFromAppInsights(); diff --git a/src/vs/code/electron-browser/workbench/workbench.html b/src/vs/code/electron-browser/workbench/workbench.html index c0564e21ba0..2ed6c9c67c7 100644 --- a/src/vs/code/electron-browser/workbench/workbench.html +++ b/src/vs/code/electron-browser/workbench/workbench.html @@ -10,6 +10,7 @@ + diff --git a/src/vs/code/electron-browser/workbench/workbench.js b/src/vs/code/electron-browser/workbench/workbench.js index f1a31a5e847..3c45d384f50 100644 --- a/src/vs/code/electron-browser/workbench/workbench.js +++ b/src/vs/code/electron-browser/workbench/workbench.js @@ -3,6 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +/// + //@ts-check 'use strict'; @@ -91,7 +93,7 @@ function showPartsSplash(configuration) { let data; if (typeof configuration.partsSplashPath === 'string') { try { - data = JSON.parse(require('fs').readFileSync(configuration.partsSplashPath, 'utf8')); + data = JSON.parse(require.__$__nodeRequire('fs').readFileSync(configuration.partsSplashPath, 'utf8')); } catch (e) { // ignore } @@ -180,7 +182,7 @@ function showPartsSplash(configuration) { */ function getLazyEnv() { - const ipc = require('electron').ipcRenderer; + const ipc = require.__$__nodeRequire('electron').ipcRenderer; return new Promise(function (resolve) { const handle = setTimeout(function () {