Update based on testing to add trailing back slash to all results
This commit is contained in:
+12
-11
@@ -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<string> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user