Skip to content

Commit f502126

Browse files
committed
Abstracts realpath handling for browser and Node environments
(#1328) Introduces environment-specific implementations for resolving real file system paths, enabling the codebase to handle symlink resolution in Node.js while providing a placeholder for browsers.
1 parent 48ce1f7 commit f502126

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/env/browser/realpath.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function realpath(_path: string): Promise<string> {
2+
// Most likely clients of this function will check for `not-isWeb` before calling,
3+
// So we probably should never get here.
4+
// But even if we do, cliens should be ready to handle errors of path resolving.
5+
return Promise.reject(new Error('Not implemented'));
6+
}

src/env/node/realpath.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { realpath as fs_realpath } from 'fs';
2+
import { promisify } from 'util';
3+
4+
export function realpath(path: string): Promise<string> {
5+
return promisify(fs_realpath)(path);
6+
}

src/git/gitUri.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Uri } from 'vscode';
22
import { isWeb } from '@env/platform';
3+
import { realpath } from '@env/realpath';
34
import { getQueryDataFromScmGitUri } from '../@types/vscode.git.uri';
45
import { Schemes } from '../constants';
56
import { Container } from '../container';
@@ -254,8 +255,7 @@ export class GitUri extends (Uri as any as UriEx) {
254255
// Check for symbolic links (Node.js only)
255256
if (configuration.get('advanced.realpath') && !isWeb && uri.scheme === 'file') {
256257
try {
257-
const { realpathSync } = await import('fs');
258-
const realPath = realpathSync(uri.fsPath);
258+
const realPath = await realpath(uri.fsPath);
259259
if (uri.fsPath !== realPath) {
260260
const newUri = Uri.file(realPath);
261261
return await this.fromUri(newUri);

0 commit comments

Comments
 (0)