mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RNGP - Sanitize the output of the config command (#46482)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46482 Fixes https://github.com/facebook/react-native/issues/46443 Fixes https://github.com/facebook/react-native/issues/46134 I'm sanitizing the output of the `config` command + I've added some more logging in case of failure. Changelog: [Android] [Fixed] - RNGP - Sanitize the output of the config command Reviewed By: cipolleschi Differential Revision: D62641979 fbshipit-source-id: c13d27a42beeb7a973c1802e7204631d49d3d09b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3cbaddbc16
commit
d7884a6bb8
+11
-2
@@ -30,10 +30,19 @@ abstract class GeneratePackageListTask : DefaultTask() {
|
||||
|
||||
@TaskAction
|
||||
fun taskAction() {
|
||||
val model = JsonUtils.fromAutolinkingConfigJson(autolinkInputFile.get().asFile)
|
||||
val model =
|
||||
JsonUtils.fromAutolinkingConfigJson(autolinkInputFile.get().asFile)
|
||||
?: error(
|
||||
"""
|
||||
RNGP - Autolinking: Could not parse autolinking config file:
|
||||
${autolinkInputFile.get().asFile.absolutePath}
|
||||
|
||||
The file is either missing or not containing valid JSON so the build won't succeed.
|
||||
"""
|
||||
.trimIndent())
|
||||
|
||||
val packageName =
|
||||
model?.project?.android?.packageName
|
||||
model.project?.android?.packageName
|
||||
?: error(
|
||||
"RNGP - Autolinking: Could not find project.android.packageName in react-native config output! Could not autolink packages without this field.")
|
||||
|
||||
|
||||
+17
-2
@@ -21,8 +21,23 @@ object JsonUtils {
|
||||
}
|
||||
|
||||
fun fromAutolinkingConfigJson(input: File): ModelAutolinkingConfigJson? =
|
||||
input.bufferedReader().use {
|
||||
runCatching { gsonConverter.fromJson(it, ModelAutolinkingConfigJson::class.java) }
|
||||
input.bufferedReader().use { reader ->
|
||||
runCatching {
|
||||
// We sanitize the output of the `config` command as it could contain debug logs
|
||||
// such as:
|
||||
//
|
||||
// > AwesomeProject@0.0.1 npx
|
||||
// > rnc-cli config
|
||||
//
|
||||
// which will render the JSON invalid.
|
||||
val content =
|
||||
reader
|
||||
.readLines()
|
||||
.filterNot { line -> line.startsWith(">") }
|
||||
.joinToString("\n")
|
||||
.trim()
|
||||
gsonConverter.fromJson(content, ModelAutolinkingConfigJson::class.java)
|
||||
}
|
||||
.getOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
+48
@@ -186,6 +186,54 @@ class JsonUtilsTest {
|
||||
assertThat("implementation").isEqualTo(parsed.project!!.android!!.dependencyConfiguration)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromAutolinkingConfigJson_withInfoLogs_sanitizeAndParseIt() {
|
||||
@Suppress("JsonStandardCompliance")
|
||||
val validJson =
|
||||
createJsonFile(
|
||||
"""
|
||||
|
||||
> AwesomeProject@0.0.1 npx
|
||||
> rnc-cli config
|
||||
|
||||
{
|
||||
"reactNativeVersion": "1000.0.0",
|
||||
"project": {
|
||||
"ios": {
|
||||
"sourceDir": "./packages/rn-tester",
|
||||
"xcodeProject": {
|
||||
"name": "RNTesterPods.xcworkspace",
|
||||
"isWorkspace": true
|
||||
},
|
||||
"automaticPodsInstallation": false
|
||||
},
|
||||
"android": {
|
||||
"sourceDir": "./packages/rn-tester",
|
||||
"appName": "RN-Tester",
|
||||
"packageName": "com.facebook.react.uiapp",
|
||||
"applicationId": "com.facebook.react.uiapp",
|
||||
"mainActivity": ".RNTesterActivity",
|
||||
"watchModeCommandParams": [
|
||||
"--mode HermesDebug"
|
||||
],
|
||||
"dependencyConfiguration": "implementation"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent())
|
||||
val parsed = JsonUtils.fromAutolinkingConfigJson(validJson)!!
|
||||
|
||||
assertThat("./packages/rn-tester").isEqualTo(parsed.project!!.android!!.sourceDir)
|
||||
assertThat("RN-Tester").isEqualTo(parsed.project!!.android!!.appName)
|
||||
assertThat("com.facebook.react.uiapp").isEqualTo(parsed.project!!.android!!.packageName)
|
||||
assertThat("com.facebook.react.uiapp").isEqualTo(parsed.project!!.android!!.applicationId)
|
||||
assertThat(".RNTesterActivity").isEqualTo(parsed.project!!.android!!.mainActivity)
|
||||
assertThat("--mode HermesDebug")
|
||||
.isEqualTo(parsed.project!!.android!!.watchModeCommandParams!![0])
|
||||
assertThat("implementation").isEqualTo(parsed.project!!.android!!.dependencyConfiguration)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromAutolinkingConfigJson_withDependenciesSpecified_canParseIt() {
|
||||
val validJson =
|
||||
|
||||
Reference in New Issue
Block a user