react-native-keys icon indicating copy to clipboard operation
react-native-keys copied to clipboard

fix: 🐛 Check if a path(basePath) exists on Android, RN >= 0.80

Open tconns opened this issue 4 months ago • 9 comments

Summary

Because RN >= 0.80 has extracted the example out of the core

Changelog

Test Plan

tconns avatar Aug 05 '25 08:08 tconns

You should do a check before, if the previous path are not available, then you use the new path. Otherwise it will be compatible only with the newer version of RN.

But the check just above was already working with RN versions below 0.80, wasn’t it?

tconns avatar Aug 05 '25 23:08 tconns

@tconns your fix seems wrong

it should be

reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
if (!reactNativeDir.toFile().exists()) {
  reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/ReactAndroid")
}

ildfreelancer avatar Aug 06 '25 04:08 ildfreelancer

i also agree with @ildfreelancer

numandev1 avatar Aug 06 '25 07:08 numandev1

@dougg0k I sent you an invite on GitHub, can you check?

numandev1 avatar Aug 06 '25 10:08 numandev1

Thanks @numandev1 but I am good as collab / contrib only, when I can.

dougg0k avatar Aug 06 '25 12:08 dougg0k

The current impl are weird, even though the first are being used for the project, a different path is used for the example project.

Then it's checked again for the actual node_modules. It seem to contain duplication in there.

https://github.com/numandev1/react-native-keys/blob/main/android/build.gradle#L85


Perhaps it should be.

// Find node_modules inside the example project
def nodeModulesDir = Paths.get(basePath.toString(), "node_modules")
def reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
if (!reactNativeDir.toFile().exists()) {
  reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/ReactAndroid")
}
if (nodeModulesDir.toFile().exists() && reactNativeDir.toFile().exists()) {
  found = true
}

Removing


if(!found){
  // Node's module resolution algorithm searches up to the root directory,
  // after which the base path will be null
  while (basePath) {
    nodeModulesDir = Paths.get(basePath.toString(), "node_modules")
    reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
    if (nodeModulesDir.toFile().exists() && reactNativeDir.toFile().exists()) {
      found = true
      break;
    }
    basePath = basePath.getParent()
  }
}

Since the example project should have no ties to the project. But it's own android folder.

dougg0k avatar Aug 09 '25 20:08 dougg0k

Just as an interesting note: when I approved this PR https://github.com/numandev1/react-native-keys/pull/102, I made a mistake and applied my own patch to the exact same lines that are changed in this current PR. Now that I've updated rn-keys to 0.7.12 and removed my patch, it's broken again. So it turns out that this diff is actually correct and functional:


if(!found){
  // Node's module resolution algorithm searches up to the root directory,
  // after which the base path will be null
  while (basePath) {
    nodeModulesDir = Paths.get(basePath.toString(), "node_modules")
    reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
    if (nodeModulesDir.toFile().exists() && reactNativeDir.toFile().exists()) {
      found = true
      break;
    }
    basePath = basePath.getParent()
  }
}

And the previous PR (https://github.com/numandev1/react-native-keys/pull/102) should be rolled back.

JerakRus avatar Aug 28 '25 16:08 JerakRus

functional are not necessarily correct, but just functional.

that is functional because before that, it is considering the supposed example project, but it should have no need.

dougg0k avatar Aug 28 '25 17:08 dougg0k

What is probably missing here due to the example project is another check of the same, done in my PR for newer RN versions.

https://github.com/numandev1/react-native-keys/issues/118

https://github.com/numandev1/react-native-keys/blob/main/android/build.gradle#L96 https://github.com/numandev1/react-native-keys/blob/main/android/build.gradle#L84

dougg0k avatar Aug 30 '25 14:08 dougg0k