Skip to content

Commit f3b191a

Browse files
author
Benjamin Pasero
committed
@ts-check for bootstrap JS files
1 parent 007fe79 commit f3b191a

11 files changed

Lines changed: 195 additions & 31 deletions

File tree

src/bootstrap-amd.js

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

6+
//@ts-check
7+
'use strict';
8+
69
const loader = require('./vs/loader');
710
const bootstrap = require('./bootstrap');
811

@@ -20,7 +23,7 @@ loader.config({
2023
});
2124

2225
// Running in Electron
23-
if (process.env['ELECTRON_RUN_AS_NODE'] || process.versions.electron) {
26+
if (process.env['ELECTRON_RUN_AS_NODE'] || process.versions['electron']) {
2427
loader.define('fs', ['original-fs'], function (originalFS) {
2528
return originalFS; // replace the patched electron fs with the original node fs for all AMD code
2629
});

src/bootstrap-fork.js

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

6+
//@ts-check
7+
'use strict';
8+
69
const bootstrap = require('./bootstrap');
710

811
// Enable ASAR in our forked processes
@@ -143,19 +146,21 @@ function disableSTDIO() {
143146
write: function () { /* No OP */ }
144147
});
145148

146-
process.__defineGetter__('stdout', function () { return writable; });
147-
process.__defineGetter__('stderr', function () { return writable; });
148-
process.__defineGetter__('stdin', function () { return writable; });
149+
process['__defineGetter__']('stdout', function () { return writable; });
150+
process['__defineGetter__']('stderr', function () { return writable; });
151+
process['__defineGetter__']('stdin', function () { return writable; });
149152
}
150153

151154
function handleExceptions() {
152155

153156
// Handle uncaught exceptions
157+
// @ts-ignore
154158
process.on('uncaughtException', function (err) {
155159
console.error('Uncaught Exception: ', err);
156160
});
157161

158162
// Handle unhandled promise rejections
163+
// @ts-ignore
159164
process.on('unhandledRejection', function (reason) {
160165
console.error('Unhandled Promise Rejection: ', reason);
161166
});
@@ -181,7 +186,7 @@ function configureCrashReporter() {
181186
try {
182187
const crashReporterOptions = JSON.parse(crashReporterOptionsRaw);
183188
if (crashReporterOptions) {
184-
process.crashReporter.start(crashReporterOptions);
189+
process['crashReporter'].start(crashReporterOptions);
185190
}
186191
} catch (error) {
187192
console.error(error);

src/bootstrap-window.js

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

6+
//@ts-check
7+
'use strict';
8+
69
const bootstrap = require('./bootstrap');
710

811
exports.parseURLQueryArgs = function () {
@@ -15,17 +18,30 @@ exports.parseURLQueryArgs = function () {
1518
.reduce(function (r, param) { r[param[0]] = decodeURIComponent(param[1]); return r; }, {});
1619
};
1720

18-
exports.assign = function (destination, source) {
21+
/**
22+
* @param {object} destination
23+
* @param {object} source
24+
* @returns {object}
25+
*/
26+
exports.assign = function assign(destination, source) {
1927
return Object.keys(source).reduce(function (r, key) { r[key] = source[key]; return r; }, destination);
2028
};
2129

30+
/**
31+
*
32+
* @param {string[]} modulePaths
33+
* @param {(result, configuration) => any} resultCallback
34+
* @param {{ removeDeveloperKeybindingsAfterLoad: boolean, canModifyDOM: (config) => void, beforeLoaderConfig: (config, loaderConfig) => void, beforeRequire: () => void }=} options
35+
*/
2236
exports.load = function (modulePaths, resultCallback, options) {
37+
// @ts-ignore
2338
const webFrame = require('electron').webFrame;
2439

2540
const args = exports.parseURLQueryArgs();
2641
const configuration = JSON.parse(args['config'] || '{}') || {};
2742

2843
// Error handler
44+
// @ts-ignore
2945
process.on('uncaughtException', function (error) { onUnexpectedError(error, enableDeveloperTools); });
3046

3147
// Developer tools
@@ -70,13 +86,13 @@ exports.load = function (modulePaths, resultCallback, options) {
7086
const amdDefine = amdLoader.require.define;
7187
const nodeRequire = amdLoader.require.nodeRequire;
7288

73-
window.nodeRequire = nodeRequire;
74-
window.require = amdRequire;
89+
window['nodeRequire'] = nodeRequire;
90+
window['require'] = amdRequire;
7591

7692
// replace the patched electron fs with the original node fs for all AMD code
7793
amdDefine('fs', ['original-fs'], function (originalFS) { return originalFS; });
7894

79-
window.MonacoEnvironment = {};
95+
window['MonacoEnvironment'] = {};
8096

8197
const loaderConfig = {
8298
baseUrl: bootstrap.uriFromPath(configuration.appRoot) + '/out',
@@ -119,7 +135,11 @@ exports.load = function (modulePaths, resultCallback, options) {
119135
});
120136
};
121137

138+
/**
139+
* @returns () => void
140+
*/
122141
function registerDeveloperKeybindings() {
142+
// @ts-ignore
123143
const ipc = require('electron').ipcRenderer;
124144

125145
const extractKey = function (e) {
@@ -156,6 +176,7 @@ function registerDeveloperKeybindings() {
156176
}
157177

158178
function onUnexpectedError(error, enableDeveloperTools) {
179+
// @ts-ignore
159180
const ipc = require('electron').ipcRenderer;
160181

161182
if (enableDeveloperTools) {

src/bootstrap.js

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

6+
//@ts-check
7+
'use strict';
8+
69
//#region global bootstrapping
710

811
// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
912
Error.stackTraceLimit = 100;
1013

1114
// Workaround for Electron not installing a handler to ignore SIGPIPE
1215
// (https://github.com/electron/electron/issues/13254)
16+
// @ts-ignore
1317
process.on('SIGPIPE', () => {
1418
console.error(new Error('Unexpected SIGPIPE'));
1519
});
@@ -18,8 +22,9 @@ process.on('SIGPIPE', () => {
1822

1923
//#region Add support for using node_modules.asar
2024
exports.enableASARSupport = function () {
21-
const path = require('path');
25+
// @ts-ignore
2226
const Module = require('module');
27+
const path = require('path');
2328

2429
let NODE_MODULES_PATH = path.join(__dirname, '../node_modules');
2530
if (process.platform === 'win32' && /[a-z]\:/.test(NODE_MODULES_PATH)) {
@@ -46,6 +51,10 @@ exports.enableASARSupport = function () {
4651
//#endregion
4752

4853
//#region URI helpers
54+
/**
55+
* @param {string} _path
56+
* @returns {string}
57+
*/
4958
exports.uriFromPath = function (_path) {
5059
const path = require('path');
5160

@@ -59,6 +68,10 @@ exports.uriFromPath = function (_path) {
5968
//#endregion
6069

6170
//#region FS helpers
71+
/**
72+
* @param {string} file
73+
* @returns {Promise}
74+
*/
6275
exports.readFile = function (file) {
6376
const fs = require('fs');
6477

@@ -73,6 +86,11 @@ exports.readFile = function (file) {
7386
});
7487
};
7588

89+
/**
90+
* @param {string} file
91+
* @param {string} content
92+
* @returns {Promise}
93+
*/
7694
exports.writeFile = function (file, content) {
7795
const fs = require('fs');
7896

@@ -136,10 +154,14 @@ exports.setupNLS = function () {
136154
//#endregion
137155

138156
//#region Portable helpers
157+
/**
158+
* @returns {{ portableDataPath: string, isPortable: boolean }}
159+
*/
139160
exports.configurePortable = function () {
161+
// @ts-ignore
162+
const product = require('../product.json');
140163
const path = require('path');
141164
const fs = require('fs');
142-
const product = require('../product.json');
143165

144166
const appRoot = path.dirname(__dirname);
145167

src/cli.js

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

6+
//@ts-check
7+
'use strict';
8+
69
const bootstrap = require('./bootstrap');
710

811
// Enable portable support

0 commit comments

Comments
 (0)