Skip to content

Commit 4deff1a

Browse files
committed
Load loader.js via a <script> tag
1 parent 118e912 commit 4deff1a

8 files changed

Lines changed: 42 additions & 22 deletions

File tree

src/bootstrap-window.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/// <reference path="typings/require.d.ts" />
7+
68
//@ts-check
79
'use strict';
810

@@ -19,10 +21,10 @@
1921
globalThis.MonacoBootstrapWindow = factory();
2022
}
2123
}(this, function () {
22-
const path = require('path');
23-
const webFrame = require('electron').webFrame;
24-
const ipc = require('electron').ipcRenderer;
25-
const bootstrap = globalThis.MonacoBootstrap || require('./bootstrap');
24+
const path = require.__$__nodeRequire('path');
25+
const webFrame = require.__$__nodeRequire('electron').webFrame;
26+
const ipc = require.__$__nodeRequire('electron').ipcRenderer;
27+
const bootstrap = globalThis.MonacoBootstrap;
2628

2729
/**
2830
* @param {string[]} modulePaths
@@ -83,17 +85,11 @@
8385

8486
window.document.documentElement.setAttribute('lang', locale);
8587

86-
// Load the loader
87-
const amdLoader = require(`${configuration.appRoot}/out/vs/loader.js`);
88-
const amdRequire = amdLoader.require;
89-
const amdDefine = amdLoader.require.define;
90-
const nodeRequire = amdLoader.require.nodeRequire;
91-
92-
window['nodeRequire'] = nodeRequire;
93-
window['require'] = amdRequire;
88+
// do not advertise AMD to avoid confusing UMD modules loaded with nodejs
89+
window['define'] = undefined;
9490

9591
// replace the patched electron fs with the original node fs for all AMD code
96-
amdDefine('fs', ['original-fs'], function (originalFS) { return originalFS; });
92+
require.define('fs', ['original-fs'], function (originalFS) { return originalFS; });
9793

9894
window['MonacoEnvironment'] = {};
9995

@@ -115,10 +111,10 @@
115111
options.beforeLoaderConfig(configuration, loaderConfig);
116112
}
117113

118-
amdRequire.config(loaderConfig);
114+
require.config(loaderConfig);
119115

120116
if (nlsConfig.pseudo) {
121-
amdRequire(['vs/nls'], function (nlsPlugin) {
117+
require(['vs/nls'], function (nlsPlugin) {
122118
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo);
123119
});
124120
}
@@ -127,7 +123,7 @@
127123
options.beforeRequire();
128124
}
129125

130-
amdRequire(modulePaths, result => {
126+
require(modulePaths, result => {
131127
try {
132128
const callbackResult = resultCallback(result, configuration);
133129
if (callbackResult && typeof callbackResult.then === 'function') {
@@ -199,7 +195,7 @@
199195

200196
/**
201197
* @param {string | Error} error
202-
* @param {boolean} enableDeveloperTools
198+
* @param {boolean} [enableDeveloperTools]
203199
*/
204200
function onUnexpectedError(error, enableDeveloperTools) {
205201
if (enableDeveloperTools) {

src/typings/require.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface NodeRequire {
4747
onError: Function;
4848
__$__nodeRequire<T>(moduleName: string): T;
4949
getStats(): ReadonlyArray<LoaderEvent>;
50+
define(amdModuleId: string, dependencies: string[], callback: (...args: any[]) => any): any;
5051
}
5152

5253
declare var require: NodeRequire;

src/vs/code/electron-browser/issue/issueReporter.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<!-- Init Bootstrap Helpers -->
1717
<script src="../../../../bootstrap.js"></script>
18+
<script src="../../../../vs/loader.js"></script>
1819
<script src="../../../../bootstrap-window.js"></script>
1920

2021
<!-- Startup via issueReporter.js -->

src/vs/code/electron-browser/processExplorer/processExplorer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<!-- Init Bootstrap Helpers -->
1313
<script src="../../../../bootstrap.js"></script>
14+
<script src="../../../../vs/loader.js"></script>
1415
<script src="../../../../bootstrap-window.js"></script>
1516

1617
<!-- Startup via processExplorer.js -->

src/vs/code/electron-browser/sharedProcess/sharedProcess.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
Shared Process
1212
</body>
1313

14+
<!-- Init Bootstrap Helpers -->
15+
<script src="../../../../bootstrap.js"></script>
16+
<script src="../../../../vs/loader.js"></script>
17+
<script src="../../../../bootstrap-window.js"></script>
18+
1419
<!-- Startup via sharedProcess.js -->
1520
<script src="sharedProcess.js"></script>
1621

17-
</html>
22+
</html>

src/vs/code/electron-browser/sharedProcess/sharedProcess.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,21 @@
66
//@ts-check
77
'use strict';
88

9-
const bootstrap = require('../../../../bootstrap');
10-
const bootstrapWindow = require('../../../../bootstrap-window');
9+
/**
10+
* @type {{ load: (modules: string[], resultCallback: (result, configuration: object) => any, options?: object) => unknown }}
11+
*/
12+
const bootstrapWindow = (() => {
13+
// @ts-ignore (defined in bootstrap-window.js)
14+
return window.MonacoBootstrapWindow;
15+
})();
16+
17+
/**
18+
* @type {{ avoidMonkeyPatchFromAppInsights: () => void; }}
19+
*/
20+
const bootstrap = (() => {
21+
// @ts-ignore (defined in bootstrap.js)
22+
return window.MonacoBootstrap;
23+
})();
1124

1225
// Avoid Monkey Patches from Application Insights
1326
bootstrap.avoidMonkeyPatchFromAppInsights();

src/vs/code/electron-browser/workbench/workbench.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<!-- Init Bootstrap Helpers -->
1212
<script src="../../../../bootstrap.js"></script>
13+
<script src="../../../../vs/loader.js"></script>
1314
<script src="../../../../bootstrap-window.js"></script>
1415

1516
<!-- Startup via workbench.js -->

src/vs/code/electron-browser/workbench/workbench.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
/// <reference path="../../../../typings/require.d.ts" />
7+
68
//@ts-check
79
'use strict';
810

@@ -91,7 +93,7 @@ function showPartsSplash(configuration) {
9193
let data;
9294
if (typeof configuration.partsSplashPath === 'string') {
9395
try {
94-
data = JSON.parse(require('fs').readFileSync(configuration.partsSplashPath, 'utf8'));
96+
data = JSON.parse(require.__$__nodeRequire('fs').readFileSync(configuration.partsSplashPath, 'utf8'));
9597
} catch (e) {
9698
// ignore
9799
}
@@ -180,7 +182,7 @@ function showPartsSplash(configuration) {
180182
*/
181183
function getLazyEnv() {
182184

183-
const ipc = require('electron').ipcRenderer;
185+
const ipc = require.__$__nodeRequire('electron').ipcRenderer;
184186

185187
return new Promise(function (resolve) {
186188
const handle = setTimeout(function () {

0 commit comments

Comments
 (0)