RNGP - Do not attempt to load JSC from other repositories (#45598)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45598

I've noticed we attempt to load JSC from the Sonatype Snapshot repository.
That is inefficient as we already know that JSC is available only inside node modules.
This change makes the repository resolution stricter by better specifying which
repo can download which dependency.

Changelog:
[Internal] [Changed] - Do not attempt to load JSC from other repositories

Reviewed By: cipolleschi

Differential Revision: D60116002

fbshipit-source-id: 21a2213708f5b0103860a59f3342f1bc0f59cdb9
This commit is contained in:
Nicola Corti
2024-07-23 08:12:42 -07:00
committed by Facebook GitHub Bot
parent 48f6c3c485
commit bd4aec869b
2 changed files with 46 additions and 11 deletions
@@ -29,13 +29,17 @@ internal object DependencyUtils {
with(eachProject) {
if (hasProperty(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO)) {
val mavenLocalRepoPath = property(INTERNAL_REACT_NATIVE_MAVEN_LOCAL_REPO) as String
mavenRepoFromURI(File(mavenLocalRepoPath).toURI())
mavenRepoFromURI(File(mavenLocalRepoPath).toURI()) { repo ->
repo.content { it.excludeGroup("org.webkit") }
}
}
// We add the snapshot for users on nightlies.
mavenRepoFromUrl("https://oss.sonatype.org/content/repositories/snapshots/")
mavenRepoFromUrl("https://oss.sonatype.org/content/repositories/snapshots/") { repo ->
repo.content { it.excludeGroup("org.webkit") }
}
repositories.mavenCentral { repo ->
// We don't want to fetch JSC from Maven Central as there are older versions there.
repo.content { it.excludeModule("org.webkit", "android-jsc") }
repo.content { it.excludeGroup("org.webkit") }
// If the user provided a react.internal.mavenLocalRepo, do not attempt to load
// anything from Maven Central that is react related.
@@ -44,9 +48,23 @@ internal object DependencyUtils {
}
}
// Android JSC is installed from npm
mavenRepoFromURI(File(reactNativeDir, "../jsc-android/dist").toURI())
repositories.google()
mavenRepoFromUrl("https://www.jitpack.io")
mavenRepoFromURI(File(reactNativeDir, "../jsc-android/dist").toURI()) { repo ->
repo.content { it.includeGroup("org.webkit") }
}
repositories.google { repo ->
repo.content {
// We don't want to fetch JSC or React from Google
it.excludeGroup("org.webkit")
it.excludeGroup("com.facebook.react")
}
}
mavenRepoFromUrl("https://www.jitpack.io") { repo ->
repo.content {
// We don't want to fetch JSC or React from JitPack
it.excludeGroup("org.webkit")
it.excludeGroup("com.facebook.react")
}
}
}
}
}
@@ -134,9 +152,21 @@ internal object DependencyUtils {
return Pair(versionString, groupString)
}
fun Project.mavenRepoFromUrl(url: String): MavenArtifactRepository =
project.repositories.maven { it.url = URI.create(url) }
fun Project.mavenRepoFromUrl(
url: String,
action: (MavenArtifactRepository) -> Unit = {}
): MavenArtifactRepository =
project.repositories.maven {
it.url = URI.create(url)
action(it)
}
fun Project.mavenRepoFromURI(uri: URI): MavenArtifactRepository =
project.repositories.maven { it.url = uri }
fun Project.mavenRepoFromURI(
uri: URI,
action: (MavenArtifactRepository) -> Unit = {}
): MavenArtifactRepository =
project.repositories.maven {
it.url = uri
action(it)
}
}
@@ -84,7 +84,12 @@ fun reactNativeArchitectures(): List<String> {
return value?.toString()?.split(",") ?: listOf("armeabi-v7a", "x86", "x86_64", "arm64-v8a")
}
repositories { maven { url = rootProject.file("node_modules/jsc-android/dist").toURI() } }
repositories {
maven {
url = rootProject.file("node_modules/jsc-android/dist").toURI()
content { includeGroup("org.webkit") }
}
}
android {
compileSdk = libs.versions.compileSdk.get().toInt()