mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RNGP - Filter out null dependencies from getGradleDependenciesToApply (#45749)
Summary: `getGradleDependenciesToApply` tries to call `implementation:` in all libraries, including the ones that are not supported on Android. ## Changelog: [INTERNAL] [FIXED] - Filter out platform-specific libraries from the auto-linking gradle plugin Pull Request resolved: https://github.com/facebook/react-native/pull/45749 Test Plan: CI should be green Reviewed By: cipolleschi Differential Revision: D60374769 Pulled By: cortinico fbshipit-source-id: 33c83e9cc39d81b0e5c497570a936831ebb345f9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3c63793cba
commit
af2cdcb752
+16
-12
@@ -184,19 +184,23 @@ abstract class ReactExtension @Inject constructor(val project: Project) {
|
||||
internal fun getGradleDependenciesToApply(inputFile: File): MutableList<Pair<String, String>> {
|
||||
val model = JsonUtils.fromAutolinkingConfigJson(inputFile)
|
||||
val result = mutableListOf<Pair<String, String>>()
|
||||
model?.dependencies?.values?.forEach { deps ->
|
||||
val nameCleansed = deps.nameCleansed
|
||||
val dependencyConfiguration = deps.platforms?.android?.dependencyConfiguration
|
||||
val buildTypes = deps.platforms?.android?.buildTypes ?: emptyList()
|
||||
if (buildTypes.isEmpty()) {
|
||||
result.add((dependencyConfiguration ?: "implementation") to ":$nameCleansed")
|
||||
} else {
|
||||
buildTypes.forEach { buildType ->
|
||||
result.add(
|
||||
(dependencyConfiguration ?: "${buildType}Implementation") to ":$nameCleansed")
|
||||
model
|
||||
?.dependencies
|
||||
?.values
|
||||
?.filter { it.platforms?.android !== null }
|
||||
?.forEach { deps ->
|
||||
val nameCleansed = deps.nameCleansed
|
||||
val dependencyConfiguration = deps.platforms?.android?.dependencyConfiguration
|
||||
val buildTypes = deps.platforms?.android?.buildTypes ?: emptyList()
|
||||
if (buildTypes.isEmpty()) {
|
||||
result.add((dependencyConfiguration ?: "implementation") to ":$nameCleansed")
|
||||
} else {
|
||||
buildTypes.forEach { buildType ->
|
||||
result.add(
|
||||
(dependencyConfiguration ?: "${buildType}Implementation") to ":$nameCleansed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
+42
-12
@@ -8,8 +8,8 @@
|
||||
package com.facebook.react
|
||||
|
||||
import com.facebook.react.ReactExtension.Companion.getGradleDependenciesToApply
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
@@ -30,7 +30,7 @@ class ReactExtensionTest {
|
||||
.trimIndent())
|
||||
|
||||
val deps = getGradleDependenciesToApply(validJsonFile)
|
||||
assertEquals(0, deps.size)
|
||||
assertThat(deps).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,8 +57,7 @@ class ReactExtensionTest {
|
||||
.trimIndent())
|
||||
|
||||
val deps = getGradleDependenciesToApply(validJsonFile)
|
||||
assertEquals(1, deps.size)
|
||||
assertTrue("implementation" to ":react-native_oss-library-example" in deps)
|
||||
assertThat(deps).containsExactly("implementation" to ":react-native_oss-library-example")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,8 +85,7 @@ class ReactExtensionTest {
|
||||
.trimIndent())
|
||||
|
||||
val deps = getGradleDependenciesToApply(validJsonFile)
|
||||
assertEquals(1, deps.size)
|
||||
assertTrue("compileOnly" to ":react-native_oss-library-example" in deps)
|
||||
assertThat(deps).containsExactly("compileOnly" to ":react-native_oss-library-example")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,9 +113,10 @@ class ReactExtensionTest {
|
||||
.trimIndent())
|
||||
|
||||
val deps = getGradleDependenciesToApply(validJsonFile)
|
||||
assertEquals(2, deps.size)
|
||||
assertTrue("debugImplementation" to ":react-native_oss-library-example" in deps)
|
||||
assertTrue("releaseImplementation" to ":react-native_oss-library-example" in deps)
|
||||
assertThat(deps)
|
||||
.containsExactly(
|
||||
"debugImplementation" to ":react-native_oss-library-example",
|
||||
"releaseImplementation" to ":react-native_oss-library-example")
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,9 +153,40 @@ class ReactExtensionTest {
|
||||
.trimIndent())
|
||||
|
||||
val deps = getGradleDependenciesToApply(validJsonFile)
|
||||
assertEquals(2, deps.size)
|
||||
assertTrue("implementation" to ":react-native_oss-library-example" in deps)
|
||||
assertTrue("implementation" to ":react-native_another-library-for-testing" in deps)
|
||||
assertThat(deps)
|
||||
.containsExactly(
|
||||
"implementation" to ":react-native_oss-library-example",
|
||||
"implementation" to ":react-native_another-library-for-testing")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getGradleDependenciesToApply_withiOSOnlyLibrary_returnsEmptyDepsMap() {
|
||||
val validJsonFile =
|
||||
createJsonFile(
|
||||
"""
|
||||
{
|
||||
"reactNativeVersion": "1000.0.0",
|
||||
"dependencies": {
|
||||
"@react-native/oss-library-example": {
|
||||
"root": "./node_modules/@react-native/oss-library-example",
|
||||
"name": "@react-native/oss-library-example",
|
||||
"platforms": {
|
||||
"ios": {
|
||||
"podspecPath": "./node_modules/@react-native/oss-library-example/oss-library-example.podspec",
|
||||
"version": "0.0.0",
|
||||
"configurations": [],
|
||||
"scriptPhases": []
|
||||
},
|
||||
"android": null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
|
||||
val deps = getGradleDependenciesToApply(validJsonFile)
|
||||
assertThat(deps).isEmpty()
|
||||
}
|
||||
|
||||
private fun createJsonFile(@Language("JSON") input: String) =
|
||||
|
||||
Reference in New Issue
Block a user