From 6fa8f07827e9ff4ae23c6f8673d6295d90a919d8 Mon Sep 17 00:00:00 2001 From: Salman Muin Kayser Chishti Date: Thu, 16 Oct 2025 13:52:43 +0100 Subject: [PATCH] Update based on testing to add trailing back slash to all results --- packages/io/src/io-util.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/io/src/io-util.ts b/packages/io/src/io-util.ts index 67bae805..31391e36 100644 --- a/packages/io/src/io-util.ts +++ b/packages/io/src/io-util.ts @@ -19,22 +19,23 @@ export const { export const IS_WINDOWS = process.platform === 'win32' /** - * Custom implementation of readlink to ensure Windows directory symlinks + * Custom implementation of readlink to ensure Windows junctions * maintain trailing backslash for backward compatibility with Node.js < 24 + * + * In Node.js 20, Windows junctions (directory symlinks) always returned paths + * with trailing backslashes. Node.js 24 removed this behavior, which breaks + * code that relied on this format for path operations. + * + * This implementation restores the Node 20 behavior by adding a trailing + * backslash to all junction results on Windows. */ export async function readlink(fsPath: string): Promise { const result = await fs.promises.readlink(fsPath) - // Only on Windows, ensure directory symlinks end with a backslash - if (IS_WINDOWS) { - try { - const stats = await fs.promises.lstat(result) - if (stats.isDirectory() && !result.endsWith('\\')) { - return `${result}\\` - } - } catch (err) { - // If we can't access the target, just return the original result - } + // On Windows, restore Node 20 behavior: add trailing backslash to all results + // since junctions on Windows are always directory links + if (IS_WINDOWS && !result.endsWith('\\')) { + return `${result}\\` } return result