Skip to content

Commit 0496e9c

Browse files
committed
esm - convert bootstrap files to TS (part 2)
1 parent 5fcebed commit 0496e9c

6 files changed

+28
-80
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@
11331133
"restrictions": []
11341134
},
11351135
{
1136-
"target": "src/{bootstrap-cli.ts,bootstrap-esm.ts,bootstrap-fork.ts,bootstrap-node.js,bootstrap-window.js,cli.js,main.js,server-cli.js,server-main.js,bootstrap-cli.js,bootstrap-server.js}",
1136+
"target": "src/{bootstrap-cli.ts,bootstrap-esm.ts,bootstrap-fork.ts,bootstrap-node.ts,bootstrap-import.ts,bootstrap-meta.ts,bootstrap-window.js,cli.js,main.js,server-cli.js,server-main.js,bootstrap-cli.js,bootstrap-server.js}",
11371137
"restrictions": []
11381138
}
11391139
]

src/bootstrap-fork.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ function configureCrashReporter(): void {
215215
const crashReporterProcessType = process.env['VSCODE_CRASH_REPORTER_PROCESS_TYPE'];
216216
if (crashReporterProcessType) {
217217
try {
218-
// @ts-ignore
218+
//@ts-ignore
219219
if (process['crashReporter'] && typeof process['crashReporter'].addExtraParameter === 'function' /* Electron only */) {
220-
// @ts-ignore
220+
//@ts-ignore
221221
process['crashReporter'].addExtraParameter('processType', crashReporterProcessType);
222222
}
223223
} catch (error) {

src/bootstrap-import.js renamed to src/bootstrap-import.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
//@ts-check
6+
/* eslint-disable local/code-import-patterns */
77

88
// *********************************************************************
99
// * *
@@ -18,15 +18,9 @@ import { join } from 'node:path';
1818

1919
// SEE https://nodejs.org/docs/latest/api/module.html#initialize
2020

21-
/**
22-
* @type {Object.<string, string>}
23-
*/
24-
const _specifierToUrl = {};
21+
const _specifierToUrl: Record<string, string> = {};
2522

26-
/**
27-
* @param {string} injectPath
28-
*/
29-
export async function initialize(injectPath) {
23+
export async function initialize(injectPath: string): Promise<void> {
3024
// populate mappings
3125

3226
const injectPackageJSONPath = fileURLToPath(new URL('../package.json', pathToFileURL(injectPath)));
@@ -55,16 +49,10 @@ export async function initialize(injectPath) {
5549
console.log(`[bootstrap-import] Initialized node_modules redirector for: ${injectPath}`);
5650
}
5751

58-
/**
59-
* @param {string | number} specifier
60-
* @param {any} context
61-
* @param {(arg0: any, arg1: any) => any} nextResolve
62-
*/
63-
export async function resolve(specifier, context, nextResolve) {
52+
export async function resolve(specifier: string | number, context: any, nextResolve: (arg0: any, arg1: any) => any) {
6453

6554
const newSpecifier = _specifierToUrl[specifier];
6655
if (newSpecifier !== undefined) {
67-
// console.log('[HOOKS]', specifier, '--->', newSpecifier);
6856
return {
6957
format: 'commonjs',
7058
shortCircuit: true,

src/bootstrap-meta.js renamed to src/bootstrap-meta.ts

+5-18
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,22 @@
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-
9-
/**
10-
* @import { IProductConfiguration } from './vs/base/common/product'
11-
*/
6+
/* eslint-disable local/code-import-patterns */
127

138
import { createRequire } from 'node:module';
9+
import { IProductConfiguration } from './vs/base/common/product.js';
1410

1511
const require = createRequire(import.meta.url);
16-
/** @type any */
17-
const module = { exports: {} };
1812

19-
/** @type Partial<IProductConfiguration> & { BUILD_INSERT_PRODUCT_CONFIGURATION?: string } */
20-
let productObj = { BUILD_INSERT_PRODUCT_CONFIGURATION: 'BUILD_INSERT_PRODUCT_CONFIGURATION' }; // DO NOT MODIFY, PATCHED DURING BUILD
13+
let productObj: Partial<IProductConfiguration> & { BUILD_INSERT_PRODUCT_CONFIGURATION?: string } = { BUILD_INSERT_PRODUCT_CONFIGURATION: 'BUILD_INSERT_PRODUCT_CONFIGURATION' }; // DO NOT MODIFY, PATCHED DURING BUILD
2114
if (productObj['BUILD_INSERT_PRODUCT_CONFIGURATION']) {
22-
// @ts-ignore
2315
productObj = require('../product.json'); // Running out of sources
2416
}
2517

26-
/** @type object & { BUILD_INSERT_PACKAGE_CONFIGURATION?: string } */
2718
let pkgObj = { BUILD_INSERT_PACKAGE_CONFIGURATION: 'BUILD_INSERT_PACKAGE_CONFIGURATION' }; // DO NOT MODIFY, PATCHED DURING BUILD
2819
if (pkgObj['BUILD_INSERT_PACKAGE_CONFIGURATION']) {
29-
// @ts-ignore
3020
pkgObj = require('../package.json'); // Running out of sources
3121
}
3222

33-
module.exports.product = productObj;
34-
module.exports.pkg = pkgObj;
35-
36-
export const product = module.exports.product;
37-
export const pkg = module.exports.pkg;
23+
export const product = productObj;
24+
export const pkg = pkgObj;

src/bootstrap-node.js renamed to src/bootstrap-node.ts

+16-40
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
//@ts-check
7-
'use strict';
6+
/* eslint-disable local/code-import-patterns */
87

98
import * as path from 'path';
109
import * as fs from 'fs';
1110
import { fileURLToPath } from 'url';
1211
import { createRequire } from 'node:module';
12+
import { IProductConfiguration } from './vs/base/common/product';
1313

14-
/** @ts-ignore */
1514
const require = createRequire(import.meta.url);
16-
/** @type any */
17-
const module = { exports: {} };
1815
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1916

2017
// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
@@ -38,7 +35,7 @@ if (!process.env['VSCODE_HANDLES_SIGPIPE']) {
3835
// Setup current working directory in all our node & electron processes
3936
// - Windows: call `process.chdir()` to always set application folder as cwd
4037
// - all OS: store the `process.cwd()` inside `VSCODE_CWD` for consistent lookups
41-
function setupCurrentWorkingDirectory() {
38+
function setupCurrentWorkingDirectory(): void {
4239
try {
4340

4441
// Store the `process.cwd()` inside `VSCODE_CWD`
@@ -64,10 +61,8 @@ setupCurrentWorkingDirectory();
6461
* Add support for redirecting the loading of node modules
6562
*
6663
* Note: only applies when running out of sources.
67-
*
68-
* @param {string} injectPath
6964
*/
70-
module.exports.devInjectNodeModuleLookupPath = function (injectPath) {
65+
export function devInjectNodeModuleLookupPath(injectPath: string): void {
7166
if (!process.env['VSCODE_DEV']) {
7267
return; // only applies running out of sources
7368
}
@@ -76,25 +71,22 @@ module.exports.devInjectNodeModuleLookupPath = function (injectPath) {
7671
throw new Error('Missing injectPath');
7772
}
7873

79-
const Module = require('node:module');
8074
// register a loader hook
75+
const Module = require('node:module');
8176
Module.register('./bootstrap-import.js', { parentURL: import.meta.url, data: injectPath });
82-
};
77+
}
8378

84-
module.exports.removeGlobalNodeJsModuleLookupPaths = function () {
79+
export function removeGlobalNodeJsModuleLookupPaths(): void {
8580
if (typeof process?.versions?.electron === 'string') {
8681
return; // Electron disables global search paths in https://github.com/electron/electron/blob/3186c2f0efa92d275dc3d57b5a14a60ed3846b0e/shell/common/node_bindings.cc#L653
8782
}
8883

8984
const Module = require('module');
90-
// @ts-ignore
9185
const globalPaths = Module.globalPaths;
9286

93-
// @ts-ignore
9487
const originalResolveLookupPaths = Module._resolveLookupPaths;
9588

96-
// @ts-ignore
97-
Module._resolveLookupPaths = function (moduleName, parent) {
89+
Module._resolveLookupPaths = function (moduleName: string, parent: any): string[] {
9890
const paths = originalResolveLookupPaths(moduleName, parent);
9991
if (Array.isArray(paths)) {
10092
let commonSuffixLength = 0;
@@ -105,21 +97,15 @@ module.exports.removeGlobalNodeJsModuleLookupPaths = function () {
10597
}
10698
return paths;
10799
};
108-
};
100+
}
109101

110102
/**
111103
* Helper to enable portable mode.
112-
*
113-
* @param {Partial<import('./vs/base/common/product').IProductConfiguration>} product
114-
* @returns {{ portableDataPath: string; isPortable: boolean; }}
115104
*/
116-
module.exports.configurePortable = function (product) {
105+
export function configurePortable(product: Partial<IProductConfiguration>): { portableDataPath: string; isPortable: boolean } {
117106
const appRoot = path.dirname(__dirname);
118107

119-
/**
120-
* @param {import('path')} path
121-
*/
122-
function getApplicationPath(path) {
108+
function getApplicationPath() {
123109
if (process.env['VSCODE_DEV']) {
124110
return appRoot;
125111
}
@@ -131,24 +117,20 @@ module.exports.configurePortable = function (product) {
131117
return path.dirname(path.dirname(appRoot));
132118
}
133119

134-
/**
135-
* @param {import('path')} path
136-
*/
137-
function getPortableDataPath(path) {
120+
function getPortableDataPath() {
138121
if (process.env['VSCODE_PORTABLE']) {
139122
return process.env['VSCODE_PORTABLE'];
140123
}
141124

142125
if (process.platform === 'win32' || process.platform === 'linux') {
143-
return path.join(getApplicationPath(path), 'data');
126+
return path.join(getApplicationPath(), 'data');
144127
}
145128

146-
// @ts-ignore
147129
const portableDataName = product.portable || `${product.applicationName}-portable-data`;
148-
return path.join(path.dirname(getApplicationPath(path)), portableDataName);
130+
return path.join(path.dirname(getApplicationPath()), portableDataName);
149131
}
150132

151-
const portableDataPath = getPortableDataPath(path);
133+
const portableDataPath = getPortableDataPath();
152134
const isPortable = !('target' in product) && fs.existsSync(portableDataPath);
153135
const portableTempPath = path.join(portableDataPath, 'tmp');
154136
const isTempPortable = isPortable && fs.existsSync(portableTempPath);
@@ -172,10 +154,4 @@ module.exports.configurePortable = function (product) {
172154
portableDataPath,
173155
isPortable
174156
};
175-
};
176-
177-
//#endregion
178-
179-
export const devInjectNodeModuleLookupPath = module.exports.devInjectNodeModuleLookupPath;
180-
export const removeGlobalNodeJsModuleLookupPaths = module.exports.removeGlobalNodeJsModuleLookupPaths;
181-
export const configurePortable = module.exports.configurePortable;
157+
}

src/tsconfig.json

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
]
2727
},
2828
"include": [
29-
"./bootstrap-import.js",
30-
"./bootstrap-meta.js",
31-
"./bootstrap-node.js",
3229
"./bootstrap-server.js",
3330
"./bootstrap-window.js",
3431
"./cli.js",

0 commit comments

Comments
 (0)