diff --git a/packages/core/src/utils/paths.test.ts b/packages/core/src/utils/paths.test.ts index 09b58d4187..bf19f8b644 100644 --- a/packages/core/src/utils/paths.test.ts +++ b/packages/core/src/utils/paths.test.ts @@ -601,6 +601,22 @@ describe('resolveToRealPath', () => { /Infinite recursion detected/, ); }); + + it('should return path as-is if fs.realpathSync and fs.lstatSync fail with ENAMETOOLONG', () => { + vi.spyOn(fs, 'realpathSync').mockImplementation(() => { + const err = new Error('File name too long') as NodeJS.ErrnoException; + err.code = 'ENAMETOOLONG'; + throw err; + }); + vi.spyOn(fs, 'lstatSync').mockImplementation(() => { + const err = new Error('File name too long') as NodeJS.ErrnoException; + err.code = 'ENAMETOOLONG'; + throw err; + }); + + const longPath = path.resolve('a'.repeat(5000)); + expect(resolveToRealPath(longPath)).toBe(longPath); + }); }); describe('makeRelative', () => { diff --git a/packages/core/src/utils/paths.ts b/packages/core/src/utils/paths.ts index dae7c5c4e8..169bf73251 100644 --- a/packages/core/src/utils/paths.ts +++ b/packages/core/src/utils/paths.ts @@ -424,7 +424,7 @@ function robustRealpath(p: string, visited = new Set()): string { e && typeof e === 'object' && 'code' in e && - (e.code === 'ENOENT' || e.code === 'EISDIR') + (e.code === 'ENOENT' || e.code === 'EISDIR' || e.code === 'ENAMETOOLONG') ) { try { const stat = fs.lstatSync(p); @@ -435,13 +435,15 @@ function robustRealpath(p: string, visited = new Set()): string { } } catch (lstatError: unknown) { // Not a symlink, or lstat failed. Re-throw if it's not an expected - // ENOENT (e.g., a permissions error), otherwise resolve parent. + // error (e.g., a permissions error), otherwise resolve parent. if ( !( lstatError && typeof lstatError === 'object' && 'code' in lstatError && - (lstatError.code === 'ENOENT' || lstatError.code === 'EISDIR') + (lstatError.code === 'ENOENT' || + lstatError.code === 'EISDIR' || + lstatError.code === 'ENAMETOOLONG') ) ) { throw lstatError;