From a23705dec3545bced3be17c7642248c1db338c91 Mon Sep 17 00:00:00 2001 From: Jakub Romanczyk Date: Fri, 13 Dec 2024 11:27:24 +0100 Subject: [PATCH] fix: resolve junctions on Windows --- packages/sdk/android/resolveNodePackage.gradle | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/sdk/android/resolveNodePackage.gradle b/packages/sdk/android/resolveNodePackage.gradle index 72d41f8..29522e3 100644 --- a/packages/sdk/android/resolveNodePackage.gradle +++ b/packages/sdk/android/resolveNodePackage.gradle @@ -1,17 +1,21 @@ // source: https://github.com/facebook/react-native/pull/39520 // TODO remove in the future when this lands in RN +// modified to better support resolving symlinks(junctions) on Windows + +import java.nio.file.* ext.resolveNodePackage = { String packageName, File startDir -> - def candidate = new File(startDir, "node_modules/$packageName") + def startPath = startDir.toPath() + def candidate = startPath.resolve("node_modules").resolve(packageName) - if (candidate.exists()) { - return candidate.canonicalFile + if (Files.exists(candidate)) { + return candidate.toRealPath().toFile() } - def parentDir = startDir.parentFile - if (parentDir == null || startDir.canonicalPath == parentDir.canonicalPath) { + def parentDir = startPath.parent + if (parentDir == null || startPath.toRealPath() == parentDir.toRealPath()) { throw new GradleException("Failed to find the package '$packageName'. Ensure you have installed node_modules.") } - return resolveNodePackage(packageName, parentDir) + return resolveNodePackage(packageName, parentDir.toFile()) } \ No newline at end of file