From 192c67db71e8c261f26e2f34c86a4791ae428b2f Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 8 Nov 2022 17:24:24 +0100 Subject: [PATCH] Always use app root for resource URIs (avoid usage of `require`) --- src/vs/base/common/network.ts | 32 ++++++++++++++----- src/vs/base/node/ps.ts | 4 +-- src/vs/base/test/common/network.test.ts | 4 +-- src/vs/code/node/cli.ts | 2 +- .../environment/common/environmentService.ts | 4 +-- .../common/extensionsScannerService.ts | 2 +- .../electron-main/extensionHostStarter.ts | 4 +-- .../node/externalTerminalService.ts | 2 +- .../files/node/watcher/watcherClient.ts | 2 +- .../issue/electron-main/issueMainService.ts | 6 ++-- src/vs/platform/product/common/product.ts | 2 +- .../sharedProcessWorkerService.ts | 2 +- .../electron-main/sharedProcess.ts | 4 +-- .../node/customEndpointTelemetryService.ts | 2 +- .../platform/terminal/node/ptyHostService.ts | 2 +- .../terminal/node/terminalEnvironment.ts | 2 +- .../electron-main/webviewProtocolProvider.ts | 6 ++-- .../windows/electron-main/windowImpl.ts | 4 +-- src/vs/server/node/extensionHostConnection.ts | 2 +- .../node/remoteExtensionHostAgentServer.ts | 4 +-- src/vs/server/node/remoteLanguagePacks.ts | 2 +- src/vs/server/node/server.main.ts | 2 +- src/vs/server/node/webClientServer.ts | 6 ++-- .../parts/editor/editor.contribution.ts | 4 +-- .../browser/parts/editor/editorGroupView.ts | 6 ++-- .../audioCues/browser/audioCueService.ts | 3 +- .../debug/browser/debug.contribution.ts | 18 +++++------ .../browser/extensionsWorkbenchService.ts | 4 +-- .../view/renderers/backLayerWebView.ts | 6 ++-- .../browser/gettingStartedService.ts | 8 ++--- .../gettingStartedMarkdownRenderer.test.ts | 2 +- .../browser/editor/editorWalkThrough.ts | 2 +- .../builtinExtensionsScannerService.ts | 4 +-- .../common/extensionManagement.ts | 2 +- .../browser/webWorkerExtensionHost.ts | 2 +- .../electron-sandbox/integrityService.ts | 8 ++--- .../languageDetectionWorkerServiceImpl.ts | 26 +++++++-------- .../browser/browserTextMateService.ts | 2 +- .../textMate/browser/nativeTextMateService.ts | 6 ++-- .../textMate/browser/textMateWorker.ts | 2 +- .../tokenStyleResolving.test.ts | 2 +- 41 files changed, 112 insertions(+), 97 deletions(-) diff --git a/src/vs/base/common/network.ts b/src/vs/base/common/network.ts index 648a6391131..a90cb849504 100644 --- a/src/vs/base/common/network.ts +++ b/src/vs/base/common/network.ts @@ -170,6 +170,22 @@ class RemoteAuthoritiesImpl { export const RemoteAuthorities = new RemoteAuthoritiesImpl(); +/** + * A string pointing to a path inside the app. It should not begin with ./ or ../ + */ +export type AppResourcePath = ( + `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` + | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` + | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` + | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` + | `y${string}` | `z${string}` +); + +export const builtinExtensionsPath: AppResourcePath = 'vs/../../extensions'; +export const nodeModulesPath: AppResourcePath = 'vs/../../node_modules'; +export const nodeModulesAsarPath: AppResourcePath = 'vs/../../node_modules.asar'; +export const nodeModulesAsarUnpackedPath: AppResourcePath = 'vs/../../node_modules.asar.unpacked'; + class FileAccessImpl { private static readonly FALLBACK_AUTHORITY = 'vscode-app'; @@ -181,9 +197,9 @@ class FileAccessImpl { * **Note:** use `dom.ts#asCSSUrl` whenever the URL is to be used in CSS context. */ asBrowserUri(uri: URI): URI; - asBrowserUri(moduleId: string, moduleIdToUrl: { toUrl(moduleId: string): string }): URI; - asBrowserUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI { - const uri = this.toUri(uriOrModule, moduleIdToUrl); + asBrowserUri(moduleId: AppResourcePath | ''): URI; + asBrowserUri(uriOrModule: URI | AppResourcePath | ''): URI { + const uri = this.toUri(uriOrModule); // Handle remote URIs via `RemoteAuthorities` if (uri.scheme === Schemas.vscodeRemote) { @@ -221,9 +237,9 @@ class FileAccessImpl { * is responsible for loading. */ asFileUri(uri: URI): URI; - asFileUri(moduleId: string, moduleIdToUrl: { toUrl(moduleId: string): string }): URI; - asFileUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI { - const uri = this.toUri(uriOrModule, moduleIdToUrl); + asFileUri(moduleId: AppResourcePath | ''): URI; + asFileUri(uriOrModule: URI | AppResourcePath | ''): URI { + const uri = this.toUri(uriOrModule); // Only convert the URI if it is `vscode-file:` scheme if (uri.scheme === Schemas.vscodeFileResource) { @@ -241,12 +257,12 @@ class FileAccessImpl { return uri; } - private toUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI { + private toUri(uriOrModule: URI | string): URI { if (URI.isUri(uriOrModule)) { return uriOrModule; } - return URI.parse(moduleIdToUrl!.toUrl(uriOrModule)); + return URI.parse(require.toUrl(uriOrModule)); } } diff --git a/src/vs/base/node/ps.ts b/src/vs/base/node/ps.ts index 8498145bed2..0bcbce4a8d4 100644 --- a/src/vs/base/node/ps.ts +++ b/src/vs/base/node/ps.ts @@ -198,7 +198,7 @@ export function listProcesses(rootPid: number): Promise { // The cpu usage value reported on Linux is the average over the process lifetime, // recalculate the usage over a one second interval // JSON.stringify is needed to escape spaces, https://github.com/nodejs/node/issues/6803 - let cmd = JSON.stringify(FileAccess.asFileUri('vs/base/node/cpuUsage.sh', require).fsPath); + let cmd = JSON.stringify(FileAccess.asFileUri('vs/base/node/cpuUsage.sh').fsPath); cmd += ' ' + pids.join(' '); exec(cmd, {}, (err, stdout, stderr) => { @@ -226,7 +226,7 @@ export function listProcesses(rootPid: number): Promise { if (process.platform !== 'linux') { reject(err || new Error(stderr.toString())); } else { - const cmd = JSON.stringify(FileAccess.asFileUri('vs/base/node/ps.sh', require).fsPath); + const cmd = JSON.stringify(FileAccess.asFileUri('vs/base/node/ps.sh').fsPath); exec(cmd, {}, (err, stdout, stderr) => { if (err || stderr) { reject(err || new Error(stderr.toString())); diff --git a/src/vs/base/test/common/network.test.ts b/src/vs/base/test/common/network.test.ts index 8916eb1c868..a59fec07594 100644 --- a/src/vs/base/test/common/network.test.ts +++ b/src/vs/base/test/common/network.test.ts @@ -30,10 +30,10 @@ suite('network', () => { }); (isWeb ? test.skip : test)('FileAccess: moduleId (native)', () => { - const browserUri = FileAccess.asBrowserUri('vs/base/test/node/network.test', require); + const browserUri = FileAccess.asBrowserUri('vs/base/test/node/network.test'); assert.strictEqual(browserUri.scheme, Schemas.vscodeFileResource); - const fileUri = FileAccess.asFileUri('vs/base/test/node/network.test', require); + const fileUri = FileAccess.asFileUri('vs/base/test/node/network.test'); assert.strictEqual(fileUri.scheme, Schemas.file); }); diff --git a/src/vs/code/node/cli.ts b/src/vs/code/node/cli.ts index bd7acdf794c..bcefa8782e3 100644 --- a/src/vs/code/node/cli.ts +++ b/src/vs/code/node/cli.ts @@ -496,7 +496,7 @@ export async function main(argv: string[]): Promise { } function getAppRoot() { - return dirname(FileAccess.asFileUri('', require).fsPath); + return dirname(FileAccess.asFileUri('').fsPath); } function eventuallyExit(code: number): void { diff --git a/src/vs/platform/environment/common/environmentService.ts b/src/vs/platform/environment/common/environmentService.ts index cfbba68219b..1745ed81462 100644 --- a/src/vs/platform/environment/common/environmentService.ts +++ b/src/vs/platform/environment/common/environmentService.ts @@ -44,7 +44,7 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron declare readonly _serviceBrand: undefined; @memoize - get appRoot(): string { return dirname(FileAccess.asFileUri('', require).fsPath); } + get appRoot(): string { return dirname(FileAccess.asFileUri('').fsPath); } @memoize get userHome(): URI { return URI.file(this.paths.homeDir); } @@ -129,7 +129,7 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron return resolve(cliBuiltinExtensionsDir); } - return normalize(join(FileAccess.asFileUri('', require).fsPath, '..', 'extensions')); + return normalize(join(FileAccess.asFileUri('').fsPath, '..', 'extensions')); } get extensionsDownloadLocation(): URI { diff --git a/src/vs/platform/extensionManagement/common/extensionsScannerService.ts b/src/vs/platform/extensionManagement/common/extensionsScannerService.ts index 2a763089d41..13dfbaa1a07 100644 --- a/src/vs/platform/extensionManagement/common/extensionsScannerService.ts +++ b/src/vs/platform/extensionManagement/common/extensionsScannerService.ts @@ -355,7 +355,7 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem this.logService.trace('Started scanning dev system extensions'); const builtinExtensionControl = checkControlFile ? await this.getBuiltInExtensionControl() : {}; const devSystemExtensionsLocations: URI[] = []; - const devSystemExtensionsLocation = URI.file(path.normalize(path.join(FileAccess.asFileUri('', require).fsPath, '..', '.build', 'builtInExtensions'))); + const devSystemExtensionsLocation = URI.file(path.normalize(path.join(FileAccess.asFileUri('').fsPath, '..', '.build', 'builtInExtensions'))); for (const extension of devSystemExtensionsList) { const controlState = builtinExtensionControl[extension.name] || 'marketplace'; switch (controlState) { diff --git a/src/vs/platform/extensions/electron-main/extensionHostStarter.ts b/src/vs/platform/extensions/electron-main/extensionHostStarter.ts index 8a2c0a87780..da9e7b5a70d 100644 --- a/src/vs/platform/extensions/electron-main/extensionHostStarter.ts +++ b/src/vs/platform/extensions/electron-main/extensionHostStarter.ts @@ -309,7 +309,7 @@ class ExtensionHostProcess extends Disposable { } const sw = StopWatch.create(false); this._process = fork( - FileAccess.asFileUri('bootstrap-fork', require).fsPath, + FileAccess.asFileUri('bootstrap-fork').fsPath, ['--type=extensionHost', '--skipWorkspaceStorageLock'], mixin({ cwd: cwd() }, opts), ); @@ -434,7 +434,7 @@ class UtilityExtensionHostProcess extends Disposable { } const serviceName = `extensionHost${this.id}`; - const modulePath = FileAccess.asFileUri('bootstrap-fork.js', require).fsPath; + const modulePath = FileAccess.asFileUri('bootstrap-fork.js').fsPath; const args: string[] = ['--type=extensionHost', '--skipWorkspaceStorageLock']; const execArgv: string[] = opts.execArgv || []; const env: { [key: string]: any } = { ...opts.env }; diff --git a/src/vs/platform/externalTerminal/node/externalTerminalService.ts b/src/vs/platform/externalTerminal/node/externalTerminalService.ts index dc00f2f647d..c378445f6f5 100644 --- a/src/vs/platform/externalTerminal/node/externalTerminalService.ts +++ b/src/vs/platform/externalTerminal/node/externalTerminalService.ts @@ -133,7 +133,7 @@ export class MacExternalTerminalService extends ExternalTerminalService implemen // and then launches the program inside that window. const script = terminalApp === DEFAULT_TERMINAL_OSX ? 'TerminalHelper' : 'iTermHelper'; - const scriptpath = FileAccess.asFileUri(`vs/workbench/contrib/externalTerminal/node/${script}.scpt`, require).fsPath; + const scriptpath = FileAccess.asFileUri(`vs/workbench/contrib/externalTerminal/node/${script}.scpt`).fsPath; const osaArgs = [ scriptpath, diff --git a/src/vs/platform/files/node/watcher/watcherClient.ts b/src/vs/platform/files/node/watcher/watcherClient.ts index 465f8421d06..221f7629496 100644 --- a/src/vs/platform/files/node/watcher/watcherClient.ts +++ b/src/vs/platform/files/node/watcher/watcherClient.ts @@ -26,7 +26,7 @@ export class UniversalWatcherClient extends AbstractUniversalWatcherClient { // Fork the universal file watcher and build a client around // its server for passing over requests and receiving events. const client = disposables.add(new Client( - FileAccess.asFileUri('bootstrap-fork', require).fsPath, + FileAccess.asFileUri('bootstrap-fork').fsPath, { serverName: 'File Watcher', args: ['--type=fileWatcher'], diff --git a/src/vs/platform/issue/electron-main/issueMainService.ts b/src/vs/platform/issue/electron-main/issueMainService.ts index a26823ec79c..c1967961955 100644 --- a/src/vs/platform/issue/electron-main/issueMainService.ts +++ b/src/vs/platform/issue/electron-main/issueMainService.ts @@ -228,7 +228,7 @@ export class IssueMainService implements IIssueMainService { }); this.issueReporterWindow.loadURL( - FileAccess.asBrowserUri(`vs/code/electron-sandbox/issue/issueReporter${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true) + FileAccess.asBrowserUri(`vs/code/electron-sandbox/issue/issueReporter${this.environmentMainService.isBuilt ? '' : '-dev'}.html`).toString(true) ); this.issueReporterWindow.on('close', () => { @@ -279,7 +279,7 @@ export class IssueMainService implements IIssueMainService { }); this.processExplorerWindow.loadURL( - FileAccess.asBrowserUri(`vs/code/electron-sandbox/processExplorer/processExplorer${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true) + FileAccess.asBrowserUri(`vs/code/electron-sandbox/processExplorer/processExplorer${this.environmentMainService.isBuilt ? '' : '-dev'}.html`).toString(true) ); this.processExplorerWindow.on('close', () => { @@ -325,7 +325,7 @@ export class IssueMainService implements IIssueMainService { title: options.title, backgroundColor: options.backgroundColor || IssueMainService.DEFAULT_BACKGROUND_COLOR, webPreferences: { - preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js', require).fsPath, + preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js').fsPath, additionalArguments: [`--vscode-window-config=${ipcObjectUrl.resource.toString()}`, `--vscode-window-kind=${windowKind}`], v8CacheOptions: this.environmentMainService.useCodeCache ? 'bypassHeatCheck' : 'none', enableWebSQL: false, diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts index bceda016f20..3f50bef5ca2 100644 --- a/src/vs/platform/product/common/product.ts +++ b/src/vs/platform/product/common/product.ts @@ -29,7 +29,7 @@ if (typeof globals.vscode !== 'undefined' && typeof globals.vscode.context !== ' else if (typeof require?.__$__nodeRequire === 'function') { // Obtain values from product.json and package.json - const rootPath = dirname(FileAccess.asFileUri('', require)); + const rootPath = dirname(FileAccess.asFileUri('')); product = require.__$__nodeRequire(joinPath(rootPath, 'product.json').fsPath); diff --git a/src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerService.ts b/src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerService.ts index 15eba30ae44..e02ea92731b 100644 --- a/src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerService.ts +++ b/src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerService.ts @@ -281,7 +281,7 @@ class SharedProcessWebWorker extends Disposable { id: SharedProcessWorkerMessages.Spawn, configuration, environment: { - bootstrapPath: FileAccess.asFileUri('bootstrap-fork', require).fsPath + bootstrapPath: FileAccess.asFileUri('bootstrap-fork').fsPath } }; diff --git a/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts b/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts index 5b3e3936011..43b70a639b5 100644 --- a/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts +++ b/src/vs/platform/sharedProcess/electron-main/sharedProcess.ts @@ -222,7 +222,7 @@ export class SharedProcess extends Disposable implements ISharedProcess { show: false, backgroundColor: this.themeMainService.getBackgroundColor(), webPreferences: { - preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js', require).fsPath, + preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js').fsPath, additionalArguments: [`--vscode-window-config=${configObjectUrl.resource.toString()}`, '--vscode-window-kind=shared-process'], v8CacheOptions: this.environmentMainService.useCodeCache ? 'bypassHeatCheck' : 'none', nodeIntegration: true, @@ -250,7 +250,7 @@ export class SharedProcess extends Disposable implements ISharedProcess { }); // Load with config - this.window.loadURL(FileAccess.asBrowserUri(`vs/code/electron-browser/sharedProcess/sharedProcess${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true)); + this.window.loadURL(FileAccess.asBrowserUri(`vs/code/electron-browser/sharedProcess/sharedProcess${this.environmentMainService.isBuilt ? '' : '-dev'}.html`).toString(true)); } private registerWindowListeners(): void { diff --git a/src/vs/platform/telemetry/node/customEndpointTelemetryService.ts b/src/vs/platform/telemetry/node/customEndpointTelemetryService.ts index 2b7a2228a4a..255f26d5217 100644 --- a/src/vs/platform/telemetry/node/customEndpointTelemetryService.ts +++ b/src/vs/platform/telemetry/node/customEndpointTelemetryService.ts @@ -34,7 +34,7 @@ export class CustomEndpointTelemetryService implements ICustomEndpointTelemetryS telemetryInfo['common.vscodesessionid'] = sessionId; const args = [endpoint.id, JSON.stringify(telemetryInfo), endpoint.aiKey]; const client = new TelemetryClient( - FileAccess.asFileUri('bootstrap-fork', require).fsPath, + FileAccess.asFileUri('bootstrap-fork').fsPath, { serverName: 'Debug Telemetry', timeout: 1000 * 60 * 5, diff --git a/src/vs/platform/terminal/node/ptyHostService.ts b/src/vs/platform/terminal/node/ptyHostService.ts index 98bc9f4180e..ac1e390de91 100644 --- a/src/vs/platform/terminal/node/ptyHostService.ts +++ b/src/vs/platform/terminal/node/ptyHostService.ts @@ -155,7 +155,7 @@ export class PtyHostService extends Disposable implements IPtyService { } } - const client = new Client(FileAccess.asFileUri('bootstrap-fork', require).fsPath, opts); + const client = new Client(FileAccess.asFileUri('bootstrap-fork').fsPath, opts); this._onPtyHostStart.fire(); // Setup heartbeat service and trigger a heartbeat immediately to reset the timeouts diff --git a/src/vs/platform/terminal/node/terminalEnvironment.ts b/src/vs/platform/terminal/node/terminalEnvironment.ts index 9ff09c4322e..774973104d6 100644 --- a/src/vs/platform/terminal/node/terminalEnvironment.ts +++ b/src/vs/platform/terminal/node/terminalEnvironment.ts @@ -119,7 +119,7 @@ export function getShellIntegrationInjection( const originalArgs = shellLaunchConfig.args; const shell = process.platform === 'win32' ? path.basename(shellLaunchConfig.executable).toLowerCase() : path.basename(shellLaunchConfig.executable); - const appRoot = path.dirname(FileAccess.asFileUri('', require).fsPath); + const appRoot = path.dirname(FileAccess.asFileUri('').fsPath); let newArgs: string[] | undefined; const envMixin: IProcessEnvironment = { 'VSCODE_INJECTION': '1' diff --git a/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts b/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts index 8c8be165bc0..7697c49c8cc 100644 --- a/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts +++ b/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts @@ -5,7 +5,7 @@ import { protocol } from 'electron'; import { Disposable } from 'vs/base/common/lifecycle'; -import { COI, FileAccess, Schemas } from 'vs/base/common/network'; +import { AppResourcePath, COI, FileAccess, Schemas } from 'vs/base/common/network'; import { URI } from 'vs/base/common/uri'; @@ -33,8 +33,8 @@ export class WebviewProtocolProvider extends Disposable { const uri = URI.parse(request.url); const entry = WebviewProtocolProvider.validWebviewFilePaths.get(uri.path); if (typeof entry === 'string') { - const relativeResourcePath = `vs/workbench/contrib/webview/browser/pre/${entry}`; - const url = FileAccess.asFileUri(relativeResourcePath, require); + const relativeResourcePath: AppResourcePath = `vs/workbench/contrib/webview/browser/pre/${entry}`; + const url = FileAccess.asFileUri(relativeResourcePath); return callback({ path: decodeURIComponent(url.fsPath), headers: { diff --git a/src/vs/platform/windows/electron-main/windowImpl.ts b/src/vs/platform/windows/electron-main/windowImpl.ts index 25eb72719b2..8efb68d9130 100644 --- a/src/vs/platform/windows/electron-main/windowImpl.ts +++ b/src/vs/platform/windows/electron-main/windowImpl.ts @@ -215,7 +215,7 @@ export class CodeWindow extends Disposable implements ICodeWindow { show: !isFullscreenOrMaximized, // reduce flicker by showing later title: this.productService.nameLong, webPreferences: { - preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js', require).fsPath, + preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js').fsPath, additionalArguments: [`--vscode-window-config=${this.configObjectUrl.resource.toString()}`], v8CacheOptions: this.environmentMainService.useCodeCache ? 'bypassHeatCheck' : 'none', enableWebSQL: false, @@ -878,7 +878,7 @@ export class CodeWindow extends Disposable implements ICodeWindow { this.readyState = ReadyState.NAVIGATING; // Load URL - this._win.loadURL(FileAccess.asBrowserUri(`vs/code/electron-sandbox/workbench/workbench${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true)); + this._win.loadURL(FileAccess.asBrowserUri(`vs/code/electron-sandbox/workbench/workbench${this.environmentMainService.isBuilt ? '' : '-dev'}.html`).toString(true)); // Remember that we did load const wasLoaded = this.wasLoaded; diff --git a/src/vs/server/node/extensionHostConnection.ts b/src/vs/server/node/extensionHostConnection.ts index 00e2e2a1305..3336c1ec2ce 100644 --- a/src/vs/server/node/extensionHostConnection.ts +++ b/src/vs/server/node/extensionHostConnection.ts @@ -257,7 +257,7 @@ export class ExtensionHostConnection { const args = ['--type=extensionHost', `--transformURIs`]; const useHostProxy = this._environmentService.args['use-host-proxy']; args.push(`--useHostProxy=${useHostProxy ? 'true' : 'false'}`); - this._extensionHostProcess = cp.fork(FileAccess.asFileUri('bootstrap-fork', require).fsPath, args, opts); + this._extensionHostProcess = cp.fork(FileAccess.asFileUri('bootstrap-fork').fsPath, args, opts); const pid = this._extensionHostProcess.pid; this._log(`<${pid}> Launched Extension Host Process.`); diff --git a/src/vs/server/node/remoteExtensionHostAgentServer.ts b/src/vs/server/node/remoteExtensionHostAgentServer.ts index 31c0864d5fb..efc591aab18 100644 --- a/src/vs/server/node/remoteExtensionHostAgentServer.ts +++ b/src/vs/server/node/remoteExtensionHostAgentServer.ts @@ -724,7 +724,7 @@ export async function createServer(address: string | net.AddressInfo | null, arg const vsdaMod = instantiationService.invokeFunction((accessor) => { const logService = accessor.get(ILogService); - const hasVSDA = fs.existsSync(join(FileAccess.asFileUri('', require).fsPath, '../node_modules/vsda')); + const hasVSDA = fs.existsSync(join(FileAccess.asFileUri('').fsPath, '../node_modules/vsda')); if (hasVSDA) { try { return require.__$__nodeRequire('vsda'); @@ -735,7 +735,7 @@ export async function createServer(address: string | net.AddressInfo | null, arg return null; }); - const hasWebClient = fs.existsSync(FileAccess.asFileUri('vs/code/browser/workbench/workbench.html', require).fsPath); + const hasWebClient = fs.existsSync(FileAccess.asFileUri('vs/code/browser/workbench/workbench.html').fsPath); if (hasWebClient && address && typeof address !== 'string') { // ships the web ui! diff --git a/src/vs/server/node/remoteLanguagePacks.ts b/src/vs/server/node/remoteLanguagePacks.ts index 1da6011a1cc..e0218f836ab 100644 --- a/src/vs/server/node/remoteLanguagePacks.ts +++ b/src/vs/server/node/remoteLanguagePacks.ts @@ -10,7 +10,7 @@ import * as path from 'vs/base/common/path'; import * as lp from 'vs/base/node/languagePacks'; import product from 'vs/platform/product/common/product'; -const metaData = path.join(FileAccess.asFileUri('', require).fsPath, 'nls.metadata.json'); +const metaData = path.join(FileAccess.asFileUri('').fsPath, 'nls.metadata.json'); const _cache: Map> = new Map(); function exists(file: string) { diff --git a/src/vs/server/node/server.main.ts b/src/vs/server/node/server.main.ts index 183b614e2bc..469671e5745 100644 --- a/src/vs/server/node/server.main.ts +++ b/src/vs/server/node/server.main.ts @@ -43,7 +43,7 @@ const GLOBAL_STORAGE_HOME = join(APP_SETTINGS_HOME, 'globalStorage'); const LOCAL_HISTORY_HOME = join(APP_SETTINGS_HOME, 'History'); const MACHINE_SETTINGS_HOME = join(USER_DATA_PATH, 'Machine'); args['user-data-dir'] = USER_DATA_PATH; -const APP_ROOT = dirname(FileAccess.asFileUri('', require).fsPath); +const APP_ROOT = dirname(FileAccess.asFileUri('').fsPath); const BUILTIN_EXTENSIONS_FOLDER_PATH = join(APP_ROOT, 'extensions'); args['builtin-extensions-dir'] = BUILTIN_EXTENSIONS_FOLDER_PATH; args['extensions-dir'] = args['extensions-dir'] || join(REMOTE_DATA_FOLDER, 'extensions'); diff --git a/src/vs/server/node/webClientServer.ts b/src/vs/server/node/webClientServer.ts index 35cdf1e9590..82d88edf26f 100644 --- a/src/vs/server/node/webClientServer.ts +++ b/src/vs/server/node/webClientServer.ts @@ -90,7 +90,7 @@ export async function serveFile(filePath: string, cacheControl: CacheControl, lo } } -const APP_ROOT = dirname(FileAccess.asFileUri('', require).fsPath); +const APP_ROOT = dirname(FileAccess.asFileUri('').fsPath); export class WebClientServer { @@ -290,7 +290,7 @@ export class WebClientServer { const resolveWorkspaceURI = (defaultLocation?: string) => defaultLocation && URI.file(path.resolve(defaultLocation)).with({ scheme: Schemas.vscodeRemote, authority: remoteAuthority }); - const filePath = FileAccess.asFileUri(this._environmentService.isBuilt ? 'vs/code/browser/workbench/workbench.html' : 'vs/code/browser/workbench/workbench-dev.html', require).fsPath; + const filePath = FileAccess.asFileUri(this._environmentService.isBuilt ? 'vs/code/browser/workbench/workbench.html' : 'vs/code/browser/workbench/workbench-dev.html').fsPath; const authSessionInfo = !this._environmentService.isBuilt && this._environmentService.args['github-auth'] ? { id: generateUuid(), providerId: 'github', @@ -398,7 +398,7 @@ export class WebClientServer { * Handle HTTP requests for /callback */ private async _handleCallback(res: http.ServerResponse): Promise { - const filePath = FileAccess.asFileUri('vs/code/browser/workbench/callback.html', require).fsPath; + const filePath = FileAccess.asFileUri('vs/code/browser/workbench/callback.html').fsPath; const data = (await fsp.readFile(filePath)).toString(); const cspDirectives = [ 'default-src \'self\';', diff --git a/src/vs/workbench/browser/parts/editor/editor.contribution.ts b/src/vs/workbench/browser/parts/editor/editor.contribution.ts index 82ca36f22a6..fbe1d5a8853 100644 --- a/src/vs/workbench/browser/parts/editor/editor.contribution.ts +++ b/src/vs/workbench/browser/parts/editor/editor.contribution.ts @@ -304,13 +304,13 @@ registerEditorCommands(); // macOS: Touchbar if (isMacintosh) { MenuRegistry.appendMenuItem(MenuId.TouchBarContext, { - command: { id: NavigateBackwardsAction.ID, title: NavigateBackwardsAction.LABEL, icon: { dark: FileAccess.asFileUri('vs/workbench/browser/parts/editor/media/back-tb.png', require) } }, + command: { id: NavigateBackwardsAction.ID, title: NavigateBackwardsAction.LABEL, icon: { dark: FileAccess.asFileUri('vs/workbench/browser/parts/editor/media/back-tb.png') } }, group: 'navigation', order: 0 }); MenuRegistry.appendMenuItem(MenuId.TouchBarContext, { - command: { id: NavigateForwardAction.ID, title: NavigateForwardAction.LABEL, icon: { dark: FileAccess.asFileUri('vs/workbench/browser/parts/editor/media/forward-tb.png', require) } }, + command: { id: NavigateForwardAction.ID, title: NavigateForwardAction.LABEL, icon: { dark: FileAccess.asFileUri('vs/workbench/browser/parts/editor/media/forward-tb.png') } }, group: 'navigation', order: 1 }); diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index de6a2d9c5c6..2fb49e6f430 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -43,7 +43,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic import { hash } from 'vs/base/common/hash'; import { getMimeTypes } from 'vs/editor/common/services/languagesAssociations'; import { extname, isEqual } from 'vs/base/common/resources'; -import { FileAccess, Schemas } from 'vs/base/common/network'; +import { AppResourcePath, FileAccess, Schemas } from 'vs/base/common/network'; import { EditorActivation, IEditorOptions } from 'vs/platform/editor/common/editor'; import { IFileDialogService, ConfirmResult } from 'vs/platform/dialogs/common/dialogs'; import { IFilesConfigurationService, AutoSaveMode } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService'; @@ -1939,10 +1939,10 @@ export interface EditorReplacement extends IEditorReplacement { registerThemingParticipant((theme, collector) => { // Letterpress - const letterpress = `./media/letterpress-${theme.type}.svg`; + const letterpress: AppResourcePath = `vs/workbench/browser/parts/editor/media/letterpress-${theme.type}.svg`; collector.addRule(` .monaco-workbench .part.editor > .content .editor-group-container.empty .editor-group-letterpress { - background-image: ${asCSSUrl(FileAccess.asBrowserUri(letterpress, require))} + background-image: ${asCSSUrl(FileAccess.asBrowserUri(letterpress))} } `); diff --git a/src/vs/workbench/contrib/audioCues/browser/audioCueService.ts b/src/vs/workbench/contrib/audioCues/browser/audioCueService.ts index b2ab0e3d458..6aeb6d66f25 100644 --- a/src/vs/workbench/contrib/audioCues/browser/audioCueService.ts +++ b/src/vs/workbench/contrib/audioCues/browser/audioCueService.ts @@ -70,8 +70,7 @@ export class AudioCueService extends Disposable implements IAudioCueService { this.playingSounds.add(sound); const url = FileAccess.asBrowserUri( - `vs/workbench/contrib/audioCues/browser/media/${sound.fileName}`, - require + `vs/workbench/contrib/audioCues/browser/media/${sound.fileName}` ).toString(); const audio = new Audio(url); audio.volume = this.getVolumeInPercent() / 100; diff --git a/src/vs/workbench/contrib/debug/browser/debug.contribution.ts b/src/vs/workbench/contrib/debug/browser/debug.contribution.ts index 77bda0eb967..95473c975cf 100644 --- a/src/vs/workbench/contrib/debug/browser/debug.contribution.ts +++ b/src/vs/workbench/contrib/debug/browser/debug.contribution.ts @@ -200,15 +200,15 @@ if (isMacintosh) { }); }; - registerTouchBarEntry(DEBUG_RUN_COMMAND_ID, DEBUG_RUN_LABEL, 0, CONTEXT_IN_DEBUG_MODE.toNegated(), FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/continue-tb.png', require)); - registerTouchBarEntry(DEBUG_START_COMMAND_ID, DEBUG_START_LABEL, 1, CONTEXT_IN_DEBUG_MODE.toNegated(), FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/run-with-debugging-tb.png', require)); - registerTouchBarEntry(CONTINUE_ID, CONTINUE_LABEL, 0, CONTEXT_DEBUG_STATE.isEqualTo('stopped'), FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/continue-tb.png', require)); - registerTouchBarEntry(PAUSE_ID, PAUSE_LABEL, 1, ContextKeyExpr.and(CONTEXT_IN_DEBUG_MODE, ContextKeyExpr.notEquals('debugState', 'stopped')), FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/pause-tb.png', require)); - registerTouchBarEntry(STEP_OVER_ID, STEP_OVER_LABEL, 2, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/stepover-tb.png', require)); - registerTouchBarEntry(STEP_INTO_ID, STEP_INTO_LABEL, 3, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/stepinto-tb.png', require)); - registerTouchBarEntry(STEP_OUT_ID, STEP_OUT_LABEL, 4, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/stepout-tb.png', require)); - registerTouchBarEntry(RESTART_SESSION_ID, RESTART_LABEL, 5, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/restart-tb.png', require)); - registerTouchBarEntry(STOP_ID, STOP_LABEL, 6, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/stop-tb.png', require)); + registerTouchBarEntry(DEBUG_RUN_COMMAND_ID, DEBUG_RUN_LABEL, 0, CONTEXT_IN_DEBUG_MODE.toNegated(), FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/continue-tb.png')); + registerTouchBarEntry(DEBUG_START_COMMAND_ID, DEBUG_START_LABEL, 1, CONTEXT_IN_DEBUG_MODE.toNegated(), FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/run-with-debugging-tb.png')); + registerTouchBarEntry(CONTINUE_ID, CONTINUE_LABEL, 0, CONTEXT_DEBUG_STATE.isEqualTo('stopped'), FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/continue-tb.png')); + registerTouchBarEntry(PAUSE_ID, PAUSE_LABEL, 1, ContextKeyExpr.and(CONTEXT_IN_DEBUG_MODE, ContextKeyExpr.notEquals('debugState', 'stopped')), FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/pause-tb.png')); + registerTouchBarEntry(STEP_OVER_ID, STEP_OVER_LABEL, 2, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/stepover-tb.png')); + registerTouchBarEntry(STEP_INTO_ID, STEP_INTO_LABEL, 3, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/stepinto-tb.png')); + registerTouchBarEntry(STEP_OUT_ID, STEP_OUT_LABEL, 4, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/stepout-tb.png')); + registerTouchBarEntry(RESTART_SESSION_ID, RESTART_LABEL, 5, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/restart-tb.png')); + registerTouchBarEntry(STOP_ID, STOP_LABEL, 6, CONTEXT_IN_DEBUG_MODE, FileAccess.asFileUri('vs/workbench/contrib/debug/browser/media/stop-tb.png')); } // Editor Title Menu's "Run/Debug" dropdown item diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts b/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts index adc6daaa487..b22acd0909a 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts @@ -191,10 +191,10 @@ export class Extension implements IExtension { if (this.type === ExtensionType.System && this.local) { if (this.local.manifest && this.local.manifest.contributes) { if (Array.isArray(this.local.manifest.contributes.themes) && this.local.manifest.contributes.themes.length) { - return FileAccess.asBrowserUri('./media/theme-icon.png', require).toString(true); + return FileAccess.asBrowserUri('vs/workbench/contrib/extensions/browser/media/theme-icon.png').toString(true); } if (Array.isArray(this.local.manifest.contributes.grammars) && this.local.manifest.contributes.grammars.length) { - return FileAccess.asBrowserUri('./media/language-icon.svg', require).toString(true); + return FileAccess.asBrowserUri('vs/workbench/contrib/extensions/browser/media/language-icon.svg').toString(true); } } } diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index 6803f396bcf..9fc80f70589 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -479,7 +479,7 @@ export class BackLayerWebView extends Disposable { this._webviewPreloadInitialized = new DeferredPromise(); if (!isWeb) { - const loaderUri = FileAccess.asFileUri('vs/loader.js', require); + const loaderUri = FileAccess.asFileUri('vs/loader.js'); const loader = this.asWebviewUri(loaderUri, undefined); coreDependencies = `