@callstack/react-native-brownfield 5.0.2 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeBrownfield.kt +47 -4
- package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeFragment.kt +23 -1
- package/gradle-plugin/brownfield/build.gradle.kts +7 -0
- package/gradle-plugin/brownfield/gradle/libs.versions.toml +2 -0
- package/gradle-plugin/brownfield/gradle.properties +1 -1
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/artifacts/RncTransitiveDependencyDiscoverer.kt +96 -0
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/expo/ExpoPublishingHelper.kt +10 -214
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/expo/utils/BrownfieldPublishingInfo.kt +7 -0
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/plugin/RNBrownfieldPlugin.kt +92 -1
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/Constants.kt +12 -1
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/{expo/utils/BrownfieldPrimitives.kt → shared/DependencyInfo.kt} +3 -8
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/DependencyPublishability.kt +22 -0
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/GradleDependencyCollector.kt +44 -0
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjector.kt +181 -0
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/TransitiveDependencyFiltering.kt +17 -0
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/{expo/utils → shared}/VersionMediatingDependencySet.kt +1 -1
- package/gradle-plugin/brownfield/src/main/kotlin/com/callstack/react/brownfield/utils/Extension.kt +11 -0
- package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/artifacts/RncTransitiveDependencyDiscovererTest.kt +171 -0
- package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/expo/ExpoPublishingHelperGradleFallbackTest.kt +47 -0
- package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/plugin/LegacyConsumerConfigurationTest.kt +110 -0
- package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/DependencyPublishabilityTest.kt +67 -0
- package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjectorTest.kt +222 -0
- package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/TransitiveDependencyFilteringTest.kt +37 -0
- package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/VersionMediatingDependencySetTest.kt +42 -0
- package/gradle-plugin/brownfield/src/test/kotlin/com/callstack/react/brownfield/utils/ExtensionTest.kt +11 -0
- package/ios/BrownfieldReactHostPreloader.h +30 -0
- package/ios/BrownfieldReactHostPreloader.m +113 -0
- package/ios/BrownfieldSurfaceRegistry.swift +93 -0
- package/ios/Expo/ExpoHostRuntime.swift +70 -8
- package/ios/JSBundleLoadObserver.swift +64 -17
- package/ios/ReactHostPreloading.swift +177 -0
- package/ios/ReactNativeBrownfield.swift +36 -1
- package/ios/Vanilla/ReactNativeHostRuntime.swift +28 -6
- package/ios/Views/ReactNativeView.swift +34 -5
- package/ios/Views/ReactNativeViewController.swift +120 -1
- package/lib/commonjs/expo-config-plugin/android/utils/constants.js +1 -1
- package/lib/commonjs/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +6 -1
- package/lib/module/expo-config-plugin/android/utils/constants.js +1 -1
- package/lib/module/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +6 -1
- package/lib/typescript/commonjs/src/expo-config-plugin/android/utils/constants.d.ts +2 -2
- package/lib/typescript/module/src/expo-config-plugin/android/utils/constants.d.ts +2 -2
- package/package.json +2 -2
- package/src/expo-config-plugin/android/utils/constants.ts +1 -1
- package/src/expo-config-plugin/template/android/ReactNativeHostManager.post55.kt +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @callstack/react-native-brownfield
|
|
2
2
|
|
|
3
|
+
## 5.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#458](https://github.com/callstack/react-native-brownfield/pull/458) [`bf976fd`](https://github.com/callstack/react-native-brownfield/commit/bf976fdebc1abb228c03213c9a1b41d9967d0909) Thanks [@KisaneNeko](https://github.com/KisaneNeko)! - Bump the Brownfield Gradle Plugin version injected by the Expo config plugin to `2.0.0-alpha09`.
|
|
8
|
+
|
|
9
|
+
- [#462](https://github.com/callstack/react-native-brownfield/pull/462) [`2f7d5da`](https://github.com/callstack/react-native-brownfield/commit/2f7d5daf661808fdfdd1caae89236dbdfec3f62e) Thanks [@likevy](https://github.com/likevy)! - fixes [#457](https://github.com/callstack/react-native-brownfield/issues/457), android back callbacks survived RN fragment view destruction, retaining delegates and intercepting back presses after re-entry
|
|
10
|
+
|
|
11
|
+
- [#470](https://github.com/callstack/react-native-brownfield/pull/470) [`09162c2`](https://github.com/callstack/react-native-brownfield/commit/09162c27bd8455b67bc0e2890a4ffe8dae5b9eae) Thanks [@KisaneNeko](https://github.com/KisaneNeko)! - Fix `popToNative()` on iOS closing every React Native screen instead of only the topmost one.
|
|
12
|
+
|
|
13
|
+
`popToNative()` is delivered as an app-wide notification, so every live React Native surface acted on it — including surfaces buried under other screens, and each surface acted twice when hosted by SwiftUI. In a stack such as RN → native → RN, a single call tore down the whole navigation stack, taking native screens with it.
|
|
14
|
+
|
|
15
|
+
A React Native surface now acts only when it is the topmost one on screen, and only once per host.
|
|
16
|
+
|
|
17
|
+
Two consequences worth knowing about:
|
|
18
|
+
- When no React Native surface is on screen — for example one hidden behind a full-screen native modal — `popToNative()` is now a no-op instead of popping the hidden screen. It logs when this happens.
|
|
19
|
+
- `popToNative()` no longer dismisses a modally presented native screen that merely _contains_ a React Native surface. Only a surface that owns a navigation stack entry pops.
|
|
20
|
+
|
|
21
|
+
- Updated dependencies []:
|
|
22
|
+
- @callstack/brownfield-cli@5.1.1
|
|
23
|
+
|
|
24
|
+
## 5.1.0
|
|
25
|
+
|
|
26
|
+
### Minor Changes
|
|
27
|
+
|
|
28
|
+
- [#450](https://github.com/callstack/react-native-brownfield/pull/450) [`4846a05`](https://github.com/callstack/react-native-brownfield/commit/4846a055eb06f8c8dea08b33d0bb0d1b2a2f2f86) Thanks [@borisyankov](https://github.com/borisyankov)! - Add `preloadBundle` to `startReactNative` on iOS. Without a preload, `startReactNative` only makes the factory, and React Native loads the JavaScript bundle when it creates the first React Native view. `startReactNative(launchOptions:preloadBundle:onBundleLoaded:)` moves that work to the app launch: the call starts the React Host, and React Native evaluates the bundle on the JavaScript thread, in parallel with the remainder of the app launch. On Android, `ReactNativeBrownfield.initialize` does the same operation. This shape of `startReactNative` also takes the launch options for the React Host.
|
|
29
|
+
|
|
30
|
+
`onBundleLoaded` now runs on the main thread, and not on the JavaScript thread. A callback that you add after React Native loaded the bundle runs in the next turn of the main run loop.
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- [#381](https://github.com/callstack/react-native-brownfield/pull/381) [`b8e8da5`](https://github.com/callstack/react-native-brownfield/commit/b8e8da50fbf20058c5c2745981c7deb5cb33061a) Thanks [@alpharius-ck](https://github.com/alpharius-ck)! - e2e tests for android
|
|
35
|
+
- Updated dependencies []:
|
|
36
|
+
- @callstack/brownfield-cli@5.1.0
|
|
37
|
+
|
|
3
38
|
## 5.0.2
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
|
@@ -65,6 +65,8 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
|
|
|
65
65
|
if (!initialized.getAndSet(true)) {
|
|
66
66
|
loadNativeLibs(application)
|
|
67
67
|
installAndPreload(reactHost, onJSBundleLoaded)
|
|
68
|
+
} else {
|
|
69
|
+
invokeWhenJSBundleLoaded(onJSBundleLoaded)
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
|
|
@@ -77,6 +79,8 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
|
|
|
77
79
|
if (!initialized.getAndSet(true)) {
|
|
78
80
|
loadNativeLibs(application)
|
|
79
81
|
installAndPreload(reactHostFactory(), onJSBundleLoaded)
|
|
82
|
+
} else {
|
|
83
|
+
invokeWhenJSBundleLoaded(onJSBundleLoaded)
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
@@ -102,6 +106,8 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
|
|
|
102
106
|
jsRuntimeFactory = null
|
|
103
107
|
)
|
|
104
108
|
installAndPreload(reactHost, onJSBundleLoaded)
|
|
109
|
+
} else {
|
|
110
|
+
invokeWhenJSBundleLoaded(onJSBundleLoaded)
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
113
|
|
|
@@ -134,6 +140,25 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
|
|
|
134
140
|
onJSBundleLoaded?.invoke(true)
|
|
135
141
|
}
|
|
136
142
|
}
|
|
143
|
+
|
|
144
|
+
private fun invokeWhenJSBundleLoaded(onJSBundleLoaded: OnJSBundleLoaded?) {
|
|
145
|
+
if (onJSBundleLoaded == null || !::instance.isInitialized) {
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
val reactHost = instance.reactHost
|
|
150
|
+
reactHost.currentReactContext?.let {
|
|
151
|
+
onJSBundleLoaded.invoke(true)
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
reactHost.addReactInstanceEventListener(object : ReactInstanceEventListener {
|
|
156
|
+
override fun onReactContextInitialized(context: ReactContext) {
|
|
157
|
+
onJSBundleLoaded.invoke(true)
|
|
158
|
+
reactHost.removeReactInstanceEventListener(this)
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
}
|
|
137
162
|
}
|
|
138
163
|
|
|
139
164
|
/**
|
|
@@ -177,6 +202,19 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
|
|
|
177
202
|
moduleName: String,
|
|
178
203
|
reactDelegate: ReactDelegateWrapper? = null,
|
|
179
204
|
launchOptions: Bundle? = null,
|
|
205
|
+
): FrameLayout = createView(activity, moduleName, reactDelegate, launchOptions, activity)
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Use the owner of the view when embedding React Native inside a fragment or
|
|
209
|
+
* another container whose lifetime is shorter than the activity.
|
|
210
|
+
* The four-argument overload retains its original JVM signature.
|
|
211
|
+
*/
|
|
212
|
+
fun createView(
|
|
213
|
+
activity: FragmentActivity?,
|
|
214
|
+
moduleName: String,
|
|
215
|
+
reactDelegate: ReactDelegateWrapper?,
|
|
216
|
+
launchOptions: Bundle?,
|
|
217
|
+
lifecycleOwner: LifecycleOwner?,
|
|
180
218
|
): FrameLayout {
|
|
181
219
|
val reactHost = shared.reactHost
|
|
182
220
|
val resolvedDelegate =
|
|
@@ -190,12 +228,17 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
|
|
|
190
228
|
}
|
|
191
229
|
|
|
192
230
|
// Register back press callback
|
|
193
|
-
|
|
231
|
+
if (lifecycleOwner != null) {
|
|
232
|
+
activity?.onBackPressedDispatcher?.addCallback(lifecycleOwner, backPressedCallback)
|
|
233
|
+
}
|
|
194
234
|
// invoked on the last RN screen exit
|
|
195
235
|
resolvedDelegate.setHardwareBackHandler {
|
|
196
236
|
backPressedCallback.isEnabled = false
|
|
197
|
-
|
|
198
|
-
|
|
237
|
+
try {
|
|
238
|
+
activity?.onBackPressedDispatcher?.onBackPressed()
|
|
239
|
+
} finally {
|
|
240
|
+
backPressedCallback.isEnabled = true
|
|
241
|
+
}
|
|
199
242
|
}
|
|
200
243
|
|
|
201
244
|
/**
|
|
@@ -205,7 +248,7 @@ class ReactNativeBrownfield private constructor(val reactHost: ReactHost) {
|
|
|
205
248
|
* In such a case, we set the lifeCycle observer.
|
|
206
249
|
*/
|
|
207
250
|
if (reactDelegate == null) {
|
|
208
|
-
|
|
251
|
+
lifecycleOwner?.lifecycle?.addObserver(getLifeCycleObserver(resolvedDelegate))
|
|
209
252
|
}
|
|
210
253
|
|
|
211
254
|
resolvedDelegate.loadApp()
|
|
@@ -54,7 +54,9 @@ class ReactNativeFragment : ReactFragment(), PermissionAwareActivity {
|
|
|
54
54
|
return ReactNativeBrownfield.shared.createView(
|
|
55
55
|
activity,
|
|
56
56
|
moduleName,
|
|
57
|
-
this.reactDelegate as ReactDelegateWrapper
|
|
57
|
+
this.reactDelegate as ReactDelegateWrapper,
|
|
58
|
+
launchOptions = null,
|
|
59
|
+
lifecycleOwner = viewLifecycleOwner
|
|
58
60
|
)
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -69,6 +71,26 @@ class ReactNativeFragment : ReactFragment(), PermissionAwareActivity {
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
override fun onPause() {
|
|
75
|
+
try {
|
|
76
|
+
super.onPause()
|
|
77
|
+
} catch (error: AssertionError) {
|
|
78
|
+
if (
|
|
79
|
+
error.message?.contains(
|
|
80
|
+
"Pausing an activity that is not the current activity"
|
|
81
|
+
) == true
|
|
82
|
+
) {
|
|
83
|
+
Log.w(
|
|
84
|
+
"ReactNativeFragment",
|
|
85
|
+
"Ignoring stale onHostPause for ${activity?.javaClass?.simpleName}",
|
|
86
|
+
error
|
|
87
|
+
)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
throw error
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
72
94
|
override fun onRequestPermissionsResult(
|
|
73
95
|
requestCode: Int,
|
|
74
96
|
permissions: Array<String>,
|
|
@@ -108,6 +108,13 @@ dependencies {
|
|
|
108
108
|
implementation(libs.common)
|
|
109
109
|
implementation(libs.asm.commons)
|
|
110
110
|
implementation(libs.versioncompare)
|
|
111
|
+
testImplementation(libs.junit.jupiter)
|
|
112
|
+
testImplementation(gradleTestKit())
|
|
113
|
+
testImplementation(kotlin("test"))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
tasks.test {
|
|
117
|
+
useJUnitPlatform()
|
|
111
118
|
}
|
|
112
119
|
|
|
113
120
|
tasks.named("detekt").configure {
|
|
@@ -6,6 +6,7 @@ agp = "8.5.2"
|
|
|
6
6
|
common = "31.2.2" # do not bump it for now, as it throws an error for incompatible AGP used
|
|
7
7
|
asm-commons = "9.7"
|
|
8
8
|
versioncompare = "1.5.0"
|
|
9
|
+
junit = "5.11.4"
|
|
9
10
|
|
|
10
11
|
[plugins]
|
|
11
12
|
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlinJvm" }
|
|
@@ -17,3 +18,4 @@ agp = { module = "com.android.tools.build:gradle", name = "agp", version.ref = "
|
|
|
17
18
|
common = { module = "com.android.tools:common", version.ref = "common" }
|
|
18
19
|
asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm-commons" }
|
|
19
20
|
versioncompare = { module = "io.github.g00fy2:versioncompare", version.ref = "versioncompare" }
|
|
21
|
+
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
package com.callstack.react.brownfield.artifacts
|
|
2
|
+
|
|
3
|
+
import com.callstack.react.brownfield.shared.Logging
|
|
4
|
+
import com.callstack.react.brownfield.shared.TRANSITIVE_DEPENDENCY_CONFIG_NAMES
|
|
5
|
+
import com.callstack.react.brownfield.shared.UnresolvedArtifactInfo
|
|
6
|
+
import com.callstack.react.brownfield.shared.VersionMediatingDependencySet
|
|
7
|
+
import com.callstack.react.brownfield.shared.collectPublishableGradleDependencies
|
|
8
|
+
import com.callstack.react.brownfield.shared.isPublishableCoordinate
|
|
9
|
+
import org.gradle.api.Project
|
|
10
|
+
import org.gradle.api.artifacts.Dependency
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Result of [RncTransitiveDependencyDiscoverer.discover].
|
|
14
|
+
*
|
|
15
|
+
* @param dependencies The mediated set of third-party dependencies to inject.
|
|
16
|
+
* @param supersededCoordinates Coordinates the consumer declares itself that an embedded module
|
|
17
|
+
* also needs. The caller must drop their pre-existing POM/module.json entries: [dependencies]
|
|
18
|
+
* already carries the mediated (never-lower) version, so keeping both duplicates or shadows it.
|
|
19
|
+
*/
|
|
20
|
+
data class RncTransitiveDependencyDiscoveryResult(
|
|
21
|
+
val dependencies: VersionMediatingDependencySet,
|
|
22
|
+
val supersededCoordinates: Set<Pair<String, String>>,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Discovers third-party dependencies of the native modules embedded into the fat AAR, for
|
|
27
|
+
* publication into its POM/module metadata. The RNC-CLI counterpart to
|
|
28
|
+
* `ExpoPublishingHelper.appendExpoTransitiveDependenciesFromGradle`.
|
|
29
|
+
*/
|
|
30
|
+
class RncTransitiveDependencyDiscoverer(private val project: Project) {
|
|
31
|
+
fun discover(artifacts: List<UnresolvedArtifactInfo>): RncTransitiveDependencyDiscoveryResult {
|
|
32
|
+
val discovered = VersionMediatingDependencySet()
|
|
33
|
+
val supersededCoordinates = mutableSetOf<Pair<String, String>>()
|
|
34
|
+
|
|
35
|
+
artifacts
|
|
36
|
+
.filter { it.isExpoPublishDependency != true }
|
|
37
|
+
.forEach { artifact -> discoverFromArtifact(artifact, discovered, supersededCoordinates) }
|
|
38
|
+
|
|
39
|
+
return RncTransitiveDependencyDiscoveryResult(discovered, supersededCoordinates)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private fun discoverFromArtifact(
|
|
43
|
+
artifact: UnresolvedArtifactInfo,
|
|
44
|
+
discovered: VersionMediatingDependencySet,
|
|
45
|
+
supersededCoordinates: MutableSet<Pair<String, String>>,
|
|
46
|
+
) {
|
|
47
|
+
val moduleProject = project.rootProject.findProject(":${artifact.moduleName}")
|
|
48
|
+
if (moduleProject == null) {
|
|
49
|
+
Logging.log(
|
|
50
|
+
"WARNING: Could not discover transitive dependencies for embedded module " +
|
|
51
|
+
"'${artifact.moduleName}' - no Gradle project found at " +
|
|
52
|
+
"':${artifact.moduleName}' in the root project",
|
|
53
|
+
)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
collectPublishableGradleDependencies(moduleProject).forEach { moduleDependency ->
|
|
58
|
+
val consumerDeclaration = consumerDeclaredDependency(moduleDependency.groupId, moduleDependency.artifactId)
|
|
59
|
+
|
|
60
|
+
if (consumerDeclaration != null) {
|
|
61
|
+
// Supersede on the declaration existing, not on it having a version: a versionless
|
|
62
|
+
// one (BOM/platform) still leaves a stale entry that must be replaced, not doubled.
|
|
63
|
+
supersededCoordinates.add(moduleDependency.groupId to moduleDependency.artifactId)
|
|
64
|
+
|
|
65
|
+
// Module-side versions are already validated upstream; this is the consumer-side
|
|
66
|
+
// equivalent, keeping a dynamic version from winning mediation and being published.
|
|
67
|
+
val consumerVersioned = moduleDependency.copy(version = consumerDeclaration.version)
|
|
68
|
+
if (isPublishableCoordinate(consumerVersioned)) {
|
|
69
|
+
discovered.add(consumerVersioned)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
discovered.add(moduleDependency)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The consumer's own declaration of this coordinate, or null if it doesn't declare it. Returns
|
|
79
|
+
* the [Dependency], not its version, so "declared without a version" stays distinguishable from
|
|
80
|
+
* "not declared" — collapsing the two leaks duplicate POM entries.
|
|
81
|
+
*
|
|
82
|
+
* Note this narrows a dynamic declaration: consumer `appcompat:1.+` against module `1.0.0`
|
|
83
|
+
* publishes `1.0.0`, possibly lower than `1.+` would have resolved to. Intended — a published
|
|
84
|
+
* `1.+` is broken for downstream consumers.
|
|
85
|
+
*/
|
|
86
|
+
private fun consumerDeclaredDependency(
|
|
87
|
+
groupId: String,
|
|
88
|
+
artifactId: String,
|
|
89
|
+
): Dependency? {
|
|
90
|
+
return TRANSITIVE_DEPENDENCY_CONFIG_NAMES.firstNotNullOfOrNull { configName ->
|
|
91
|
+
project.configurations.findByName(configName)?.dependencies?.firstOrNull {
|
|
92
|
+
it.group == groupId && it.name == artifactId
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
package com.callstack.react.brownfield.expo
|
|
2
2
|
|
|
3
3
|
import com.android.utils.forEach
|
|
4
|
-
import com.callstack.react.brownfield.expo.utils.DependencyInfo
|
|
5
4
|
import com.callstack.react.brownfield.expo.utils.ExpoGradleProjectProjection
|
|
6
5
|
import com.callstack.react.brownfield.expo.utils.LocalMavenUtils
|
|
7
|
-
import com.callstack.react.brownfield.expo.utils.VersionMediatingDependencySet
|
|
8
6
|
import com.callstack.react.brownfield.expo.utils.asExpoGradleProjectProjection
|
|
9
7
|
import com.callstack.react.brownfield.shared.Constants
|
|
8
|
+
import com.callstack.react.brownfield.shared.DependencyInfo
|
|
10
9
|
import com.callstack.react.brownfield.shared.Logging
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import groovy.util.NodeList
|
|
10
|
+
import com.callstack.react.brownfield.shared.VersionMediatingDependencySet
|
|
11
|
+
import com.callstack.react.brownfield.shared.collectPublishableGradleDependencies
|
|
14
12
|
import org.gradle.api.Project
|
|
15
|
-
import org.gradle.api.publish.PublishingExtension
|
|
16
|
-
import org.gradle.api.publish.maven.MavenPublication
|
|
17
|
-
import org.gradle.api.publish.tasks.GenerateModuleMetadata
|
|
18
13
|
import org.w3c.dom.Node
|
|
19
14
|
import java.io.File
|
|
20
15
|
import javax.xml.parsers.DocumentBuilderFactory
|
|
@@ -29,6 +24,11 @@ fun Node.getChildNodeByName(nodeName: String): Node? {
|
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
open class ExpoPublishingHelper(val brownfieldAppProject: Project) {
|
|
27
|
+
/**
|
|
28
|
+
* Discovers *which* Expo projects are publishable, not their transitive dependencies: this runs
|
|
29
|
+
* during `apply()`, when those projects may not have configured their own dependencies yet.
|
|
30
|
+
* [discoverAllExpoTransitiveDependencies] handles that later.
|
|
31
|
+
*/
|
|
32
32
|
fun configure(): List<ExpoGradleProjectProjection> {
|
|
33
33
|
val discoverableExpoProjects = getDiscoverableExpoProjects()
|
|
34
34
|
|
|
@@ -39,29 +39,10 @@ open class ExpoPublishingHelper(val brownfieldAppProject: Project) {
|
|
|
39
39
|
) { it.name },
|
|
40
40
|
)
|
|
41
41
|
|
|
42
|
-
val expoTransitiveDependencies =
|
|
43
|
-
discoverAllExpoTransitiveDependencies(
|
|
44
|
-
expoProjects = discoverableExpoProjects,
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
Logging.log(
|
|
48
|
-
"Collected a total of ${expoTransitiveDependencies.size} unique Expo transitive " +
|
|
49
|
-
"dependencies for brownfield app project publishing",
|
|
50
|
-
)
|
|
51
|
-
expoTransitiveDependencies.forEach {
|
|
52
|
-
Logging.log(
|
|
53
|
-
"(*) dependency ${it.groupId}:${it.artifactId}:${it.version} (scope: ${it.scope}, " +
|
|
54
|
-
"${if (it.optional) "optional" else "required"})",
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
reconfigurePOM(expoTransitiveDependencies)
|
|
59
|
-
reconfigureGradleModuleJSON(expoTransitiveDependencies)
|
|
60
|
-
|
|
61
42
|
return discoverableExpoProjects
|
|
62
43
|
}
|
|
63
44
|
|
|
64
|
-
|
|
45
|
+
internal fun shouldExcludeDependency(
|
|
65
46
|
groupId: String,
|
|
66
47
|
artifactId: String,
|
|
67
48
|
): Boolean {
|
|
@@ -78,174 +59,6 @@ open class ExpoPublishingHelper(val brownfieldAppProject: Project) {
|
|
|
78
59
|
return (isRootProjectArtifact || isExpoArtifact)
|
|
79
60
|
}
|
|
80
61
|
|
|
81
|
-
/**
|
|
82
|
-
* Modifies the generated Gradle Module Metadata file to inject Expo transitive dependencies.
|
|
83
|
-
* @param discoveredExpoTransitiveDependencies Set of DependencyInfo
|
|
84
|
-
* representing Expo transitive dependencies to add.
|
|
85
|
-
*/
|
|
86
|
-
@Suppress("LongMethod")
|
|
87
|
-
protected fun reconfigureGradleModuleJSON(discoveredExpoTransitiveDependencies: VersionMediatingDependencySet) {
|
|
88
|
-
val removeDependenciesFromModuleFileTask =
|
|
89
|
-
brownfieldAppProject.tasks.register("removeDependenciesFromModuleFile")
|
|
90
|
-
removeDependenciesFromModuleFileTask.configure { task ->
|
|
91
|
-
task.doLast {
|
|
92
|
-
val moduleBuildDir = brownfieldAppProject.layout.buildDirectory.get()
|
|
93
|
-
|
|
94
|
-
File("$moduleBuildDir/publications/mavenAar/module.json").run {
|
|
95
|
-
val json = inputStream().use { JsonSlurper().parse(it) as Map<*, *> }
|
|
96
|
-
|
|
97
|
-
discoveredExpoTransitiveDependencies.forEach { dependencyToAdd ->
|
|
98
|
-
@Suppress("UNCHECKED_CAST")
|
|
99
|
-
(json["variants"] as? List<MutableMap<String, Any>>)?.forEach { variant ->
|
|
100
|
-
Logging.log(
|
|
101
|
-
"Injecting dependency to Gradle module JSON for variant " +
|
|
102
|
-
"'${variant["name"]}': ${dependencyToAdd.groupId}:" +
|
|
103
|
-
"${dependencyToAdd.artifactId}:${dependencyToAdd.version}",
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
(variant["dependencies"] as? MutableList<MutableMap<String, Any>>)?.add(
|
|
107
|
-
mutableMapOf<String, Any>(
|
|
108
|
-
"group" to dependencyToAdd.groupId,
|
|
109
|
-
"module" to dependencyToAdd.artifactId,
|
|
110
|
-
).apply {
|
|
111
|
-
dependencyToAdd.version?.let { version ->
|
|
112
|
-
put(
|
|
113
|
-
"version",
|
|
114
|
-
mapOf(
|
|
115
|
-
"requires" to version,
|
|
116
|
-
),
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@Suppress("UNCHECKED_CAST")
|
|
125
|
-
(json["variants"] as? List<MutableMap<String, Any>>)?.forEach { variant ->
|
|
126
|
-
(variant["dependencies"] as? MutableList<Map<String, Any>>)?.removeAll {
|
|
127
|
-
val group = it["group"] as String
|
|
128
|
-
val module = it["module"] as String
|
|
129
|
-
|
|
130
|
-
val shouldBeExcluded =
|
|
131
|
-
shouldExcludeDependency(
|
|
132
|
-
groupId = group,
|
|
133
|
-
artifactId = module,
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
if (shouldBeExcluded) {
|
|
137
|
-
Logging.log(
|
|
138
|
-
"Removing excluded dependency from Gradle module JSON: $group:$module",
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
shouldBeExcluded
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
writer().use {
|
|
146
|
-
it.write(
|
|
147
|
-
JsonOutput.prettyPrint(
|
|
148
|
-
JsonOutput.toJson(
|
|
149
|
-
json,
|
|
150
|
-
),
|
|
151
|
-
),
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
brownfieldAppProject.tasks.withType(GenerateModuleMetadata::class.java)
|
|
160
|
-
.configureEach {
|
|
161
|
-
it.finalizedBy(removeDependenciesFromModuleFileTask.get())
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Modifies the generated Maven POM file to inject Expo transitive dependencies.
|
|
167
|
-
* @param discoveredExpoTransitiveDependencies Set of DependencyInfo
|
|
168
|
-
* representing Expo transitive dependencies to add.
|
|
169
|
-
*/
|
|
170
|
-
@Suppress("LongMethod")
|
|
171
|
-
protected fun reconfigurePOM(discoveredExpoTransitiveDependencies: VersionMediatingDependencySet) {
|
|
172
|
-
brownfieldAppProject.pluginManager.withPlugin("maven-publish") {
|
|
173
|
-
brownfieldAppProject.extensions.configure(PublishingExtension::class.java) { publishing ->
|
|
174
|
-
publishing.publications.withType(MavenPublication::class.java)
|
|
175
|
-
.configureEach { pub ->
|
|
176
|
-
Logging.log(
|
|
177
|
-
"Configuring POM for publication '${pub.name}' to include Expo transitive dependencies",
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
pub.pom.withXml {
|
|
181
|
-
val root = it.asNode()
|
|
182
|
-
|
|
183
|
-
// below: obtains a view of the <dependencies> node(s)
|
|
184
|
-
// inside the POM XML; in practice, there should be only one such node
|
|
185
|
-
val dependenciesNodeList =
|
|
186
|
-
root.get("dependencies") as NodeList
|
|
187
|
-
val dependenciesNode =
|
|
188
|
-
dependenciesNodeList.first() as groovy.util.Node
|
|
189
|
-
|
|
190
|
-
// below: inject the discovered Expo transitive dependencies
|
|
191
|
-
// into the POM's <dependencies> node
|
|
192
|
-
discoveredExpoTransitiveDependencies.forEach { dependencyToAdd ->
|
|
193
|
-
Logging.log(
|
|
194
|
-
"Injecting dependency to POM: ${dependencyToAdd.groupId}:" +
|
|
195
|
-
"${dependencyToAdd.artifactId}:${dependencyToAdd.version}",
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
val childTags =
|
|
199
|
-
mutableMapOf(
|
|
200
|
-
"groupId" to dependencyToAdd.groupId,
|
|
201
|
-
"artifactId" to dependencyToAdd.artifactId,
|
|
202
|
-
"scope" to dependencyToAdd.scope,
|
|
203
|
-
"optional" to dependencyToAdd.optional.toString(),
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
if (dependencyToAdd.version?.isNotBlank() == true) {
|
|
207
|
-
childTags["version"] = dependencyToAdd.version
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
dependenciesNode.appendNode("dependency").let { newDepNode ->
|
|
211
|
-
childTags.forEach { (tagName, tagValue) ->
|
|
212
|
-
newDepNode.appendNode(tagName, tagValue)
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// below: filter out dependencies that should be excluded
|
|
218
|
-
dependenciesNode.children()
|
|
219
|
-
.filterIsInstance<groovy.util.Node>()
|
|
220
|
-
.filter { dependency ->
|
|
221
|
-
val groupId =
|
|
222
|
-
(dependency["groupId"] as NodeList).text()
|
|
223
|
-
val artifactId =
|
|
224
|
-
(dependency["artifactId"] as NodeList).text()
|
|
225
|
-
|
|
226
|
-
val shouldBeExcluded =
|
|
227
|
-
shouldExcludeDependency(
|
|
228
|
-
groupId = groupId,
|
|
229
|
-
artifactId = artifactId,
|
|
230
|
-
)
|
|
231
|
-
|
|
232
|
-
if (shouldBeExcluded) {
|
|
233
|
-
Logging.log(
|
|
234
|
-
"Removing excluded dependency from POM: $groupId:$artifactId",
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
shouldBeExcluded
|
|
239
|
-
}
|
|
240
|
-
.forEach { dependency ->
|
|
241
|
-
dependenciesNode.remove(dependency)
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
62
|
fun discoverAllExpoTransitiveDependencies(expoProjects: Iterable<ExpoGradleProjectProjection>): VersionMediatingDependencySet {
|
|
250
63
|
var discoveredExpoTransitiveDependencies = VersionMediatingDependencySet()
|
|
251
64
|
expoProjects.forEach { expoProj ->
|
|
@@ -368,24 +181,7 @@ open class ExpoPublishingHelper(val brownfieldAppProject: Project) {
|
|
|
368
181
|
pkgProject: Project,
|
|
369
182
|
dependencies: VersionMediatingDependencySet,
|
|
370
183
|
) {
|
|
371
|
-
|
|
372
|
-
* Not accounting for variant specific configurations as Expo packages are not
|
|
373
|
-
* using it. Should we face any issues/needs to account for it, we can do it here.
|
|
374
|
-
*/
|
|
375
|
-
listOf("implementation", "api", "runtime").forEach {
|
|
376
|
-
val configuration = pkgProject.configurations.findByName(it)
|
|
377
|
-
configuration?.dependencies?.forEach { dep ->
|
|
378
|
-
if (dep.group != null) {
|
|
379
|
-
dependencies.add(
|
|
380
|
-
DependencyInfo.fromGradleDep(
|
|
381
|
-
groupId = dep.group!!,
|
|
382
|
-
artifactId = dep.name,
|
|
383
|
-
version = dep.version,
|
|
384
|
-
),
|
|
385
|
-
)
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
184
|
+
dependencies.addAll(collectPublishableGradleDependencies(pkgProject))
|
|
389
185
|
}
|
|
390
186
|
|
|
391
187
|
/**
|