Skip to content

Commit

Permalink
RNGP - Do not attempt to load JSC from other repositories (#45598)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
cortinico authored and facebook-github-bot committed Jul 23, 2024
1 parent 48f6c3c commit bd4aec8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
}
}
}
}
}
Expand Down Expand Up @@ -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)
}
}
7 changes: 6 additions & 1 deletion packages/rn-tester/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bd4aec8

Please sign in to comment.