diff --git a/src/bootstrap-esm.ts b/src/bootstrap-esm.ts index 8640ba96eab..188a25ab4c7 100644 --- a/src/bootstrap-esm.ts +++ b/src/bootstrap-esm.ts @@ -3,9 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'path'; import * as fs from 'fs'; -import { fileURLToPath } from 'url'; import { createRequire, register } from 'node:module'; import { product, pkg } from './bootstrap-meta.js'; import './bootstrap-node.js'; @@ -13,7 +11,6 @@ import * as performance from './vs/base/common/performance.js'; import { INLSConfiguration } from './vs/nls.js'; const require = createRequire(import.meta.url); -const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Install a hook to module resolution to map 'fs' to 'original-fs' if (process.env['ELECTRON_RUN_AS_NODE'] || process.versions['electron']) { @@ -43,7 +40,7 @@ if (process.env['VSCODE_DEV']) { } catch (error) { /* ignore */ } } globalThis._VSCODE_PACKAGE_JSON = { ...pkg }; -globalThis._VSCODE_FILE_ROOT = __dirname; +globalThis._VSCODE_FILE_ROOT = import.meta.dirname; //#region NLS helpers diff --git a/src/bootstrap-node.ts b/src/bootstrap-node.ts index 2e78b6e42f3..076e9b7c487 100644 --- a/src/bootstrap-node.ts +++ b/src/bootstrap-node.ts @@ -5,12 +5,10 @@ import * as path from 'path'; import * as fs from 'fs'; -import { fileURLToPath } from 'url'; import { createRequire } from 'node:module'; import type { IProductConfiguration } from './vs/base/common/product.js'; const require = createRequire(import.meta.url); -const __dirname = path.dirname(fileURLToPath(import.meta.url)); const isWindows = process.platform === 'win32'; // increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API) @@ -133,7 +131,7 @@ export function removeGlobalNodeJsModuleLookupPaths(): void { * Helper to enable portable mode. */ export function configurePortable(product: Partial): { portableDataPath: string; isPortable: boolean } { - const appRoot = path.dirname(__dirname); + const appRoot = path.dirname(import.meta.dirname); function getApplicationPath(): string { if (process.env['VSCODE_DEV']) { diff --git a/src/cli.ts b/src/cli.ts index ac17eae7012..b643e346b08 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -4,17 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import './bootstrap-cli.js'; // this MUST come before other imports as it changes global state -import { dirname } from 'path'; -import { fileURLToPath } from 'url'; import { configurePortable } from './bootstrap-node.js'; import { bootstrapESM } from './bootstrap-esm.js'; import { resolveNLSConfiguration } from './vs/base/node/nls.js'; import { product } from './bootstrap-meta.js'; -const __dirname = dirname(fileURLToPath(import.meta.url)); - // NLS -const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: __dirname }); +const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: import.meta.dirname }); process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfiguration); // required for `bootstrap-esm` to pick up NLS messages // Enable portable support diff --git a/src/main.ts b/src/main.ts index fc3b6ad6a35..1600666ee1b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,6 @@ import * as os from 'os'; import { performance } from 'perf_hooks'; import { configurePortable } from './bootstrap-node.js'; import { bootstrapESM } from './bootstrap-esm.js'; -import { fileURLToPath } from 'url'; import { app, protocol, crashReporter, Menu, contentTracing } from 'electron'; import minimist from 'minimist'; import { product } from './bootstrap-meta.js'; @@ -21,8 +20,6 @@ import { getUNCHost, addUNCHostToAllowlist } from './vs/base/node/unc.js'; import { INLSConfiguration } from './vs/nls.js'; import { NativeParsedArgs } from './vs/platform/environment/common/argv.js'; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - perf.mark('code/didStartMain'); perf.mark('code/willLoadMainBundle', { @@ -129,7 +126,7 @@ if (userLocale) { osLocale, commit: product.commit, userDataPath, - nlsMetadataPath: __dirname + nlsMetadataPath: import.meta.dirname }); } @@ -691,7 +688,7 @@ async function resolveNlsConfiguration(): Promise { userLocale: 'en', osLocale, resolvedLanguage: 'en', - defaultMessagesFile: path.join(__dirname, 'nls.messages.json'), + defaultMessagesFile: path.join(import.meta.dirname, 'nls.messages.json'), // NLS: below 2 are a relic from old times only used by vscode-nls and deprecated locale: 'en', @@ -707,7 +704,7 @@ async function resolveNlsConfiguration(): Promise { osLocale, commit: product.commit, userDataPath, - nlsMetadataPath: __dirname + nlsMetadataPath: import.meta.dirname }); } diff --git a/src/server-cli.ts b/src/server-cli.ts index 4d1afa4018a..6932f926960 100644 --- a/src/server-cli.ts +++ b/src/server-cli.ts @@ -4,23 +4,20 @@ *--------------------------------------------------------------------------------------------*/ import './bootstrap-server.js'; // this MUST come before other imports as it changes global state -import { dirname, join } from 'path'; -import { fileURLToPath } from 'url'; +import { join } from 'path'; import { devInjectNodeModuleLookupPath } from './bootstrap-node.js'; import { bootstrapESM } from './bootstrap-esm.js'; import { resolveNLSConfiguration } from './vs/base/node/nls.js'; import { product } from './bootstrap-meta.js'; -const __dirname = dirname(fileURLToPath(import.meta.url)); - // NLS -const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: __dirname }); +const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: import.meta.dirname }); process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfiguration); // required for `bootstrap-esm` to pick up NLS messages if (process.env['VSCODE_DEV']) { // When running out of sources, we need to load node modules from remote/node_modules, // which are compiled against nodejs, not electron - process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] = process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] || join(__dirname, '..', 'remote', 'node_modules'); + process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] = process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] || join(import.meta.dirname, '..', 'remote', 'node_modules'); devInjectNodeModuleLookupPath(process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH']); } else { delete process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH']; diff --git a/src/server-main.ts b/src/server-main.ts index 4ffe8fcde12..303aafdf911 100644 --- a/src/server-main.ts +++ b/src/server-main.ts @@ -10,7 +10,6 @@ import { AddressInfo } from 'net'; import * as os from 'os'; import * as readline from 'readline'; import { performance } from 'perf_hooks'; -import { fileURLToPath } from 'url'; import minimist from 'minimist'; import { devInjectNodeModuleLookupPath, removeGlobalNodeJsModuleLookupPaths } from './bootstrap-node.js'; import { bootstrapESM } from './bootstrap-esm.js'; @@ -20,8 +19,6 @@ import * as perf from './vs/base/common/performance.js'; import { INLSConfiguration } from './vs/nls.js'; import { IServerAPI } from './vs/server/node/remoteExtensionHostAgentServer.js'; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - perf.mark('code/server/start'); (globalThis as any).vscodeServerStartTime = performance.now(); @@ -45,7 +42,7 @@ const extensionInstallArgs = ['install-extension', 'install-builtin-extension', const shouldSpawnCli = parsedArgs.help || parsedArgs.version || extensionLookupArgs.some(a => !!parsedArgs[a]) || (extensionInstallArgs.some(a => !!parsedArgs[a]) && !parsedArgs['start-server']); -const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: __dirname }); +const nlsConfiguration = await resolveNLSConfiguration({ userLocale: 'en', osLocale: 'en', commit: product.commit, userDataPath: '', nlsMetadataPath: import.meta.dirname }); if (shouldSpawnCli) { loadCode(nlsConfiguration).then((mod) => { @@ -241,7 +238,7 @@ async function loadCode(nlsConfiguration: INLSConfiguration) { if (process.env['VSCODE_DEV']) { // When running out of sources, we need to load node modules from remote/node_modules, // which are compiled against nodejs, not electron - process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] = process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] || path.join(__dirname, '..', 'remote', 'node_modules'); + process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] = process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'] || path.join(import.meta.dirname, '..', 'remote', 'node_modules'); devInjectNodeModuleLookupPath(process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH']); } else { delete process.env['VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH'];