Skip to content

Commit d90df28

Browse files
committed
feat: unify approach to expo-updates, downstream from #360
1 parent af1c8fb commit d90df28

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,33 @@ object RNSourceSets {
5555
isDebuggable = variant.debuggable,
5656
)
5757
val capitalizedBundledAssetsVariantName = bundledAssetsVariantName.capitalized()
58+
val appProject = getAppProject()
5859

5960
// 3. Lazily configure the 'variant-specific' source set using .named()
6061
androidExtension.sourceSets.named(variantName) { sourceSet ->
61-
// Paths are collected and added, similar to your improved version
6262
val bundlePathSegments =
6363
listOf(
6464
// outputs for RN <= 0.81
6565
"createBundle${capitalizedBundledAssetsVariantName}JsAndAssets",
6666
// outputs for RN >= 0.82
6767
"react/$bundledAssetsVariantName",
68-
// expo update resources
69-
"create${capitalizedBundledAssetsVariantName}UpdatesResources",
7068
)
69+
val updateResourcesPathSegment = Utils.getExpoUpdatesResourcesTaskName(variant.name)
7170

7271
// Add the variant-specific generated asset and resource directories
7372
val appBuildDir = getAppBuildDir()
7473
sourceSet.assets.srcDirs(bundlePathSegments.map { "$appBuildDir/generated/assets/$it" })
7574
sourceSet.res.srcDirs(bundlePathSegments.map { "$appBuildDir/generated/res/$it" })
7675
sourceSet.jniLibs.srcDirs("libs${variantName.capitalized()}")
76+
if (Utils.hasExpoUpdates(appProject, variant.name)) {
77+
val updateResourcesTask = appProject.tasks.named(updateResourcesPathSegment)
78+
sourceSet.assets.srcDir(
79+
project.files("$appBuildDir/generated/assets/$updateResourcesPathSegment").builtBy(updateResourcesTask),
80+
)
81+
sourceSet.res.srcDir(
82+
project.files("$appBuildDir/generated/res/$updateResourcesPathSegment").builtBy(updateResourcesTask),
83+
)
84+
}
7785
}
7886
}
7987
}

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/processors/VariantTaskProvider.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,9 @@ class VariantTaskProvider(val project: Project) {
9595
preBuildTask.dependsOn("${appProject.path}:createBundle${capitalizedBundledAssetsVariantName}JsAndAssets")
9696

9797
if (Utils.isExpoProject(project)) {
98-
val updatesResourcesTaskName =
99-
"create${capitalizedBundledAssetsVariantName}UpdatesResources"
100-
101-
appProject.tasks
102-
.matching { it.name == updatesResourcesTaskName }
103-
.configureEach { updatesTask ->
104-
preBuildTask.dependsOn(updatesTask)
98+
val updatesResourcesTaskName = Utils.getExpoUpdatesResourcesTaskName(variantName)
99+
if (Utils.hasExpoUpdates(appProject, variantName)) {
100+
preBuildTask.dependsOn("${appProject.path}:$updatesResourcesTaskName")
105101
}
106102
}
107103
}

gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/utils/Utils.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ object Utils {
2828
return project.findProject(EXPO_PROJECT_LOCATOR) != null
2929
}
3030

31+
fun getExpoUpdatesResourcesTaskName(variantName: String): String {
32+
return "create${variantName.capitalized()}UpdatesResources"
33+
}
34+
35+
fun hasExpoUpdates(
36+
project: Project,
37+
variantName: String,
38+
): Boolean {
39+
return isExpoProject(project) &&
40+
project.tasks.names.contains(
41+
getExpoUpdatesResourcesTaskName(variantName),
42+
)
43+
}
44+
3145
fun getBundledAssetsVariantName(
3246
variantName: String?,
3347
buildTypeName: String?,

0 commit comments

Comments
 (0)