Skip to content

Commit 891c995

Browse files
authored
feat: arrange the correct order for evaluating expo transitive dependencies (#238)
* feat: move expo publishing helper to main afterEvaluate block in order * feat: only add compile scoped dependencies * feat: only add api and implementation configuration dependencies * feat: use getByName to reduce array operations * fix: indentation and unused import * fix: pr comments * fix: account for variant specific configurations
1 parent 8b99d0b commit 891c995

File tree

3 files changed

+50
-65
lines changed

3 files changed

+50
-65
lines changed

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/expo/ExpoPublishingHelper.kt

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.callstack.react.brownfield.expo.utils.DependencyInfo
77
import com.callstack.react.brownfield.expo.utils.ExpoGradleProjectProjection
88
import com.callstack.react.brownfield.expo.utils.VersionMediatingDependencySet
99
import com.callstack.react.brownfield.expo.utils.asExpoGradleProjectProjection
10-
import com.callstack.react.brownfield.plugin.RNBrownfieldPlugin.Companion.EXPO_PROJECT_LOCATOR
1110
import com.callstack.react.brownfield.shared.Constants
1211
import com.callstack.react.brownfield.shared.Logging
1312
import groovy.json.JsonOutput
@@ -30,39 +29,35 @@ fun Node.getChildNodeByName(nodeName: String): Node? {
3029
}
3130
}
3231

33-
open class ExpoPublishingHelper(val brownfieldAppProject: Project, val expoProject: Project) {
34-
fun configure() {
35-
brownfieldAppProject.evaluationDependsOn(EXPO_PROJECT_LOCATOR)
32+
open class ExpoPublishingHelper(val brownfieldAppProject: Project) {
33+
fun afterEvaluate() {
34+
val discoverableExpoProjects = getDiscoverableExpoProjects()
3635

37-
brownfieldAppProject.afterEvaluate {
38-
val discoverableExpoProjects = getDiscoverableExpoProjects()
36+
Logging.log(
37+
"Discovered ${discoverableExpoProjects.size} discoverable Expo projects: " +
38+
discoverableExpoProjects.joinToString(
39+
", ",
40+
) { it.name },
41+
)
3942

40-
Logging.log(
41-
"Discovered ${discoverableExpoProjects.size} discoverable Expo projects: " +
42-
discoverableExpoProjects.joinToString(
43-
", ",
44-
) { it.name },
43+
val expoTransitiveDependencies =
44+
discoverAllExpoTransitiveDependencies(
45+
expoProjects = discoverableExpoProjects,
4546
)
4647

47-
val expoTransitiveDependencies =
48-
discoverAllExpoTransitiveDependencies(
49-
expoProjects = discoverableExpoProjects,
50-
)
51-
48+
Logging.log(
49+
"Collected a total of ${expoTransitiveDependencies.size} unique Expo transitive " +
50+
"dependencies for brownfield app project publishing",
51+
)
52+
expoTransitiveDependencies.forEach {
5253
Logging.log(
53-
"Collected a total of ${expoTransitiveDependencies.size} unique Expo transitive " +
54-
"dependencies for brownfield app project publishing",
54+
"(*) dependency ${it.groupId}:${it.artifactId}:${it.version} (scope: ${it.scope}, " +
55+
"${if (it.optional) "optional" else "required"})",
5556
)
56-
expoTransitiveDependencies.forEach {
57-
Logging.log(
58-
"(*) dependency ${it.groupId}:${it.artifactId}:${it.version} (scope: ${it.scope}, " +
59-
"${if (it.optional) "optional" else "required"})",
60-
)
61-
}
62-
63-
reconfigurePOM(expoTransitiveDependencies)
64-
reconfigureGradleModuleJSON(expoTransitiveDependencies)
6557
}
58+
59+
reconfigurePOM(expoTransitiveDependencies)
60+
reconfigureGradleModuleJSON(expoTransitiveDependencies)
6661
}
6762

6863
protected fun shouldExcludeDependency(
@@ -356,14 +351,18 @@ open class ExpoPublishingHelper(val brownfieldAppProject: Project, val expoProje
356351
) {
357352
dependenciesNodes.forEach { depNodeList ->
358353
depNodeList.childNodes.forEach { depNode ->
359-
// below: some nodes are not dependencies, but pure text, in which case their name is '#text'
360-
if (depNode.nodeName == "dependency") {
354+
/**
355+
* below: some nodes are not dependencies, but pure text, in which case their name is '#text'
356+
*
357+
* Only add dependencies with compile scope, if scope is null, default to compile
358+
*/
359+
val scope = depNode.getChildNodeByName("scope")?.textContent
360+
if (depNode.nodeName == "dependency" && (scope == null || scope == "compile")) {
361361
val groupId = depNode.getChildNodeByName("groupId")!!.textContent
362362
val maybeArtifactId = depNode.getChildNodeByName("artifactId")
363363

364364
val artifactId = maybeArtifactId!!.textContent
365365
val version = depNode.getChildNodeByName("version")?.textContent
366-
val scope = depNode.getChildNodeByName("scope")?.textContent
367366
val optional = depNode.getChildNodeByName("optional")?.textContent
368367

369368
val dependencyInfo =
@@ -385,38 +384,22 @@ open class ExpoPublishingHelper(val brownfieldAppProject: Project, val expoProje
385384
pkgProject: Project,
386385
dependencies: VersionMediatingDependencySet,
387386
) {
388-
pkgProject.configurations
389-
.filter { cfg ->
390-
setOf(
391-
"test",
392-
"androidTest",
393-
"kapt",
394-
"annotationProcessor",
395-
"lint",
396-
"detached",
397-
).none {
398-
cfg.name.contains(it, ignoreCase = true)
399-
}
400-
}
401-
.filter { cfg ->
402-
setOf("compile", "implementation", "api", "runtime").any {
403-
cfg.name.contains(it, ignoreCase = true)
387+
val configurations = pkgProject.configurations.matching {
388+
it.name.contains("implementation", ignoreCase = true) || it.name.contains("api", ignoreCase = true)
389+
}
390+
configurations.forEach {
391+
it.dependencies.forEach { dep ->
392+
if (dep.group != null) {
393+
dependencies.add(
394+
DependencyInfo.fromGradleDep(
395+
groupId = dep.group!!,
396+
artifactId = dep.name,
397+
version = dep.version,
398+
),
399+
)
404400
}
405401
}
406-
.forEach { cfg ->
407-
cfg.dependencies
408-
.filter { dep ->
409-
dep.group != null
410-
}.forEach { dep ->
411-
dependencies.add(
412-
DependencyInfo.fromGradleDep(
413-
groupId = dep.group!!,
414-
artifactId = dep.name,
415-
version = dep.version,
416-
),
417-
)
418-
}
419-
}
402+
}
420403
}
421404

422405
/**

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/plugin/RNBrownfieldPlugin.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ class RNBrownfieldPlugin
4242
*/
4343
if (this.isExpoProject) {
4444
Logging.log("Expo project detected.")
45-
ExpoPublishingHelper(
46-
brownfieldAppProject = project,
47-
expoProject = maybeExpoProject!!,
48-
).configure()
45+
project.evaluationDependsOn(EXPO_PROJECT_LOCATOR)
4946
}
5047

5148
RNSourceSets.configure(project, extension)
@@ -54,6 +51,12 @@ class RNBrownfieldPlugin
5451

5552
project.afterEvaluate {
5653
afterEvaluate()
54+
55+
if (this.isExpoProject) {
56+
ExpoPublishingHelper(
57+
brownfieldAppProject = project,
58+
).afterEvaluate()
59+
}
5760
}
5861
}
5962

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/Constants.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.callstack.react.brownfield.shared
22

33
import com.callstack.react.brownfield.expo.utils.DependencyInfo
44
import com.callstack.react.brownfield.utils.StringMatcher
5-
import io.github.g00fy2.versioncompare.Version
65

76
/**
87
* A condition that checks if a certain Expo version meets specific criteria

0 commit comments

Comments
 (0)