diff --git a/.eslintrc.json b/.eslintrc.json index fbbd1fd8b3d..28694da3ae7 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1133,7 +1133,7 @@ "restrictions": [] }, { - "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}", + "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}", "restrictions": [] } ] diff --git a/src/bootstrap-fork.ts b/src/bootstrap-fork.ts index eb77e0bf8b6..094fe16dc34 100644 --- a/src/bootstrap-fork.ts +++ b/src/bootstrap-fork.ts @@ -215,9 +215,9 @@ function configureCrashReporter(): void { const crashReporterProcessType = process.env['VSCODE_CRASH_REPORTER_PROCESS_TYPE']; if (crashReporterProcessType) { try { - // @ts-ignore + //@ts-ignore if (process['crashReporter'] && typeof process['crashReporter'].addExtraParameter === 'function' /* Electron only */) { - // @ts-ignore + //@ts-ignore process['crashReporter'].addExtraParameter('processType', crashReporterProcessType); } } catch (error) { diff --git a/src/bootstrap-import.js b/src/bootstrap-import.ts similarity index 83% rename from src/bootstrap-import.js rename to src/bootstrap-import.ts index 070b0b93b4b..c280170efb9 100644 --- a/src/bootstrap-import.js +++ b/src/bootstrap-import.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -//@ts-check +/* eslint-disable local/code-import-patterns */ // ********************************************************************* // * * @@ -18,15 +18,9 @@ import { join } from 'node:path'; // SEE https://nodejs.org/docs/latest/api/module.html#initialize -/** - * @type {Object.} - */ -const _specifierToUrl = {}; +const _specifierToUrl: Record = {}; -/** - * @param {string} injectPath - */ -export async function initialize(injectPath) { +export async function initialize(injectPath: string): Promise { // populate mappings const injectPackageJSONPath = fileURLToPath(new URL('../package.json', pathToFileURL(injectPath))); @@ -55,16 +49,10 @@ export async function initialize(injectPath) { console.log(`[bootstrap-import] Initialized node_modules redirector for: ${injectPath}`); } -/** - * @param {string | number} specifier - * @param {any} context - * @param {(arg0: any, arg1: any) => any} nextResolve - */ -export async function resolve(specifier, context, nextResolve) { +export async function resolve(specifier: string | number, context: any, nextResolve: (arg0: any, arg1: any) => any) { const newSpecifier = _specifierToUrl[specifier]; if (newSpecifier !== undefined) { - // console.log('[HOOKS]', specifier, '--->', newSpecifier); return { format: 'commonjs', shortCircuit: true, diff --git a/src/bootstrap-meta.js b/src/bootstrap-meta.ts similarity index 56% rename from src/bootstrap-meta.js rename to src/bootstrap-meta.ts index de52000bb70..b8a163d277e 100644 --- a/src/bootstrap-meta.js +++ b/src/bootstrap-meta.ts @@ -3,35 +3,22 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -//@ts-check -'use strict'; - -/** - * @import { IProductConfiguration } from './vs/base/common/product' - */ +/* eslint-disable local/code-import-patterns */ import { createRequire } from 'node:module'; +import { IProductConfiguration } from './vs/base/common/product.js'; const require = createRequire(import.meta.url); -/** @type any */ -const module = { exports: {} }; -/** @type Partial & { BUILD_INSERT_PRODUCT_CONFIGURATION?: string } */ -let productObj = { BUILD_INSERT_PRODUCT_CONFIGURATION: 'BUILD_INSERT_PRODUCT_CONFIGURATION' }; // DO NOT MODIFY, PATCHED DURING BUILD +let productObj: Partial & { BUILD_INSERT_PRODUCT_CONFIGURATION?: string } = { BUILD_INSERT_PRODUCT_CONFIGURATION: 'BUILD_INSERT_PRODUCT_CONFIGURATION' }; // DO NOT MODIFY, PATCHED DURING BUILD if (productObj['BUILD_INSERT_PRODUCT_CONFIGURATION']) { - // @ts-ignore productObj = require('../product.json'); // Running out of sources } -/** @type object & { BUILD_INSERT_PACKAGE_CONFIGURATION?: string } */ let pkgObj = { BUILD_INSERT_PACKAGE_CONFIGURATION: 'BUILD_INSERT_PACKAGE_CONFIGURATION' }; // DO NOT MODIFY, PATCHED DURING BUILD if (pkgObj['BUILD_INSERT_PACKAGE_CONFIGURATION']) { - // @ts-ignore pkgObj = require('../package.json'); // Running out of sources } -module.exports.product = productObj; -module.exports.pkg = pkgObj; - -export const product = module.exports.product; -export const pkg = module.exports.pkg; +export const product = productObj; +export const pkg = pkgObj; diff --git a/src/bootstrap-node.js b/src/bootstrap-node.ts similarity index 77% rename from src/bootstrap-node.js rename to src/bootstrap-node.ts index edb360006f0..e770cedcc46 100644 --- a/src/bootstrap-node.js +++ b/src/bootstrap-node.ts @@ -3,18 +3,15 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -//@ts-check -'use strict'; +/* eslint-disable local/code-import-patterns */ import * as path from 'path'; import * as fs from 'fs'; import { fileURLToPath } from 'url'; import { createRequire } from 'node:module'; +import { IProductConfiguration } from './vs/base/common/product'; -/** @ts-ignore */ const require = createRequire(import.meta.url); -/** @type any */ -const module = { exports: {} }; const __dirname = path.dirname(fileURLToPath(import.meta.url)); // 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']) { // Setup current working directory in all our node & electron processes // - Windows: call `process.chdir()` to always set application folder as cwd // - all OS: store the `process.cwd()` inside `VSCODE_CWD` for consistent lookups -function setupCurrentWorkingDirectory() { +function setupCurrentWorkingDirectory(): void { try { // Store the `process.cwd()` inside `VSCODE_CWD` @@ -64,10 +61,8 @@ setupCurrentWorkingDirectory(); * Add support for redirecting the loading of node modules * * Note: only applies when running out of sources. - * - * @param {string} injectPath */ -module.exports.devInjectNodeModuleLookupPath = function (injectPath) { +export function devInjectNodeModuleLookupPath(injectPath: string): void { if (!process.env['VSCODE_DEV']) { return; // only applies running out of sources } @@ -76,25 +71,22 @@ module.exports.devInjectNodeModuleLookupPath = function (injectPath) { throw new Error('Missing injectPath'); } - const Module = require('node:module'); // register a loader hook + const Module = require('node:module'); Module.register('./bootstrap-import.js', { parentURL: import.meta.url, data: injectPath }); -}; +} -module.exports.removeGlobalNodeJsModuleLookupPaths = function () { +export function removeGlobalNodeJsModuleLookupPaths(): void { if (typeof process?.versions?.electron === 'string') { return; // Electron disables global search paths in https://github.com/electron/electron/blob/3186c2f0efa92d275dc3d57b5a14a60ed3846b0e/shell/common/node_bindings.cc#L653 } const Module = require('module'); - // @ts-ignore const globalPaths = Module.globalPaths; - // @ts-ignore const originalResolveLookupPaths = Module._resolveLookupPaths; - // @ts-ignore - Module._resolveLookupPaths = function (moduleName, parent) { + Module._resolveLookupPaths = function (moduleName: string, parent: any): string[] { const paths = originalResolveLookupPaths(moduleName, parent); if (Array.isArray(paths)) { let commonSuffixLength = 0; @@ -105,21 +97,15 @@ module.exports.removeGlobalNodeJsModuleLookupPaths = function () { } return paths; }; -}; +} /** * Helper to enable portable mode. - * - * @param {Partial} product - * @returns {{ portableDataPath: string; isPortable: boolean; }} */ -module.exports.configurePortable = function (product) { +export function configurePortable(product: Partial): { portableDataPath: string; isPortable: boolean } { const appRoot = path.dirname(__dirname); - /** - * @param {import('path')} path - */ - function getApplicationPath(path) { + function getApplicationPath() { if (process.env['VSCODE_DEV']) { return appRoot; } @@ -131,24 +117,20 @@ module.exports.configurePortable = function (product) { return path.dirname(path.dirname(appRoot)); } - /** - * @param {import('path')} path - */ - function getPortableDataPath(path) { + function getPortableDataPath() { if (process.env['VSCODE_PORTABLE']) { return process.env['VSCODE_PORTABLE']; } if (process.platform === 'win32' || process.platform === 'linux') { - return path.join(getApplicationPath(path), 'data'); + return path.join(getApplicationPath(), 'data'); } - // @ts-ignore const portableDataName = product.portable || `${product.applicationName}-portable-data`; - return path.join(path.dirname(getApplicationPath(path)), portableDataName); + return path.join(path.dirname(getApplicationPath()), portableDataName); } - const portableDataPath = getPortableDataPath(path); + const portableDataPath = getPortableDataPath(); const isPortable = !('target' in product) && fs.existsSync(portableDataPath); const portableTempPath = path.join(portableDataPath, 'tmp'); const isTempPortable = isPortable && fs.existsSync(portableTempPath); @@ -172,10 +154,4 @@ module.exports.configurePortable = function (product) { portableDataPath, isPortable }; -}; - -//#endregion - -export const devInjectNodeModuleLookupPath = module.exports.devInjectNodeModuleLookupPath; -export const removeGlobalNodeJsModuleLookupPaths = module.exports.removeGlobalNodeJsModuleLookupPaths; -export const configurePortable = module.exports.configurePortable; +} diff --git a/src/tsconfig.json b/src/tsconfig.json index 28263043cdb..43f3440eff7 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -26,9 +26,6 @@ ] }, "include": [ - "./bootstrap-import.js", - "./bootstrap-meta.js", - "./bootstrap-node.js", "./bootstrap-server.js", "./bootstrap-window.js", "./cli.js",