Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/core/src/utils/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,22 @@ describe('resolveToRealPath', () => {
expect(resolveToRealPath(input)).toBe(expected);
});

it('should return decoded path even if fs.realpathSync fails with EISDIR', () => {
vi.spyOn(fs, 'realpathSync').mockImplementationOnce(() => {
const err = new Error(
'Illegal operation on a directory',
) as NodeJS.ErrnoException;
err.code = 'EISDIR';
throw err;
});

const p = path.resolve('path', 'to', 'New Project');
const input = pathToFileURL(p).toString();
const expected = p;

expect(resolveToRealPath(input)).toBe(expected);
});

it('should recursively resolve symlinks for non-existent child paths', () => {
const parentPath = path.resolve('/some/parent/path');
const resolvedParentPath = path.resolve('/resolved/parent/path');
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,12 @@ function robustRealpath(p: string, visited = new Set<string>()): string {
try {
return fs.realpathSync(p);
} catch (e: unknown) {
if (e && typeof e === 'object' && 'code' in e && e.code === 'ENOENT') {
if (
e &&
typeof e === 'object' &&
'code' in e &&
(e.code === 'ENOENT' || e.code === 'EISDIR')
) {
try {
const stat = fs.lstatSync(p);
if (stat.isSymbolicLink()) {
Expand All @@ -400,7 +405,7 @@ function robustRealpath(p: string, visited = new Set<string>()): string {
lstatError &&
typeof lstatError === 'object' &&
'code' in lstatError &&
lstatError.code === 'ENOENT'
(lstatError.code === 'ENOENT' || lstatError.code === 'EISDIR')
)
) {
throw lstatError;
Expand Down
Loading