From ccfc09d82c3cbc7e03ed293174f287c54439e908 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Tue, 16 Aug 2022 12:09:47 -0700 Subject: [PATCH] Cherry-pick PR #50306 into release-4.8 (#50324) Component commits: b73d93bf2a On windows handle the long paths in realpathSync.native Fixes #49470 Co-authored-by: Sheetal Nandi --- src/compiler/sys.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index e293932b0b463..b0cc058fd93bf 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1440,7 +1440,7 @@ namespace ts { const platform: string = _os.platform(); const useCaseSensitiveFileNames = isFileSystemCaseSensitive(); - const realpathSync = _fs.realpathSync.native ?? _fs.realpathSync; + const fsRealpath = !!_fs.realpathSync.native ? process.platform === "win32" ? fsRealPathHandlingLongPath : _fs.realpathSync.native : _fs.realpathSync; const fsSupportsRecursiveFsWatch = isNode4OrLater && (process.platform === "win32" || process.platform === "darwin"); const getCurrentDirectory = memoize(() => process.cwd()); @@ -1889,9 +1889,13 @@ namespace ts { return getAccessibleFileSystemEntries(path).directories.slice(); } + function fsRealPathHandlingLongPath(path: string): string { + return path.length < 260 ? _fs.realpathSync.native(path) : _fs.realpathSync(path); + } + function realpath(path: string): string { try { - return realpathSync(path); + return fsRealpath(path); } catch { return path;