@ohos-ports/react-native-gradle-plugin 0.71.19-beta.0 → 0.86.0-beta.0

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.
Files changed (74) hide show
  1. package/README.md +11 -4
  2. package/build.gradle.kts +33 -41
  3. package/gradle/libs.versions.toml +22 -0
  4. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  5. package/gradle/wrapper/gradle-wrapper.properties +3 -1
  6. package/gradle.properties +2 -0
  7. package/gradlew +32 -18
  8. package/gradlew.bat +22 -18
  9. package/package.json +21 -11
  10. package/react-native-gradle-plugin/README.md +17 -0
  11. package/react-native-gradle-plugin/build.gradle.kts +83 -0
  12. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactExtension.kt +78 -10
  13. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +320 -0
  14. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt +86 -0
  15. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/TaskConfiguration.kt +36 -25
  16. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt +11 -4
  17. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +60 -50
  18. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateAutolinkingNewArchitecturesFileTask.kt +252 -0
  19. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +8 -3
  20. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +11 -18
  21. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateEntryPointTask.kt +108 -0
  22. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GeneratePackageListTask.kt +214 -0
  23. package/{src/main/kotlin/com/facebook/react/tasks → react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal}/BuildCodegenCLITask.kt +24 -17
  24. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/CustomExecTask.kt +46 -0
  25. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareBoostTask.kt +10 -4
  26. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/PrepareGflagsTask.kt +119 -0
  27. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareGlogTask.kt +26 -18
  28. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTask.kt +28 -12
  29. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntry.kt +4 -3
  30. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +163 -0
  31. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +71 -0
  32. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +299 -0
  33. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt +64 -0
  34. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +59 -65
  35. package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PathUtils.kt +44 -30
  36. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +119 -0
  37. package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PropertyUtils.kt +96 -0
  38. package/settings-plugin/build.gradle.kts +73 -0
  39. package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt +217 -0
  40. package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsPlugin.kt +23 -0
  41. package/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt +475 -0
  42. package/settings.gradle.kts +10 -1
  43. package/shared/build.gradle.kts +52 -0
  44. package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingAndroidProjectJson.kt +18 -0
  45. package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingConfigJson.kt +14 -0
  46. package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesJson.kt +18 -0
  47. package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesPlatformAndroidJson.kt +23 -0
  48. package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesPlatformJson.kt +12 -0
  49. package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingProjectJson.kt +10 -0
  50. package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfig.kt +2 -1
  51. package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelPackageJson.kt +1 -1
  52. package/shared/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +43 -0
  53. package/shared/src/main/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtils.kt +32 -0
  54. package/{src → shared/src}/main/kotlin/com/facebook/react/utils/Os.kt +7 -6
  55. package/{src → shared/src}/main/kotlin/com/facebook/react/utils/TaskUtils.kt +4 -5
  56. package/shared/src/test/kotlin/com/facebook/react/utils/JsonUtilsTest.kt +382 -0
  57. package/shared/src/test/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtilsTest.kt +82 -0
  58. package/shared/src/test/kotlin/com/facebook/react/utils/OsTest.kt +87 -0
  59. package/shared/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt +76 -0
  60. package/shared-testutil/build.gradle.kts +46 -0
  61. package/shared-testutil/src/main/kotlin/com/facebook/react/tests/OsRule.kt +52 -0
  62. package/shared-testutil/src/main/kotlin/com/facebook/react/tests/WithOs.kt +17 -0
  63. package/build/libs/react-native-gradle-plugin.jar +0 -0
  64. package/index.js +0 -73
  65. package/src/main/kotlin/com/facebook/react/ReactPlugin.kt +0 -212
  66. package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareJSCTask.kt +0 -50
  67. package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareLibeventTask.kt +0 -51
  68. package/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +0 -54
  69. package/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +0 -48
  70. package/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +0 -109
  71. package/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +0 -21
  72. package/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +0 -55
  73. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/FileUtils.kt +0 -0
  74. /package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfigAndroid.kt +0 -0
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import com.facebook.react.model.ModelAutolinkingConfigJson
11
+ import com.facebook.react.model.ModelPackageJson
12
+ import com.google.gson.Gson
13
+ import java.io.File
14
+
15
+ object JsonUtils {
16
+ private val gsonConverter = Gson()
17
+
18
+ fun fromPackageJson(input: File): ModelPackageJson? =
19
+ input.bufferedReader().use {
20
+ runCatching { gsonConverter.fromJson(it, ModelPackageJson::class.java) }.getOrNull()
21
+ }
22
+
23
+ fun fromAutolinkingConfigJson(input: File): ModelAutolinkingConfigJson? =
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
+ }
41
+ .getOrNull()
42
+ }
43
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import java.util.Locale
11
+
12
+ object KotlinStdlibCompatUtils {
13
+ @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
14
+ fun String.lowercaseCompat(): String = (this as java.lang.String).toLowerCase(Locale.ROOT)
15
+
16
+ fun String.capitalizeCompat(): String =
17
+ if (isNotEmpty()) {
18
+ val firstChar = this[0]
19
+ val uppercaseChar = Character.toUpperCase(firstChar)
20
+ val restString = this@capitalizeCompat.substring(1)
21
+ uppercaseChar + restString
22
+ } else {
23
+ this
24
+ }
25
+
26
+ fun String.toBooleanStrictOrNullCompat(): Boolean? =
27
+ when (this) {
28
+ "true" -> true
29
+ "false" -> false
30
+ else -> null
31
+ }
32
+ }
@@ -7,18 +7,19 @@
7
7
 
8
8
  package com.facebook.react.utils
9
9
 
10
+ import com.facebook.react.utils.KotlinStdlibCompatUtils.lowercaseCompat
10
11
  import java.io.File
11
12
 
12
- internal object Os {
13
+ object Os {
13
14
 
14
15
  fun isWindows(): Boolean =
15
- System.getProperty("os.name")?.lowercase()?.contains("windows") ?: false
16
+ System.getProperty("os.name")?.lowercaseCompat()?.contains("windows") ?: false
16
17
 
17
- fun isMac(): Boolean = System.getProperty("os.name")?.lowercase()?.contains("mac") ?: false
18
+ fun isMac(): Boolean = System.getProperty("os.name")?.lowercaseCompat()?.contains("mac") ?: false
18
19
 
19
20
  fun isLinuxAmd64(): Boolean {
20
- val osNameMatch = System.getProperty("os.name")?.lowercase()?.contains("linux") ?: false
21
- val archMatch = System.getProperty("os.arch")?.lowercase()?.contains("amd64") ?: false
21
+ val osNameMatch = System.getProperty("os.name")?.lowercaseCompat()?.contains("linux") ?: false
22
+ val archMatch = System.getProperty("os.arch")?.lowercaseCompat()?.contains("amd64") ?: false
22
23
  return osNameMatch && archMatch
23
24
  }
24
25
 
@@ -39,6 +40,6 @@ internal object Os {
39
40
  if (isWindows()) {
40
41
  this.relativeTo(base).path
41
42
  } else {
42
- this.absolutePath
43
+ absolutePath
43
44
  }
44
45
  }
@@ -7,19 +7,18 @@
7
7
 
8
8
  package com.facebook.react.utils
9
9
 
10
- internal fun windowsAwareCommandLine(vararg args: Any): List<Any> =
11
- windowsAwareCommandLine(args.toList())
10
+ fun windowsAwareCommandLine(vararg args: Any): List<Any> = windowsAwareCommandLine(args.toList())
12
11
 
13
- internal fun windowsAwareCommandLine(args: List<Any>): List<Any> =
12
+ fun windowsAwareCommandLine(args: List<Any>): List<Any> =
14
13
  if (Os.isWindows()) {
15
14
  listOf("cmd", "/c") + args
16
15
  } else {
17
16
  args
18
17
  }
19
18
 
20
- internal fun windowsAwareBashCommandLine(
19
+ fun windowsAwareBashCommandLine(
21
20
  vararg args: String,
22
- bashWindowsHome: String? = null
21
+ bashWindowsHome: String? = null,
23
22
  ): List<String> =
24
23
  if (Os.isWindows()) {
25
24
  listOf(bashWindowsHome ?: "bash", "-c") + args
@@ -0,0 +1,382 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import org.assertj.core.api.Assertions.assertThat
11
+ import org.intellij.lang.annotations.Language
12
+ import org.junit.Rule
13
+ import org.junit.Test
14
+ import org.junit.rules.TemporaryFolder
15
+
16
+ class JsonUtilsTest {
17
+
18
+ @get:Rule val tempFolder = TemporaryFolder()
19
+
20
+ @Test
21
+ fun fromPackageJson_withInvalidJson_returnsNull() {
22
+ val invalidJson = createJsonFile("""¯\_(ツ)_/¯""")
23
+
24
+ assertThat(JsonUtils.fromPackageJson(invalidJson)).isNull()
25
+ }
26
+
27
+ @Test
28
+ fun fromPackageJson_withEmptyJson_returnsEmptyObject() {
29
+ val invalidJson = createJsonFile("""{}""")
30
+
31
+ val parsed = JsonUtils.fromPackageJson(invalidJson)
32
+
33
+ assertThat(parsed).isNotNull()
34
+ assertThat(parsed?.codegenConfig).isNull()
35
+ }
36
+
37
+ @Test
38
+ fun fromPackageJson_withOldJsonConfig_returnsAnEmptyLibrary() {
39
+ val oldJsonConfig =
40
+ createJsonFile(
41
+ """
42
+ {
43
+ "name": "yet another npm package",
44
+ "codegenConfig": {
45
+ "libraries": [
46
+ {
47
+ "name": "an awesome library",
48
+ "jsSrcsDir": "../js/",
49
+ "android": {}
50
+ }
51
+ ]
52
+ }
53
+ }
54
+ """
55
+ .trimIndent()
56
+ )
57
+
58
+ val parsed = JsonUtils.fromPackageJson(oldJsonConfig)!!
59
+
60
+ assertThat(parsed.codegenConfig?.name).isNull()
61
+ assertThat(parsed.codegenConfig?.jsSrcsDir).isNull()
62
+ assertThat(parsed.codegenConfig?.android).isNull()
63
+ }
64
+
65
+ @Test
66
+ fun fromPackageJson_withValidJson_parsesCorrectly() {
67
+ val validJson =
68
+ createJsonFile(
69
+ """
70
+ {
71
+ "name": "yet another npm package",
72
+ "codegenConfig": {
73
+ "name": "an awesome library",
74
+ "jsSrcsDir": "../js/",
75
+ "android": {
76
+ "javaPackageName": "com.awesome.library"
77
+ },
78
+ "ios": {
79
+ "other ios only keys": "which are ignored during parsing"
80
+ }
81
+ }
82
+ }
83
+ """
84
+ .trimIndent()
85
+ )
86
+
87
+ val parsed = JsonUtils.fromPackageJson(validJson)!!
88
+
89
+ assertThat("an awesome library").isEqualTo(parsed.codegenConfig!!.name)
90
+ assertThat("../js/").isEqualTo(parsed.codegenConfig!!.jsSrcsDir)
91
+ assertThat("com.awesome.library").isEqualTo(parsed.codegenConfig!!.android!!.javaPackageName)
92
+ }
93
+
94
+ @Test
95
+ fun fromReactNativePackageJson_withInvalidJson_returnsNull() {
96
+ val invalidJson = createJsonFile("""¯\_(ツ)_/¯""")
97
+
98
+ assertThat(JsonUtils.fromPackageJson(invalidJson)).isNull()
99
+ }
100
+
101
+ @Test
102
+ fun fromReactNativePackageJson_withEmptyJson_returnsEmptyObject() {
103
+ val invalidJson = createJsonFile("""{}""")
104
+
105
+ val parsed = JsonUtils.fromPackageJson(invalidJson)
106
+
107
+ assertThat(parsed).isNotNull()
108
+ assertThat(parsed?.version).isNull()
109
+ }
110
+
111
+ @Test
112
+ fun fromReactNativePackageJson_withValidJson_parsesJsonCorrectly() {
113
+ val validJson =
114
+ createJsonFile(
115
+ """
116
+ {
117
+ "version": "1000.0.0"
118
+ }
119
+ """
120
+ .trimIndent()
121
+ )
122
+ val parsed = JsonUtils.fromPackageJson(validJson)!!
123
+
124
+ assertThat("1000.0.0").isEqualTo(parsed.version)
125
+ }
126
+
127
+ @Test
128
+ fun fromAutolinkingConfigJson_withInvalidJson_returnsNull() {
129
+ val invalidJson = createJsonFile("""¯\_(ツ)_/¯""")
130
+
131
+ assertThat(JsonUtils.fromAutolinkingConfigJson(invalidJson)).isNull()
132
+ }
133
+
134
+ @Test
135
+ fun fromAutolinkingConfigJson_withSimpleJson_returnsIt() {
136
+ val validJson =
137
+ createJsonFile(
138
+ """
139
+ {
140
+ "reactNativeVersion": "1000.0.0"
141
+ }
142
+ """
143
+ .trimIndent()
144
+ )
145
+ val parsed = JsonUtils.fromAutolinkingConfigJson(validJson)!!
146
+
147
+ assertThat("1000.0.0").isEqualTo(parsed.reactNativeVersion)
148
+ }
149
+
150
+ @Test
151
+ fun fromAutolinkingConfigJson_withProjectSpecified_canParseIt() {
152
+ val validJson =
153
+ createJsonFile(
154
+ """
155
+ {
156
+ "reactNativeVersion": "1000.0.0",
157
+ "project": {
158
+ "ios": {
159
+ "sourceDir": "./packages/rn-tester",
160
+ "xcodeProject": {
161
+ "name": "RNTesterPods.xcworkspace",
162
+ "isWorkspace": true
163
+ },
164
+ "automaticPodsInstallation": false
165
+ },
166
+ "android": {
167
+ "sourceDir": "./packages/rn-tester",
168
+ "appName": "RN-Tester",
169
+ "packageName": "com.facebook.react.uiapp",
170
+ "applicationId": "com.facebook.react.uiapp",
171
+ "mainActivity": ".RNTesterActivity",
172
+ "watchModeCommandParams": [
173
+ "--mode HermesDebug"
174
+ ],
175
+ "dependencyConfiguration": "implementation"
176
+ }
177
+ }
178
+ }
179
+ """
180
+ .trimIndent()
181
+ )
182
+ val parsed = JsonUtils.fromAutolinkingConfigJson(validJson)!!
183
+
184
+ assertThat("./packages/rn-tester").isEqualTo(parsed.project!!.android!!.sourceDir)
185
+ assertThat("RN-Tester").isEqualTo(parsed.project!!.android!!.appName)
186
+ assertThat("com.facebook.react.uiapp").isEqualTo(parsed.project!!.android!!.packageName)
187
+ assertThat("com.facebook.react.uiapp").isEqualTo(parsed.project!!.android!!.applicationId)
188
+ assertThat(".RNTesterActivity").isEqualTo(parsed.project!!.android!!.mainActivity)
189
+ assertThat("--mode HermesDebug")
190
+ .isEqualTo(parsed.project!!.android!!.watchModeCommandParams!![0])
191
+ assertThat("implementation").isEqualTo(parsed.project!!.android!!.dependencyConfiguration)
192
+ }
193
+
194
+ @Test
195
+ fun fromAutolinkingConfigJson_withInfoLogs_sanitizeAndParseIt() {
196
+ @Suppress("JsonStandardCompliance")
197
+ val validJson =
198
+ createJsonFile(
199
+ """
200
+
201
+ > AwesomeProject@0.0.1 npx
202
+ > rnc-cli config
203
+
204
+ {
205
+ "reactNativeVersion": "1000.0.0",
206
+ "project": {
207
+ "ios": {
208
+ "sourceDir": "./packages/rn-tester",
209
+ "xcodeProject": {
210
+ "name": "RNTesterPods.xcworkspace",
211
+ "isWorkspace": true
212
+ },
213
+ "automaticPodsInstallation": false
214
+ },
215
+ "android": {
216
+ "sourceDir": "./packages/rn-tester",
217
+ "appName": "RN-Tester",
218
+ "packageName": "com.facebook.react.uiapp",
219
+ "applicationId": "com.facebook.react.uiapp",
220
+ "mainActivity": ".RNTesterActivity",
221
+ "watchModeCommandParams": [
222
+ "--mode HermesDebug"
223
+ ],
224
+ "dependencyConfiguration": "implementation"
225
+ }
226
+ }
227
+ }
228
+ """
229
+ .trimIndent()
230
+ )
231
+ val parsed = JsonUtils.fromAutolinkingConfigJson(validJson)!!
232
+
233
+ assertThat("./packages/rn-tester").isEqualTo(parsed.project!!.android!!.sourceDir)
234
+ assertThat("RN-Tester").isEqualTo(parsed.project!!.android!!.appName)
235
+ assertThat("com.facebook.react.uiapp").isEqualTo(parsed.project!!.android!!.packageName)
236
+ assertThat("com.facebook.react.uiapp").isEqualTo(parsed.project!!.android!!.applicationId)
237
+ assertThat(".RNTesterActivity").isEqualTo(parsed.project!!.android!!.mainActivity)
238
+ assertThat("--mode HermesDebug")
239
+ .isEqualTo(parsed.project!!.android!!.watchModeCommandParams!![0])
240
+ assertThat("implementation").isEqualTo(parsed.project!!.android!!.dependencyConfiguration)
241
+ }
242
+
243
+ @Test
244
+ fun fromAutolinkingConfigJson_withDependenciesSpecified_canParseIt() {
245
+ val validJson =
246
+ createJsonFile(
247
+ """
248
+ {
249
+ "reactNativeVersion": "1000.0.0",
250
+ "dependencies": {
251
+ "@react-native/oss-library-example": {
252
+ "root": "./node_modules/@react-native/oss-library-example",
253
+ "name": "@react-native/oss-library-example",
254
+ "platforms": {
255
+ "ios": {
256
+ "podspecPath": "./node_modules/@react-native/oss-library-example/OSSLibraryExample.podspec",
257
+ "version": "0.0.1",
258
+ "configurations": [],
259
+ "scriptPhases": []
260
+ },
261
+ "android": {
262
+ "sourceDir": "./node_modules/@react-native/oss-library-example/android",
263
+ "packageImportPath": "import com.facebook.react.osslibraryexample.OSSLibraryExamplePackage;",
264
+ "packageInstance": "new OSSLibraryExamplePackage()",
265
+ "buildTypes": ["staging", "debug", "release"],
266
+ "libraryName": "OSSLibraryExampleSpec",
267
+ "componentDescriptors": [
268
+ "SampleNativeComponentComponentDescriptor"
269
+ ],
270
+ "cmakeListsPath": "./node_modules/@react-native/oss-library-example/android/build/generated/source/codegen/jni/CMakeLists.txt",
271
+ "cxxModuleCMakeListsModuleName": null,
272
+ "cxxModuleCMakeListsPath": null,
273
+ "cxxModuleHeaderName": null,
274
+ "dependencyConfiguration": "implementation",
275
+ "isPureCxxDependency": false
276
+ }
277
+ }
278
+ }
279
+ }
280
+ }
281
+ """
282
+ .trimIndent()
283
+ )
284
+ val parsed = JsonUtils.fromAutolinkingConfigJson(validJson)!!
285
+
286
+ assertThat("./node_modules/@react-native/oss-library-example")
287
+ .isEqualTo(parsed.dependencies!!["@react-native/oss-library-example"]!!.root)
288
+ assertThat("@react-native/oss-library-example")
289
+ .isEqualTo(parsed.dependencies!!["@react-native/oss-library-example"]!!.name)
290
+ assertThat("react-native_oss-library-example")
291
+ .isEqualTo(parsed.dependencies!!["@react-native/oss-library-example"]!!.nameCleansed)
292
+ assertThat("./node_modules/@react-native/oss-library-example/android")
293
+ .isEqualTo(
294
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
295
+ .platforms!!
296
+ .android!!
297
+ .sourceDir
298
+ )
299
+ assertThat("import com.facebook.react.osslibraryexample.OSSLibraryExamplePackage;")
300
+ .isEqualTo(
301
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
302
+ .platforms!!
303
+ .android!!
304
+ .packageImportPath
305
+ )
306
+ assertThat("new OSSLibraryExamplePackage()")
307
+ .isEqualTo(
308
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
309
+ .platforms!!
310
+ .android!!
311
+ .packageInstance
312
+ )
313
+ assertThat(listOf("staging", "debug", "release"))
314
+ .isEqualTo(
315
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
316
+ .platforms!!
317
+ .android!!
318
+ .buildTypes
319
+ )
320
+ assertThat("OSSLibraryExampleSpec")
321
+ .isEqualTo(
322
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
323
+ .platforms!!
324
+ .android!!
325
+ .libraryName
326
+ )
327
+ assertThat(listOf("SampleNativeComponentComponentDescriptor"))
328
+ .isEqualTo(
329
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
330
+ .platforms!!
331
+ .android!!
332
+ .componentDescriptors
333
+ )
334
+ assertThat(
335
+ "./node_modules/@react-native/oss-library-example/android/build/generated/source/codegen/jni/CMakeLists.txt"
336
+ )
337
+ .isEqualTo(
338
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
339
+ .platforms!!
340
+ .android!!
341
+ .cmakeListsPath
342
+ )
343
+ assertThat(
344
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
345
+ .platforms!!
346
+ .android!!
347
+ .cxxModuleHeaderName
348
+ )
349
+ .isNull()
350
+ assertThat(
351
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
352
+ .platforms!!
353
+ .android!!
354
+ .cxxModuleCMakeListsPath
355
+ )
356
+ .isNull()
357
+ assertThat(
358
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
359
+ .platforms!!
360
+ .android!!
361
+ .cxxModuleCMakeListsModuleName
362
+ )
363
+ .isNull()
364
+ assertThat("implementation")
365
+ .isEqualTo(
366
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
367
+ .platforms!!
368
+ .android!!
369
+ .dependencyConfiguration
370
+ )
371
+ assertThat(
372
+ parsed.dependencies!!["@react-native/oss-library-example"]!!
373
+ .platforms!!
374
+ .android!!
375
+ .isPureCxxDependency!!
376
+ )
377
+ .isFalse()
378
+ }
379
+
380
+ private fun createJsonFile(@Language("JSON") input: String) =
381
+ tempFolder.newFile().apply { writeText(input) }
382
+ }
@@ -0,0 +1,82 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import com.facebook.react.utils.KotlinStdlibCompatUtils.capitalizeCompat
11
+ import com.facebook.react.utils.KotlinStdlibCompatUtils.lowercaseCompat
12
+ import com.facebook.react.utils.KotlinStdlibCompatUtils.toBooleanStrictOrNullCompat
13
+ import org.assertj.core.api.Assertions.assertThat
14
+ import org.junit.Test
15
+
16
+ class KotlinStdlibCompatUtilsTest {
17
+
18
+ @Test
19
+ fun lowercaseCompat_withEmptyString() {
20
+ assertThat("".lowercaseCompat()).isEqualTo("")
21
+ }
22
+
23
+ @Test
24
+ fun lowercaseCompat_withLowercaseString() {
25
+ assertThat("frodo".lowercaseCompat()).isEqualTo("frodo")
26
+ }
27
+
28
+ @Test
29
+ fun lowercaseCompat_withTitlecaseString() {
30
+ assertThat("Frodo".lowercaseCompat()).isEqualTo("frodo")
31
+ }
32
+
33
+ @Test
34
+ fun lowercaseCompat_withUppercaseString() {
35
+ assertThat("FRODO".lowercaseCompat()).isEqualTo("frodo")
36
+ }
37
+
38
+ @Test
39
+ fun capitalizeCompat_withEmptyString() {
40
+ assertThat("".capitalizeCompat()).isEqualTo("")
41
+ }
42
+
43
+ @Test
44
+ fun capitalizeCompat_withLowercaseString() {
45
+ assertThat("bilbo".capitalizeCompat()).isEqualTo("Bilbo")
46
+ }
47
+
48
+ @Test
49
+ fun capitalizeCompat_withTitlecaseString() {
50
+ assertThat("Bilbo".capitalizeCompat()).isEqualTo("Bilbo")
51
+ }
52
+
53
+ @Test
54
+ fun capitalizeCompat_withUppercaseString() {
55
+ assertThat("BILBO".capitalizeCompat()).isEqualTo("BILBO")
56
+ }
57
+
58
+ @Test
59
+ fun toBooleanStrictOrNullCompat_withEmptyString() {
60
+ assertThat("".toBooleanStrictOrNullCompat()).isNull()
61
+ }
62
+
63
+ @Test
64
+ fun toBooleanStrictOrNullCompat_withfalse() {
65
+ assertThat("false".toBooleanStrictOrNullCompat()).isFalse()
66
+ }
67
+
68
+ @Test
69
+ fun toBooleanStrictOrNullCompat_withCapitalTrue_returnsNull() {
70
+ assertThat("True".toBooleanStrictOrNullCompat()).isNull()
71
+ }
72
+
73
+ @Test
74
+ fun toBooleanStrictOrNullCompat_withCapitalFalse_returnsNull() {
75
+ assertThat("False".toBooleanStrictOrNullCompat()).isNull()
76
+ }
77
+
78
+ @Test
79
+ fun toBooleanStrictOrNullCompat_withRandomInput_returnsNull() {
80
+ assertThat("maybe".toBooleanStrictOrNullCompat()).isNull()
81
+ }
82
+ }
@@ -0,0 +1,87 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import com.facebook.react.tests.OS
11
+ import com.facebook.react.tests.OsRule
12
+ import com.facebook.react.tests.WithOs
13
+ import com.facebook.react.utils.Os.cliPath
14
+ import com.facebook.react.utils.Os.unixifyPath
15
+ import org.assertj.core.api.Assertions.assertThat
16
+ import org.junit.Rule
17
+ import org.junit.Test
18
+ import org.junit.rules.TemporaryFolder
19
+
20
+ class OsTest {
21
+
22
+ @get:Rule val osRule = OsRule()
23
+ @get:Rule val tempFolder = TemporaryFolder()
24
+
25
+ @Test
26
+ @WithOs(OS.LINUX, "amd64")
27
+ fun onLinuxAmd64_checksOsCorrectly() {
28
+ assertThat(Os.isWindows()).isFalse()
29
+ assertThat(Os.isMac()).isFalse()
30
+ assertThat(Os.isLinuxAmd64()).isTrue()
31
+ }
32
+
33
+ @Test
34
+ @WithOs(OS.MAC)
35
+ fun onMac_checksOsCorrectly() {
36
+ assertThat(Os.isWindows()).isFalse()
37
+ assertThat(Os.isMac()).isTrue()
38
+ assertThat(Os.isLinuxAmd64()).isFalse()
39
+ }
40
+
41
+ @Test
42
+ @WithOs(OS.WIN)
43
+ fun isWindows_onWindows_returnsTrue() {
44
+ assertThat(Os.isWindows()).isTrue()
45
+ assertThat(Os.isMac()).isFalse()
46
+ assertThat(Os.isLinuxAmd64()).isFalse()
47
+ }
48
+
49
+ @Test
50
+ fun unixifyPath_withAUnixPath_doesNothing() {
51
+ val aUnixPath = "/just/a/unix/path.sh"
52
+
53
+ assertThat(aUnixPath).isEqualTo(aUnixPath.unixifyPath())
54
+ }
55
+
56
+ @Test
57
+ fun unixifyPath_withAWindowsPath_convertsItCorrectly() {
58
+ val aWindowsPath = "D:\\just\\a\\windows\\path\\"
59
+
60
+ assertThat("/D/just/a/windows/path/").isEqualTo(aWindowsPath.unixifyPath())
61
+ }
62
+
63
+ @Test
64
+ @WithOs(OS.WIN)
65
+ fun cliPath_onWindows_returnsRelativePath() {
66
+ val tempFile = tempFolder.newFile("test.txt").apply { createNewFile() }
67
+
68
+ assertThat(tempFile.relativeTo(tempFolder.root).path)
69
+ .isEqualTo(tempFile.cliPath(tempFolder.root))
70
+ }
71
+
72
+ @Test
73
+ @WithOs(OS.LINUX)
74
+ fun cliPath_onLinux_returnsAbsolutePath() {
75
+ val tempFile = tempFolder.newFile("test.txt").apply { createNewFile() }
76
+
77
+ assertThat(tempFile.absolutePath).isEqualTo(tempFile.cliPath(tempFolder.root))
78
+ }
79
+
80
+ @Test
81
+ @WithOs(OS.MAC)
82
+ fun cliPath_onMac_returnsAbsolutePath() {
83
+ val tempFile = tempFolder.newFile("test.txt").apply { createNewFile() }
84
+
85
+ assertThat(tempFile.absolutePath).isEqualTo(tempFile.cliPath(tempFolder.root))
86
+ }
87
+ }