diff --git a/src/vs/code/electron-browser/issue/issueReporter.js b/src/vs/code/electron-browser/issue/issueReporter.js index 07e8b8663d7..01d097357b0 100644 --- a/src/vs/code/electron-browser/issue/issueReporter.js +++ b/src/vs/code/electron-browser/issue/issueReporter.js @@ -146,6 +146,8 @@ function main() { // In the bundled version the nls plugin is packaged with the loader so the NLS Plugins // loads as soon as the loader loads. To be able to have pseudo translation createScript(rootUrl + '/vs/loader.js', function () { + var define = global.define; + global.define = undefined; define('fs', ['original-fs'], function (originalFS) { return originalFS; }); // replace the patched electron fs with the original node fs for all AMD code window.MonacoEnvironment = {}; diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcess.js b/src/vs/code/electron-browser/sharedProcess/sharedProcess.js index b4e968d7990..ffc640718d0 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcess.js +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcess.js @@ -131,6 +131,8 @@ function main() { // In the bundled version the nls plugin is packaged with the loader so the NLS Plugins // loads as soon as the loader loads. To be able to have pseudo translation createScript(rootUrl + '/vs/loader.js', function () { + var define = global.define; + global.define = undefined; define('fs', ['original-fs'], function (originalFS) { return originalFS; }); // replace the patched electron fs with the original node fs for all AMD code window.MonacoEnvironment = {}; diff --git a/src/vs/css.js b/src/vs/css.js index ae281dacb7b..4a2d5a4d299 100644 --- a/src/vs/css.js +++ b/src/vs/css.js @@ -20,7 +20,7 @@ var CSSLoaderPlugin; * Known issue: * - In IE there is no way to know if the CSS file loaded successfully or not. */ - var BrowserCSSLoader = (function () { + var BrowserCSSLoader = /** @class */ (function () { function BrowserCSSLoader() { this._pendingLoads = 0; } @@ -93,7 +93,7 @@ var CSSLoaderPlugin; return BrowserCSSLoader; }()); // ------------------------------ Finally, the plugin - var CSSPlugin = (function () { + var CSSPlugin = /** @class */ (function () { function CSSPlugin() { this._cssLoader = new BrowserCSSLoader(); } @@ -110,12 +110,5 @@ var CSSLoaderPlugin; return CSSPlugin; }()); CSSLoaderPlugin.CSSPlugin = CSSPlugin; - function init() { - define('vs/css', new CSSPlugin()); - } - CSSLoaderPlugin.init = init; - ; - if (typeof doNotInitLoader === 'undefined') { - init(); - } + define('vs/css', new CSSPlugin()); })(CSSLoaderPlugin || (CSSLoaderPlugin = {})); diff --git a/src/vs/loader.js b/src/vs/loader.js index aa1ae79ae5e..291f0e8b6b3 100644 --- a/src/vs/loader.js +++ b/src/vs/loader.js @@ -22,20 +22,55 @@ var _amdLoaderGlobal = this; var AMDLoader; (function (AMDLoader) { AMDLoader.global = _amdLoaderGlobal; - var Environment = (function () { - function Environment(opts) { - this.isWindows = opts.isWindows; - this.isNode = opts.isNode; - this.isElectronRenderer = opts.isElectronRenderer; - this.isWebWorker = opts.isWebWorker; + var Environment = /** @class */ (function () { + function Environment() { + this._detected = false; + this._isWindows = false; + this._isNode = false; + this._isElectronRenderer = false; + this._isWebWorker = false; } - Environment.detect = function () { - return new Environment({ - isWindows: this._isWindows(), - isNode: (typeof module !== 'undefined' && !!module.exports), - isElectronRenderer: (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions.electron !== 'undefined' && process.type === 'renderer'), - isWebWorker: (typeof AMDLoader.global.importScripts === 'function') - }); + Object.defineProperty(Environment.prototype, "isWindows", { + get: function () { + this._detect(); + return this._isWindows; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Environment.prototype, "isNode", { + get: function () { + this._detect(); + return this._isNode; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Environment.prototype, "isElectronRenderer", { + get: function () { + this._detect(); + return this._isElectronRenderer; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Environment.prototype, "isWebWorker", { + get: function () { + this._detect(); + return this._isWebWorker; + }, + enumerable: true, + configurable: true + }); + Environment.prototype._detect = function () { + if (this._detected) { + return; + } + this._detected = true; + this._isWindows = Environment._isWindows(); + this._isNode = (typeof module !== 'undefined' && !!module.exports); + this._isElectronRenderer = (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions.electron !== 'undefined' && process.type === 'renderer'); + this._isWebWorker = (typeof AMDLoader.global.importScripts === 'function'); }; Environment._isWindows = function () { if (typeof navigator !== 'undefined') { @@ -58,20 +93,7 @@ var AMDLoader; *--------------------------------------------------------------------------------------------*/ var AMDLoader; (function (AMDLoader) { - var LoaderEventType; - (function (LoaderEventType) { - LoaderEventType[LoaderEventType["LoaderAvailable"] = 1] = "LoaderAvailable"; - LoaderEventType[LoaderEventType["BeginLoadingScript"] = 10] = "BeginLoadingScript"; - LoaderEventType[LoaderEventType["EndLoadingScriptOK"] = 11] = "EndLoadingScriptOK"; - LoaderEventType[LoaderEventType["EndLoadingScriptError"] = 12] = "EndLoadingScriptError"; - LoaderEventType[LoaderEventType["BeginInvokeFactory"] = 21] = "BeginInvokeFactory"; - LoaderEventType[LoaderEventType["EndInvokeFactory"] = 22] = "EndInvokeFactory"; - LoaderEventType[LoaderEventType["NodeBeginEvaluatingScript"] = 31] = "NodeBeginEvaluatingScript"; - LoaderEventType[LoaderEventType["NodeEndEvaluatingScript"] = 32] = "NodeEndEvaluatingScript"; - LoaderEventType[LoaderEventType["NodeBeginNativeRequire"] = 33] = "NodeBeginNativeRequire"; - LoaderEventType[LoaderEventType["NodeEndNativeRequire"] = 34] = "NodeEndNativeRequire"; - })(LoaderEventType = AMDLoader.LoaderEventType || (AMDLoader.LoaderEventType = {})); - var LoaderEvent = (function () { + var LoaderEvent = /** @class */ (function () { function LoaderEvent(type, detail, timestamp) { this.type = type; this.detail = detail; @@ -80,9 +102,9 @@ var AMDLoader; return LoaderEvent; }()); AMDLoader.LoaderEvent = LoaderEvent; - var LoaderEventRecorder = (function () { + var LoaderEventRecorder = /** @class */ (function () { function LoaderEventRecorder(loaderAvailableTimestamp) { - this._events = [new LoaderEvent(LoaderEventType.LoaderAvailable, '', loaderAvailableTimestamp)]; + this._events = [new LoaderEvent(1 /* LoaderAvailable */, '', loaderAvailableTimestamp)]; } LoaderEventRecorder.prototype.record = function (type, detail) { this._events.push(new LoaderEvent(type, detail, AMDLoader.Utilities.getHighPerformanceTimestamp())); @@ -93,7 +115,7 @@ var AMDLoader; return LoaderEventRecorder; }()); AMDLoader.LoaderEventRecorder = LoaderEventRecorder; - var NullLoaderEventRecorder = (function () { + var NullLoaderEventRecorder = /** @class */ (function () { function NullLoaderEventRecorder() { } NullLoaderEventRecorder.prototype.record = function (type, detail) { @@ -102,9 +124,9 @@ var AMDLoader; NullLoaderEventRecorder.prototype.getEvents = function () { return []; }; + NullLoaderEventRecorder.INSTANCE = new NullLoaderEventRecorder(); return NullLoaderEventRecorder; }()); - NullLoaderEventRecorder.INSTANCE = new NullLoaderEventRecorder(); AMDLoader.NullLoaderEventRecorder = NullLoaderEventRecorder; })(AMDLoader || (AMDLoader = {})); /*--------------------------------------------------------------------------------------------- @@ -113,7 +135,7 @@ var AMDLoader; *--------------------------------------------------------------------------------------------*/ var AMDLoader; (function (AMDLoader) { - var Utilities = (function () { + var Utilities = /** @class */ (function () { function Utilities() { } /** @@ -199,11 +221,11 @@ var AMDLoader; } return (this.HAS_PERFORMANCE_NOW ? AMDLoader.global.performance.now() : Date.now()); }; + Utilities.NEXT_ANONYMOUS_ID = 1; + Utilities.PERFORMANCE_NOW_PROBED = false; + Utilities.HAS_PERFORMANCE_NOW = false; return Utilities; }()); - Utilities.NEXT_ANONYMOUS_ID = 1; - Utilities.PERFORMANCE_NOW_PROBED = false; - Utilities.HAS_PERFORMANCE_NOW = false; AMDLoader.Utilities = Utilities; })(AMDLoader || (AMDLoader = {})); /*--------------------------------------------------------------------------------------------- @@ -212,13 +234,13 @@ var AMDLoader; *--------------------------------------------------------------------------------------------*/ var AMDLoader; (function (AMDLoader) { - var ConfigurationOptionsUtil = (function () { + var ConfigurationOptionsUtil = /** @class */ (function () { function ConfigurationOptionsUtil() { } /** * Ensure configuration options make sense */ - ConfigurationOptionsUtil.validateConfigurationOptions = function (isWebWorker, options) { + ConfigurationOptionsUtil.validateConfigurationOptions = function (options) { function defaultOnError(err) { if (err.errorCode === 'load') { console.error('Loading "' + err.moduleId + '" failed'); @@ -253,8 +275,7 @@ var AMDLoader; options.config = {}; } if (typeof options.catchError === 'undefined') { - // Catch errors by default in web workers, do not catch errors by default in other contexts - options.catchError = isWebWorker; + options.catchError = false; } if (typeof options.urlArgs !== 'string') { options.urlArgs = ''; @@ -295,7 +316,7 @@ var AMDLoader; } return options; }; - ConfigurationOptionsUtil.mergeConfigurationOptions = function (isWebWorker, overwrite, base) { + ConfigurationOptionsUtil.mergeConfigurationOptions = function (overwrite, base) { if (overwrite === void 0) { overwrite = null; } if (base === void 0) { base = null; } var result = AMDLoader.Utilities.recursiveClone(base || {}); @@ -314,25 +335,25 @@ var AMDLoader; result[key] = AMDLoader.Utilities.recursiveClone(value); } }); - return ConfigurationOptionsUtil.validateConfigurationOptions(isWebWorker, result); + return ConfigurationOptionsUtil.validateConfigurationOptions(result); }; return ConfigurationOptionsUtil; }()); AMDLoader.ConfigurationOptionsUtil = ConfigurationOptionsUtil; - var Configuration = (function () { + var Configuration = /** @class */ (function () { function Configuration(env, options) { this._env = env; - this.options = ConfigurationOptionsUtil.mergeConfigurationOptions(this._env.isWebWorker, options); + this.options = ConfigurationOptionsUtil.mergeConfigurationOptions(options); this._createIgnoreDuplicateModulesMap(); this._createNodeModulesMap(); this._createSortedPathsRules(); if (this.options.baseUrl === '') { - if (this._env.isNode && this.options.nodeRequire && this.options.nodeRequire.main && this.options.nodeRequire.main.filename) { + if (this.options.nodeRequire && this.options.nodeRequire.main && this.options.nodeRequire.main.filename && this._env.isNode) { var nodeMain = this.options.nodeRequire.main.filename; var dirnameIndex = Math.max(nodeMain.lastIndexOf('/'), nodeMain.lastIndexOf('\\')); this.options.baseUrl = nodeMain.substring(0, dirnameIndex + 1); } - if (this._env.isNode && this.options.nodeMain) { + if (this.options.nodeMain && this._env.isNode) { var nodeMain = this.options.nodeMain; var dirnameIndex = Math.max(nodeMain.lastIndexOf('/'), nodeMain.lastIndexOf('\\')); this.options.baseUrl = nodeMain.substring(0, dirnameIndex + 1); @@ -383,7 +404,7 @@ var AMDLoader; * @result A new configuration */ Configuration.prototype.cloneAndMerge = function (options) { - return new Configuration(this._env, ConfigurationOptionsUtil.mergeConfigurationOptions(this._env.isWebWorker, options, this.options)); + return new Configuration(this._env, ConfigurationOptionsUtil.mergeConfigurationOptions(options, this.options)); }; /** * Get current options bag. Useful for passing it forward to plugins. @@ -530,41 +551,49 @@ var AMDLoader; /** * Load `scriptSrc` only once (avoid multiple