Skip to content

Commit 192c67d

Browse files
committed
Always use app root for resource URIs (avoid usage of require)
1 parent 57f489b commit 192c67d

File tree

41 files changed

+112
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+112
-97
lines changed

src/vs/base/common/network.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ class RemoteAuthoritiesImpl {
170170

171171
export const RemoteAuthorities = new RemoteAuthoritiesImpl();
172172

173+
/**
174+
* A string pointing to a path inside the app. It should not begin with ./ or ../
175+
*/
176+
export type AppResourcePath = (
177+
`a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}`
178+
| `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}`
179+
| `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}`
180+
| `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}`
181+
| `y${string}` | `z${string}`
182+
);
183+
184+
export const builtinExtensionsPath: AppResourcePath = 'vs/../../extensions';
185+
export const nodeModulesPath: AppResourcePath = 'vs/../../node_modules';
186+
export const nodeModulesAsarPath: AppResourcePath = 'vs/../../node_modules.asar';
187+
export const nodeModulesAsarUnpackedPath: AppResourcePath = 'vs/../../node_modules.asar.unpacked';
188+
173189
class FileAccessImpl {
174190

175191
private static readonly FALLBACK_AUTHORITY = 'vscode-app';
@@ -181,9 +197,9 @@ class FileAccessImpl {
181197
* **Note:** use `dom.ts#asCSSUrl` whenever the URL is to be used in CSS context.
182198
*/
183199
asBrowserUri(uri: URI): URI;
184-
asBrowserUri(moduleId: string, moduleIdToUrl: { toUrl(moduleId: string): string }): URI;
185-
asBrowserUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI {
186-
const uri = this.toUri(uriOrModule, moduleIdToUrl);
200+
asBrowserUri(moduleId: AppResourcePath | ''): URI;
201+
asBrowserUri(uriOrModule: URI | AppResourcePath | ''): URI {
202+
const uri = this.toUri(uriOrModule);
187203

188204
// Handle remote URIs via `RemoteAuthorities`
189205
if (uri.scheme === Schemas.vscodeRemote) {
@@ -221,9 +237,9 @@ class FileAccessImpl {
221237
* is responsible for loading.
222238
*/
223239
asFileUri(uri: URI): URI;
224-
asFileUri(moduleId: string, moduleIdToUrl: { toUrl(moduleId: string): string }): URI;
225-
asFileUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI {
226-
const uri = this.toUri(uriOrModule, moduleIdToUrl);
240+
asFileUri(moduleId: AppResourcePath | ''): URI;
241+
asFileUri(uriOrModule: URI | AppResourcePath | ''): URI {
242+
const uri = this.toUri(uriOrModule);
227243

228244
// Only convert the URI if it is `vscode-file:` scheme
229245
if (uri.scheme === Schemas.vscodeFileResource) {
@@ -241,12 +257,12 @@ class FileAccessImpl {
241257
return uri;
242258
}
243259

244-
private toUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI {
260+
private toUri(uriOrModule: URI | string): URI {
245261
if (URI.isUri(uriOrModule)) {
246262
return uriOrModule;
247263
}
248264

249-
return URI.parse(moduleIdToUrl!.toUrl(uriOrModule));
265+
return URI.parse(require.toUrl(uriOrModule));
250266
}
251267
}
252268

src/vs/base/node/ps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
198198
// The cpu usage value reported on Linux is the average over the process lifetime,
199199
// recalculate the usage over a one second interval
200200
// JSON.stringify is needed to escape spaces, https://github.com/nodejs/node/issues/6803
201-
let cmd = JSON.stringify(FileAccess.asFileUri('vs/base/node/cpuUsage.sh', require).fsPath);
201+
let cmd = JSON.stringify(FileAccess.asFileUri('vs/base/node/cpuUsage.sh').fsPath);
202202
cmd += ' ' + pids.join(' ');
203203

204204
exec(cmd, {}, (err, stdout, stderr) => {
@@ -226,7 +226,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
226226
if (process.platform !== 'linux') {
227227
reject(err || new Error(stderr.toString()));
228228
} else {
229-
const cmd = JSON.stringify(FileAccess.asFileUri('vs/base/node/ps.sh', require).fsPath);
229+
const cmd = JSON.stringify(FileAccess.asFileUri('vs/base/node/ps.sh').fsPath);
230230
exec(cmd, {}, (err, stdout, stderr) => {
231231
if (err || stderr) {
232232
reject(err || new Error(stderr.toString()));

src/vs/base/test/common/network.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ suite('network', () => {
3030
});
3131

3232
(isWeb ? test.skip : test)('FileAccess: moduleId (native)', () => {
33-
const browserUri = FileAccess.asBrowserUri('vs/base/test/node/network.test', require);
33+
const browserUri = FileAccess.asBrowserUri('vs/base/test/node/network.test');
3434
assert.strictEqual(browserUri.scheme, Schemas.vscodeFileResource);
3535

36-
const fileUri = FileAccess.asFileUri('vs/base/test/node/network.test', require);
36+
const fileUri = FileAccess.asFileUri('vs/base/test/node/network.test');
3737
assert.strictEqual(fileUri.scheme, Schemas.file);
3838
});
3939

src/vs/code/node/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ export async function main(argv: string[]): Promise<any> {
496496
}
497497

498498
function getAppRoot() {
499-
return dirname(FileAccess.asFileUri('', require).fsPath);
499+
return dirname(FileAccess.asFileUri('').fsPath);
500500
}
501501

502502
function eventuallyExit(code: number): void {

src/vs/platform/environment/common/environmentService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron
4444
declare readonly _serviceBrand: undefined;
4545

4646
@memoize
47-
get appRoot(): string { return dirname(FileAccess.asFileUri('', require).fsPath); }
47+
get appRoot(): string { return dirname(FileAccess.asFileUri('').fsPath); }
4848

4949
@memoize
5050
get userHome(): URI { return URI.file(this.paths.homeDir); }
@@ -129,7 +129,7 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron
129129
return resolve(cliBuiltinExtensionsDir);
130130
}
131131

132-
return normalize(join(FileAccess.asFileUri('', require).fsPath, '..', 'extensions'));
132+
return normalize(join(FileAccess.asFileUri('').fsPath, '..', 'extensions'));
133133
}
134134

135135
get extensionsDownloadLocation(): URI {

src/vs/platform/extensionManagement/common/extensionsScannerService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export abstract class AbstractExtensionsScannerService extends Disposable implem
355355
this.logService.trace('Started scanning dev system extensions');
356356
const builtinExtensionControl = checkControlFile ? await this.getBuiltInExtensionControl() : {};
357357
const devSystemExtensionsLocations: URI[] = [];
358-
const devSystemExtensionsLocation = URI.file(path.normalize(path.join(FileAccess.asFileUri('', require).fsPath, '..', '.build', 'builtInExtensions')));
358+
const devSystemExtensionsLocation = URI.file(path.normalize(path.join(FileAccess.asFileUri('').fsPath, '..', '.build', 'builtInExtensions')));
359359
for (const extension of devSystemExtensionsList) {
360360
const controlState = builtinExtensionControl[extension.name] || 'marketplace';
361361
switch (controlState) {

src/vs/platform/extensions/electron-main/extensionHostStarter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class ExtensionHostProcess extends Disposable {
309309
}
310310
const sw = StopWatch.create(false);
311311
this._process = fork(
312-
FileAccess.asFileUri('bootstrap-fork', require).fsPath,
312+
FileAccess.asFileUri('bootstrap-fork').fsPath,
313313
['--type=extensionHost', '--skipWorkspaceStorageLock'],
314314
mixin({ cwd: cwd() }, opts),
315315
);
@@ -434,7 +434,7 @@ class UtilityExtensionHostProcess extends Disposable {
434434
}
435435

436436
const serviceName = `extensionHost${this.id}`;
437-
const modulePath = FileAccess.asFileUri('bootstrap-fork.js', require).fsPath;
437+
const modulePath = FileAccess.asFileUri('bootstrap-fork.js').fsPath;
438438
const args: string[] = ['--type=extensionHost', '--skipWorkspaceStorageLock'];
439439
const execArgv: string[] = opts.execArgv || [];
440440
const env: { [key: string]: any } = { ...opts.env };

src/vs/platform/externalTerminal/node/externalTerminalService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class MacExternalTerminalService extends ExternalTerminalService implemen
133133
// and then launches the program inside that window.
134134

135135
const script = terminalApp === DEFAULT_TERMINAL_OSX ? 'TerminalHelper' : 'iTermHelper';
136-
const scriptpath = FileAccess.asFileUri(`vs/workbench/contrib/externalTerminal/node/${script}.scpt`, require).fsPath;
136+
const scriptpath = FileAccess.asFileUri(`vs/workbench/contrib/externalTerminal/node/${script}.scpt`).fsPath;
137137

138138
const osaArgs = [
139139
scriptpath,

src/vs/platform/files/node/watcher/watcherClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class UniversalWatcherClient extends AbstractUniversalWatcherClient {
2626
// Fork the universal file watcher and build a client around
2727
// its server for passing over requests and receiving events.
2828
const client = disposables.add(new Client(
29-
FileAccess.asFileUri('bootstrap-fork', require).fsPath,
29+
FileAccess.asFileUri('bootstrap-fork').fsPath,
3030
{
3131
serverName: 'File Watcher',
3232
args: ['--type=fileWatcher'],

src/vs/platform/issue/electron-main/issueMainService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class IssueMainService implements IIssueMainService {
228228
});
229229

230230
this.issueReporterWindow.loadURL(
231-
FileAccess.asBrowserUri(`vs/code/electron-sandbox/issue/issueReporter${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true)
231+
FileAccess.asBrowserUri(`vs/code/electron-sandbox/issue/issueReporter${this.environmentMainService.isBuilt ? '' : '-dev'}.html`).toString(true)
232232
);
233233

234234
this.issueReporterWindow.on('close', () => {
@@ -279,7 +279,7 @@ export class IssueMainService implements IIssueMainService {
279279
});
280280

281281
this.processExplorerWindow.loadURL(
282-
FileAccess.asBrowserUri(`vs/code/electron-sandbox/processExplorer/processExplorer${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true)
282+
FileAccess.asBrowserUri(`vs/code/electron-sandbox/processExplorer/processExplorer${this.environmentMainService.isBuilt ? '' : '-dev'}.html`).toString(true)
283283
);
284284

285285
this.processExplorerWindow.on('close', () => {
@@ -325,7 +325,7 @@ export class IssueMainService implements IIssueMainService {
325325
title: options.title,
326326
backgroundColor: options.backgroundColor || IssueMainService.DEFAULT_BACKGROUND_COLOR,
327327
webPreferences: {
328-
preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js', require).fsPath,
328+
preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js').fsPath,
329329
additionalArguments: [`--vscode-window-config=${ipcObjectUrl.resource.toString()}`, `--vscode-window-kind=${windowKind}`],
330330
v8CacheOptions: this.environmentMainService.useCodeCache ? 'bypassHeatCheck' : 'none',
331331
enableWebSQL: false,

0 commit comments

Comments
 (0)