@react-native/gradle-plugin 0.76.0-rc.0 → 0.76.0-rc.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/package.json +1 -1
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt +1 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GeneratePackageListTask.kt +11 -2
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt +38 -0
- package/shared/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +17 -2
- package/shared/src/test/kotlin/com/facebook/react/utils/JsonUtilsTest.kt +48 -0
package/package.json
CHANGED
|
@@ -188,6 +188,7 @@ abstract class ReactExtension @Inject constructor(val project: Project) {
|
|
|
188
188
|
?.dependencies
|
|
189
189
|
?.values
|
|
190
190
|
?.filter { it.platforms?.android !== null }
|
|
191
|
+
?.filterNot { it.platforms?.android?.isPureCxxDependency == true }
|
|
191
192
|
?.forEach { deps ->
|
|
192
193
|
val nameCleansed = deps.nameCleansed
|
|
193
194
|
val dependencyConfiguration = deps.platforms?.android?.dependencyConfiguration
|
|
@@ -30,10 +30,19 @@ abstract class GeneratePackageListTask : DefaultTask() {
|
|
|
30
30
|
|
|
31
31
|
@TaskAction
|
|
32
32
|
fun taskAction() {
|
|
33
|
-
val model =
|
|
33
|
+
val model =
|
|
34
|
+
JsonUtils.fromAutolinkingConfigJson(autolinkInputFile.get().asFile)
|
|
35
|
+
?: error(
|
|
36
|
+
"""
|
|
37
|
+
RNGP - Autolinking: Could not parse autolinking config file:
|
|
38
|
+
${autolinkInputFile.get().asFile.absolutePath}
|
|
39
|
+
|
|
40
|
+
The file is either missing or not containing valid JSON so the build won't succeed.
|
|
41
|
+
"""
|
|
42
|
+
.trimIndent())
|
|
34
43
|
|
|
35
44
|
val packageName =
|
|
36
|
-
model
|
|
45
|
+
model.project?.android?.packageName
|
|
37
46
|
?: error(
|
|
38
47
|
"RNGP - Autolinking: Could not find project.android.packageName in react-native config output! Could not autolink packages without this field.")
|
|
39
48
|
|
|
@@ -189,6 +189,44 @@ class ReactExtensionTest {
|
|
|
189
189
|
assertThat(deps).isEmpty()
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
@Test
|
|
193
|
+
fun getGradleDependenciesToApply_withIsPureCxxDeps_filtersCorrectly() {
|
|
194
|
+
val validJsonFile =
|
|
195
|
+
createJsonFile(
|
|
196
|
+
"""
|
|
197
|
+
{
|
|
198
|
+
"reactNativeVersion": "1000.0.0",
|
|
199
|
+
"dependencies": {
|
|
200
|
+
"@react-native/oss-library-example": {
|
|
201
|
+
"root": "./node_modules/@react-native/android-example",
|
|
202
|
+
"name": "@react-native/android-example",
|
|
203
|
+
"platforms": {
|
|
204
|
+
"android": {
|
|
205
|
+
"sourceDir": "src/main/java",
|
|
206
|
+
"packageImportPath": "com.facebook.react"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
"@react-native/another-library-for-testing": {
|
|
211
|
+
"root": "./node_modules/@react-native/cxx-testing",
|
|
212
|
+
"name": "@react-native/cxx-testing",
|
|
213
|
+
"platforms": {
|
|
214
|
+
"android": {
|
|
215
|
+
"sourceDir": "src/main/java",
|
|
216
|
+
"packageImportPath": "com.facebook.react",
|
|
217
|
+
"isPureCxxDependency": true
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
"""
|
|
224
|
+
.trimIndent())
|
|
225
|
+
|
|
226
|
+
val deps = getGradleDependenciesToApply(validJsonFile)
|
|
227
|
+
assertThat(deps).containsExactly("implementation" to ":react-native_android-example")
|
|
228
|
+
}
|
|
229
|
+
|
|
192
230
|
private fun createJsonFile(@Language("JSON") input: String) =
|
|
193
231
|
tempFolder.newFile().apply { writeText(input) }
|
|
194
232
|
}
|
|
@@ -21,8 +21,23 @@ object JsonUtils {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
fun fromAutolinkingConfigJson(input: File): ModelAutolinkingConfigJson? =
|
|
24
|
-
input.bufferedReader().use {
|
|
25
|
-
runCatching {
|
|
24
|
+
input.bufferedReader().use { reader ->
|
|
25
|
+
runCatching {
|
|
26
|
+
// We sanitize the output of the `config` command as it could contain debug logs
|
|
27
|
+
// such as:
|
|
28
|
+
//
|
|
29
|
+
// > AwesomeProject@0.0.1 npx
|
|
30
|
+
// > rnc-cli config
|
|
31
|
+
//
|
|
32
|
+
// which will render the JSON invalid.
|
|
33
|
+
val content =
|
|
34
|
+
reader
|
|
35
|
+
.readLines()
|
|
36
|
+
.filterNot { line -> line.startsWith(">") }
|
|
37
|
+
.joinToString("\n")
|
|
38
|
+
.trim()
|
|
39
|
+
gsonConverter.fromJson(content, ModelAutolinkingConfigJson::class.java)
|
|
40
|
+
}
|
|
26
41
|
.getOrNull()
|
|
27
42
|
}
|
|
28
43
|
}
|
|
@@ -186,6 +186,54 @@ class JsonUtilsTest {
|
|
|
186
186
|
assertThat("implementation").isEqualTo(parsed.project!!.android!!.dependencyConfiguration)
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
@Test
|
|
190
|
+
fun fromAutolinkingConfigJson_withInfoLogs_sanitizeAndParseIt() {
|
|
191
|
+
@Suppress("JsonStandardCompliance")
|
|
192
|
+
val validJson =
|
|
193
|
+
createJsonFile(
|
|
194
|
+
"""
|
|
195
|
+
|
|
196
|
+
> AwesomeProject@0.0.1 npx
|
|
197
|
+
> rnc-cli config
|
|
198
|
+
|
|
199
|
+
{
|
|
200
|
+
"reactNativeVersion": "1000.0.0",
|
|
201
|
+
"project": {
|
|
202
|
+
"ios": {
|
|
203
|
+
"sourceDir": "./packages/rn-tester",
|
|
204
|
+
"xcodeProject": {
|
|
205
|
+
"name": "RNTesterPods.xcworkspace",
|
|
206
|
+
"isWorkspace": true
|
|
207
|
+
},
|
|
208
|
+
"automaticPodsInstallation": false
|
|
209
|
+
},
|
|
210
|
+
"android": {
|
|
211
|
+
"sourceDir": "./packages/rn-tester",
|
|
212
|
+
"appName": "RN-Tester",
|
|
213
|
+
"packageName": "com.facebook.react.uiapp",
|
|
214
|
+
"applicationId": "com.facebook.react.uiapp",
|
|
215
|
+
"mainActivity": ".RNTesterActivity",
|
|
216
|
+
"watchModeCommandParams": [
|
|
217
|
+
"--mode HermesDebug"
|
|
218
|
+
],
|
|
219
|
+
"dependencyConfiguration": "implementation"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
"""
|
|
224
|
+
.trimIndent())
|
|
225
|
+
val parsed = JsonUtils.fromAutolinkingConfigJson(validJson)!!
|
|
226
|
+
|
|
227
|
+
assertThat("./packages/rn-tester").isEqualTo(parsed.project!!.android!!.sourceDir)
|
|
228
|
+
assertThat("RN-Tester").isEqualTo(parsed.project!!.android!!.appName)
|
|
229
|
+
assertThat("com.facebook.react.uiapp").isEqualTo(parsed.project!!.android!!.packageName)
|
|
230
|
+
assertThat("com.facebook.react.uiapp").isEqualTo(parsed.project!!.android!!.applicationId)
|
|
231
|
+
assertThat(".RNTesterActivity").isEqualTo(parsed.project!!.android!!.mainActivity)
|
|
232
|
+
assertThat("--mode HermesDebug")
|
|
233
|
+
.isEqualTo(parsed.project!!.android!!.watchModeCommandParams!![0])
|
|
234
|
+
assertThat("implementation").isEqualTo(parsed.project!!.android!!.dependencyConfiguration)
|
|
235
|
+
}
|
|
236
|
+
|
|
189
237
|
@Test
|
|
190
238
|
fun fromAutolinkingConfigJson_withDependenciesSpecified_canParseIt() {
|
|
191
239
|
val validJson =
|