@react-native/gradle-plugin 0.74.85 → 0.74.87
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/build.gradle.kts +2 -75
- package/package.json +4 -3
- package/react-native-gradle-plugin/build.gradle.kts +84 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/TestReactExtension.kt +12 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/BundleHermesCTaskTest.kt +434 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTaskTest.kt +212 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTaskTest.kt +192 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITaskTest.kt +27 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareBoostTaskTest.kt +105 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareGlogTaskTest.kt +130 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareJSCTaskTest.kt +128 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTaskTest.kt +201 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntryTest.kt +25 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/OsRule.kt +52 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/TaskTestUtils.kt +69 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/WithOs.kt +17 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/AgpConfiguratorUtilsTest.kt +65 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/BackwardCompatUtilsTest.kt +43 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt +404 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/FileUtilsTest.kt +45 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/JsonUtilsTest.kt +126 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtilsTest.kt +82 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt +46 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/OsTest.kt +86 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/PathUtilsTest.kt +325 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.kt +533 -0
- package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt +77 -0
- package/settings-plugin/build.gradle.kts +50 -0
- package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsPlugin.kt +24 -0
- package/settings.gradle.kts +6 -1
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactExtension.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactPlugin.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/TaskConfiguration.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfig.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfigAndroid.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelPackageJson.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITask.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareBoostTask.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareGlogTask.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareJSCTask.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTask.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntry.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/FileUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/JsonUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/Os.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PathUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PropertyUtils.kt +0 -0
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/TaskUtils.kt +0 -0
package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
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.createProject
|
|
11
|
+
import com.facebook.react.utils.DependencyUtils.configureDependencies
|
|
12
|
+
import com.facebook.react.utils.DependencyUtils.configureRepositories
|
|
13
|
+
import com.facebook.react.utils.DependencyUtils.getDependencySubstitutions
|
|
14
|
+
import com.facebook.react.utils.DependencyUtils.mavenRepoFromURI
|
|
15
|
+
import com.facebook.react.utils.DependencyUtils.mavenRepoFromUrl
|
|
16
|
+
import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
|
|
17
|
+
import java.net.URI
|
|
18
|
+
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
|
|
19
|
+
import org.gradle.testfixtures.ProjectBuilder
|
|
20
|
+
import org.junit.Assert.*
|
|
21
|
+
import org.junit.Rule
|
|
22
|
+
import org.junit.Test
|
|
23
|
+
import org.junit.rules.TemporaryFolder
|
|
24
|
+
|
|
25
|
+
class DependencyUtilsTest {
|
|
26
|
+
|
|
27
|
+
@get:Rule val tempFolder = TemporaryFolder()
|
|
28
|
+
|
|
29
|
+
@Test
|
|
30
|
+
fun configureRepositories_withProjectPropertySet_configuresMavenLocalCorrectly() {
|
|
31
|
+
val localMaven = tempFolder.newFolder("m2")
|
|
32
|
+
val localMavenURI = localMaven.toURI()
|
|
33
|
+
val project = createProject()
|
|
34
|
+
project.extensions.extraProperties.set("react.internal.mavenLocalRepo", localMaven.absolutePath)
|
|
35
|
+
|
|
36
|
+
configureRepositories(project, tempFolder.root)
|
|
37
|
+
|
|
38
|
+
assertNotNull(
|
|
39
|
+
project.repositories.firstOrNull {
|
|
40
|
+
it is MavenArtifactRepository && it.url == localMavenURI
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test
|
|
45
|
+
fun configureRepositories_containsSnapshotRepo() {
|
|
46
|
+
val repositoryURI = URI.create("https://oss.sonatype.org/content/repositories/snapshots/")
|
|
47
|
+
val project = createProject()
|
|
48
|
+
|
|
49
|
+
configureRepositories(project, tempFolder.root)
|
|
50
|
+
|
|
51
|
+
assertNotNull(
|
|
52
|
+
project.repositories.firstOrNull {
|
|
53
|
+
it is MavenArtifactRepository && it.url == repositoryURI
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Test
|
|
58
|
+
fun configureRepositories_containsJscLocalMavenRepo() {
|
|
59
|
+
val projectFolder = tempFolder.newFolder()
|
|
60
|
+
val reactNativeDir = tempFolder.newFolder("react-native")
|
|
61
|
+
val jscAndroidDir = tempFolder.newFolder("jsc-android")
|
|
62
|
+
val repositoryURI = URI.create("file://${jscAndroidDir}/dist")
|
|
63
|
+
val project = createProject(projectFolder)
|
|
64
|
+
|
|
65
|
+
configureRepositories(project, reactNativeDir)
|
|
66
|
+
|
|
67
|
+
assertNotNull(
|
|
68
|
+
project.repositories.firstOrNull {
|
|
69
|
+
it is MavenArtifactRepository && it.url == repositoryURI
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test
|
|
74
|
+
fun configureRepositories_containsMavenCentral() {
|
|
75
|
+
val repositoryURI = URI.create("https://repo.maven.apache.org/maven2/")
|
|
76
|
+
val project = createProject()
|
|
77
|
+
|
|
78
|
+
configureRepositories(project, tempFolder.root)
|
|
79
|
+
|
|
80
|
+
assertNotNull(
|
|
81
|
+
project.repositories.firstOrNull {
|
|
82
|
+
it is MavenArtifactRepository && it.url == repositoryURI
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Test
|
|
87
|
+
fun configureRepositories_containsGoogleRepo() {
|
|
88
|
+
val repositoryURI = URI.create("https://dl.google.com/dl/android/maven2/")
|
|
89
|
+
val project = createProject()
|
|
90
|
+
|
|
91
|
+
configureRepositories(project, tempFolder.root)
|
|
92
|
+
|
|
93
|
+
assertNotNull(
|
|
94
|
+
project.repositories.firstOrNull {
|
|
95
|
+
it is MavenArtifactRepository && it.url == repositoryURI
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Test
|
|
100
|
+
fun configureRepositories_containsJitPack() {
|
|
101
|
+
val repositoryURI = URI.create("https://www.jitpack.io")
|
|
102
|
+
val project = createProject()
|
|
103
|
+
|
|
104
|
+
configureRepositories(project, tempFolder.root)
|
|
105
|
+
|
|
106
|
+
assertNotNull(
|
|
107
|
+
project.repositories.firstOrNull {
|
|
108
|
+
it is MavenArtifactRepository && it.url == repositoryURI
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@Test
|
|
113
|
+
fun configureRepositories_withProjectPropertySet_hasHigherPriorityThanMavenCentral() {
|
|
114
|
+
val localMaven = tempFolder.newFolder("m2")
|
|
115
|
+
val localMavenURI = localMaven.toURI()
|
|
116
|
+
val mavenCentralURI = URI.create("https://repo.maven.apache.org/maven2/")
|
|
117
|
+
val project = createProject()
|
|
118
|
+
project.extensions.extraProperties.set("react.internal.mavenLocalRepo", localMaven.absolutePath)
|
|
119
|
+
|
|
120
|
+
configureRepositories(project, tempFolder.root)
|
|
121
|
+
|
|
122
|
+
val indexOfLocalRepo =
|
|
123
|
+
project.repositories.indexOfFirst {
|
|
124
|
+
it is MavenArtifactRepository && it.url == localMavenURI
|
|
125
|
+
}
|
|
126
|
+
val indexOfMavenCentral =
|
|
127
|
+
project.repositories.indexOfFirst {
|
|
128
|
+
it is MavenArtifactRepository && it.url == mavenCentralURI
|
|
129
|
+
}
|
|
130
|
+
assertTrue(indexOfLocalRepo < indexOfMavenCentral)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@Test
|
|
134
|
+
fun configureRepositories_snapshotRepoHasHigherPriorityThanMavenCentral() {
|
|
135
|
+
val repositoryURI = URI.create("https://oss.sonatype.org/content/repositories/snapshots/")
|
|
136
|
+
val mavenCentralURI = URI.create("https://repo.maven.apache.org/maven2/")
|
|
137
|
+
val project = createProject()
|
|
138
|
+
|
|
139
|
+
configureRepositories(project, tempFolder.root)
|
|
140
|
+
|
|
141
|
+
val indexOfSnapshotRepo =
|
|
142
|
+
project.repositories.indexOfFirst {
|
|
143
|
+
it is MavenArtifactRepository && it.url == repositoryURI
|
|
144
|
+
}
|
|
145
|
+
val indexOfMavenCentral =
|
|
146
|
+
project.repositories.indexOfFirst {
|
|
147
|
+
it is MavenArtifactRepository && it.url == mavenCentralURI
|
|
148
|
+
}
|
|
149
|
+
assertTrue(indexOfSnapshotRepo < indexOfMavenCentral)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@Test
|
|
153
|
+
fun configureRepositories_appliesToAllProjects() {
|
|
154
|
+
val repositoryURI = URI.create("https://repo.maven.apache.org/maven2/")
|
|
155
|
+
val rootProject = ProjectBuilder.builder().build()
|
|
156
|
+
val appProject = ProjectBuilder.builder().withName("app").withParent(rootProject).build()
|
|
157
|
+
val libProject = ProjectBuilder.builder().withName("lib").withParent(rootProject).build()
|
|
158
|
+
|
|
159
|
+
configureRepositories(appProject, tempFolder.root)
|
|
160
|
+
|
|
161
|
+
assertNotNull(
|
|
162
|
+
appProject.repositories.firstOrNull {
|
|
163
|
+
it is MavenArtifactRepository && it.url == repositoryURI
|
|
164
|
+
})
|
|
165
|
+
assertNotNull(
|
|
166
|
+
libProject.repositories.firstOrNull {
|
|
167
|
+
it is MavenArtifactRepository && it.url == repositoryURI
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@Test
|
|
172
|
+
fun configureRepositories_withPreviousExclusionRulesOnMavenCentral_appliesCorrectly() {
|
|
173
|
+
val repositoryURI = URI.create("https://repo.maven.apache.org/maven2/")
|
|
174
|
+
val rootProject = ProjectBuilder.builder().build()
|
|
175
|
+
val appProject = ProjectBuilder.builder().withName("app").withParent(rootProject).build()
|
|
176
|
+
val libProject = ProjectBuilder.builder().withName("lib").withParent(rootProject).build()
|
|
177
|
+
|
|
178
|
+
// Let's emulate a library which set an `excludeGroup` on `com.facebook.react` for Central.
|
|
179
|
+
libProject.repositories.mavenCentral { repo ->
|
|
180
|
+
repo.content { content -> content.excludeGroup("com.facebook.react") }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
configureRepositories(appProject, tempFolder.root)
|
|
184
|
+
|
|
185
|
+
// We need to make sure we have Maven Central defined twice, one by the library,
|
|
186
|
+
// and another is the override by RNGP.
|
|
187
|
+
assertEquals(
|
|
188
|
+
2,
|
|
189
|
+
libProject.repositories.count { it is MavenArtifactRepository && it.url == repositoryURI })
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@Test
|
|
193
|
+
fun configureDependencies_withEmptyVersion_doesNothing() {
|
|
194
|
+
val project = createProject()
|
|
195
|
+
|
|
196
|
+
configureDependencies(project, "")
|
|
197
|
+
|
|
198
|
+
assertTrue(project.configurations.first().resolutionStrategy.forcedModules.isEmpty())
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@Test
|
|
202
|
+
fun configureDependencies_withVersionString_appliesResolutionStrategy() {
|
|
203
|
+
val project = createProject()
|
|
204
|
+
|
|
205
|
+
configureDependencies(project, "1.2.3")
|
|
206
|
+
|
|
207
|
+
val forcedModules = project.configurations.first().resolutionStrategy.forcedModules
|
|
208
|
+
assertTrue(forcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" })
|
|
209
|
+
assertTrue(forcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" })
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@Test
|
|
213
|
+
fun configureDependencies_withVersionString_appliesOnAllProjects() {
|
|
214
|
+
val rootProject = ProjectBuilder.builder().build()
|
|
215
|
+
val appProject = ProjectBuilder.builder().withName("app").withParent(rootProject).build()
|
|
216
|
+
val libProject = ProjectBuilder.builder().withName("lib").withParent(rootProject).build()
|
|
217
|
+
appProject.plugins.apply("com.android.application")
|
|
218
|
+
libProject.plugins.apply("com.android.library")
|
|
219
|
+
|
|
220
|
+
configureDependencies(appProject, "1.2.3")
|
|
221
|
+
|
|
222
|
+
val appForcedModules = appProject.configurations.first().resolutionStrategy.forcedModules
|
|
223
|
+
val libForcedModules = libProject.configurations.first().resolutionStrategy.forcedModules
|
|
224
|
+
assertTrue(appForcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" })
|
|
225
|
+
assertTrue(appForcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" })
|
|
226
|
+
assertTrue(libForcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" })
|
|
227
|
+
assertTrue(libForcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" })
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@Test
|
|
231
|
+
fun configureDependencies_withVersionStringAndGroupString_appliesOnAllProjects() {
|
|
232
|
+
val rootProject = ProjectBuilder.builder().build()
|
|
233
|
+
val appProject = ProjectBuilder.builder().withName("app").withParent(rootProject).build()
|
|
234
|
+
val libProject = ProjectBuilder.builder().withName("lib").withParent(rootProject).build()
|
|
235
|
+
appProject.plugins.apply("com.android.application")
|
|
236
|
+
libProject.plugins.apply("com.android.library")
|
|
237
|
+
|
|
238
|
+
configureDependencies(appProject, "1.2.3", "io.github.test")
|
|
239
|
+
|
|
240
|
+
val appForcedModules = appProject.configurations.first().resolutionStrategy.forcedModules
|
|
241
|
+
val libForcedModules = libProject.configurations.first().resolutionStrategy.forcedModules
|
|
242
|
+
assertTrue(appForcedModules.any { it.toString() == "io.github.test:react-android:1.2.3" })
|
|
243
|
+
assertTrue(appForcedModules.any { it.toString() == "io.github.test:hermes-android:1.2.3" })
|
|
244
|
+
assertTrue(libForcedModules.any { it.toString() == "io.github.test:react-android:1.2.3" })
|
|
245
|
+
assertTrue(libForcedModules.any { it.toString() == "io.github.test:hermes-android:1.2.3" })
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@Test
|
|
249
|
+
fun getDependencySubstitutions_withDefaultGroup_substitutesCorrectly() {
|
|
250
|
+
val dependencySubstitutions = getDependencySubstitutions("0.42.0")
|
|
251
|
+
|
|
252
|
+
assertEquals(dependencySubstitutions[0].first, "com.facebook.react:react-native")
|
|
253
|
+
assertEquals(dependencySubstitutions[0].second, "com.facebook.react:react-android:0.42.0")
|
|
254
|
+
assertEquals(
|
|
255
|
+
dependencySubstitutions[0].third,
|
|
256
|
+
"The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.")
|
|
257
|
+
assertEquals(dependencySubstitutions[1].first, "com.facebook.react:hermes-engine")
|
|
258
|
+
assertEquals(dependencySubstitutions[1].second, "com.facebook.react:hermes-android:0.42.0")
|
|
259
|
+
assertEquals(
|
|
260
|
+
dependencySubstitutions[1].third,
|
|
261
|
+
"The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.")
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@Test
|
|
265
|
+
fun getDependencySubstitutions_withCustomGroup_substitutesCorrectly() {
|
|
266
|
+
val dependencySubstitutions = getDependencySubstitutions("0.42.0", "io.github.test")
|
|
267
|
+
|
|
268
|
+
assertEquals(dependencySubstitutions[0].first, "com.facebook.react:react-native")
|
|
269
|
+
assertEquals(dependencySubstitutions[0].second, "io.github.test:react-android:0.42.0")
|
|
270
|
+
assertEquals(
|
|
271
|
+
dependencySubstitutions[0].third,
|
|
272
|
+
"The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.")
|
|
273
|
+
assertEquals(dependencySubstitutions[1].first, "com.facebook.react:hermes-engine")
|
|
274
|
+
assertEquals(dependencySubstitutions[1].second, "io.github.test:hermes-android:0.42.0")
|
|
275
|
+
assertEquals(
|
|
276
|
+
dependencySubstitutions[1].third,
|
|
277
|
+
"The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.")
|
|
278
|
+
assertEquals(dependencySubstitutions[2].first, "com.facebook.react:react-android")
|
|
279
|
+
assertEquals(dependencySubstitutions[2].second, "io.github.test:react-android:0.42.0")
|
|
280
|
+
assertEquals(
|
|
281
|
+
dependencySubstitutions[2].third,
|
|
282
|
+
"The react-android dependency was modified to use the correct Maven group.")
|
|
283
|
+
assertEquals(dependencySubstitutions[3].first, "com.facebook.react:hermes-android")
|
|
284
|
+
assertEquals(dependencySubstitutions[3].second, "io.github.test:hermes-android:0.42.0")
|
|
285
|
+
assertEquals(
|
|
286
|
+
dependencySubstitutions[3].third,
|
|
287
|
+
"The hermes-android dependency was modified to use the correct Maven group.")
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@Test
|
|
291
|
+
fun readVersionString_withCorrectVersionString_returnsIt() {
|
|
292
|
+
val propertiesFile =
|
|
293
|
+
tempFolder.newFile("gradle.properties").apply {
|
|
294
|
+
writeText(
|
|
295
|
+
"""
|
|
296
|
+
VERSION_NAME=1000.0.0
|
|
297
|
+
ANOTHER_PROPERTY=true
|
|
298
|
+
"""
|
|
299
|
+
.trimIndent())
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
val versionString = readVersionAndGroupStrings(propertiesFile).first
|
|
303
|
+
|
|
304
|
+
assertEquals("1000.0.0", versionString)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
@Test
|
|
308
|
+
fun readVersionString_withNightlyVersionString_returnsSnapshotVersion() {
|
|
309
|
+
val propertiesFile =
|
|
310
|
+
tempFolder.newFile("gradle.properties").apply {
|
|
311
|
+
writeText(
|
|
312
|
+
"""
|
|
313
|
+
VERSION_NAME=0.0.0-20221101-2019-cfe811ab1
|
|
314
|
+
ANOTHER_PROPERTY=true
|
|
315
|
+
"""
|
|
316
|
+
.trimIndent())
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
val versionString = readVersionAndGroupStrings(propertiesFile).first
|
|
320
|
+
|
|
321
|
+
assertEquals("0.0.0-20221101-2019-cfe811ab1-SNAPSHOT", versionString)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
@Test
|
|
325
|
+
fun readVersionString_withMissingVersionString_returnsEmpty() {
|
|
326
|
+
val propertiesFile =
|
|
327
|
+
tempFolder.newFile("gradle.properties").apply {
|
|
328
|
+
writeText(
|
|
329
|
+
"""
|
|
330
|
+
ANOTHER_PROPERTY=true
|
|
331
|
+
"""
|
|
332
|
+
.trimIndent())
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
val versionString = readVersionAndGroupStrings(propertiesFile).first
|
|
336
|
+
assertEquals("", versionString)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
@Test
|
|
340
|
+
fun readVersionString_withEmptyVersionString_returnsEmpty() {
|
|
341
|
+
val propertiesFile =
|
|
342
|
+
tempFolder.newFile("gradle.properties").apply {
|
|
343
|
+
writeText(
|
|
344
|
+
"""
|
|
345
|
+
VERSION_NAME=
|
|
346
|
+
ANOTHER_PROPERTY=true
|
|
347
|
+
"""
|
|
348
|
+
.trimIndent())
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
val versionString = readVersionAndGroupStrings(propertiesFile).first
|
|
352
|
+
assertEquals("", versionString)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
@Test
|
|
356
|
+
fun readGroupString_withCorrectGroupString_returnsIt() {
|
|
357
|
+
val propertiesFile =
|
|
358
|
+
tempFolder.newFile("gradle.properties").apply {
|
|
359
|
+
writeText(
|
|
360
|
+
"""
|
|
361
|
+
react.internal.publishingGroup=io.github.test
|
|
362
|
+
ANOTHER_PROPERTY=true
|
|
363
|
+
"""
|
|
364
|
+
.trimIndent())
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
val groupString = readVersionAndGroupStrings(propertiesFile).second
|
|
368
|
+
|
|
369
|
+
assertEquals("io.github.test", groupString)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
@Test
|
|
373
|
+
fun readGroupString_withEmptyGroupString_returnsDefault() {
|
|
374
|
+
val propertiesFile =
|
|
375
|
+
tempFolder.newFile("gradle.properties").apply {
|
|
376
|
+
writeText(
|
|
377
|
+
"""
|
|
378
|
+
ANOTHER_PROPERTY=true
|
|
379
|
+
"""
|
|
380
|
+
.trimIndent())
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
val groupString = readVersionAndGroupStrings(propertiesFile).second
|
|
384
|
+
|
|
385
|
+
assertEquals("com.facebook.react", groupString)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
@Test
|
|
389
|
+
fun mavenRepoFromUrl_worksCorrectly() {
|
|
390
|
+
val process = createProject()
|
|
391
|
+
val mavenRepo = process.mavenRepoFromUrl("https://hello.world")
|
|
392
|
+
|
|
393
|
+
assertEquals(URI.create("https://hello.world"), mavenRepo.url)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
@Test
|
|
397
|
+
fun mavenRepoFromURI_worksCorrectly() {
|
|
398
|
+
val process = createProject()
|
|
399
|
+
val repoFolder = tempFolder.newFolder("maven-repo")
|
|
400
|
+
val mavenRepo = process.mavenRepoFromURI(repoFolder.toURI())
|
|
401
|
+
|
|
402
|
+
assertEquals(repoFolder.toURI(), mavenRepo.url)
|
|
403
|
+
}
|
|
404
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.io.File
|
|
11
|
+
import org.junit.Assert.*
|
|
12
|
+
import org.junit.Rule
|
|
13
|
+
import org.junit.Test
|
|
14
|
+
import org.junit.rules.TemporaryFolder
|
|
15
|
+
|
|
16
|
+
class FileUtilsTest {
|
|
17
|
+
|
|
18
|
+
@get:Rule val tempFolder = TemporaryFolder()
|
|
19
|
+
|
|
20
|
+
@Test
|
|
21
|
+
fun moveTo_movesCorrectly() {
|
|
22
|
+
val fileToMove = tempFolder.newFile().apply { writeText("42") }
|
|
23
|
+
val destFolder = tempFolder.newFolder("destFolder")
|
|
24
|
+
val destFile = File(destFolder, "destFile")
|
|
25
|
+
|
|
26
|
+
fileToMove.moveTo(destFile)
|
|
27
|
+
|
|
28
|
+
assertEquals("42", destFile.readText())
|
|
29
|
+
assertFalse(fileToMove.exists())
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Test
|
|
33
|
+
fun recreateDir_worksCorrectly() {
|
|
34
|
+
val subFolder = tempFolder.newFolder()
|
|
35
|
+
File(subFolder, "1").apply { writeText("1") }
|
|
36
|
+
File(subFolder, "2").apply { writeText("2") }
|
|
37
|
+
File(subFolder, "subDir").apply { mkdirs() }
|
|
38
|
+
File(subFolder, "subDir/3").apply { writeText("3") }
|
|
39
|
+
|
|
40
|
+
subFolder.recreateDir()
|
|
41
|
+
|
|
42
|
+
assertTrue(subFolder.exists())
|
|
43
|
+
assertEquals(0, subFolder.listFiles()?.size)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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.intellij.lang.annotations.Language
|
|
11
|
+
import org.junit.Assert.*
|
|
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 withInvalidJson_returnsNull() {
|
|
22
|
+
val invalidJson = createJsonFile("""¯\_(ツ)_/¯""")
|
|
23
|
+
|
|
24
|
+
assertNull(JsonUtils.fromPackageJson(invalidJson))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Test
|
|
28
|
+
fun withEmptyJson_returnsEmptyObject() {
|
|
29
|
+
val invalidJson = createJsonFile("""{}""")
|
|
30
|
+
|
|
31
|
+
val parsed = JsonUtils.fromPackageJson(invalidJson)
|
|
32
|
+
|
|
33
|
+
assertNotNull(parsed)
|
|
34
|
+
assertNull(parsed?.codegenConfig)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test
|
|
38
|
+
fun 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
|
+
val parsed = JsonUtils.fromPackageJson(oldJsonConfig)!!
|
|
58
|
+
|
|
59
|
+
assertNull(parsed.codegenConfig?.name)
|
|
60
|
+
assertNull(parsed.codegenConfig?.jsSrcsDir)
|
|
61
|
+
assertNull(parsed.codegenConfig?.android)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Test
|
|
65
|
+
fun withValidJson_parsesCorrectly() {
|
|
66
|
+
val validJson =
|
|
67
|
+
createJsonFile(
|
|
68
|
+
"""
|
|
69
|
+
{
|
|
70
|
+
"name": "yet another npm package",
|
|
71
|
+
"codegenConfig": {
|
|
72
|
+
"name": "an awesome library",
|
|
73
|
+
"jsSrcsDir": "../js/",
|
|
74
|
+
"android": {
|
|
75
|
+
"javaPackageName": "com.awesome.library"
|
|
76
|
+
},
|
|
77
|
+
"ios": {
|
|
78
|
+
"other ios only keys": "which are ignored during parsing"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
"""
|
|
83
|
+
.trimIndent())
|
|
84
|
+
|
|
85
|
+
val parsed = JsonUtils.fromPackageJson(validJson)!!
|
|
86
|
+
|
|
87
|
+
assertEquals("an awesome library", parsed.codegenConfig!!.name)
|
|
88
|
+
assertEquals("../js/", parsed.codegenConfig!!.jsSrcsDir)
|
|
89
|
+
assertEquals("com.awesome.library", parsed.codegenConfig!!.android!!.javaPackageName)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Test
|
|
93
|
+
fun fromReactNativePackageJson_withInvalidJson_returnsNull() {
|
|
94
|
+
val invalidJson = createJsonFile("""¯\_(ツ)_/¯""")
|
|
95
|
+
|
|
96
|
+
assertNull(JsonUtils.fromPackageJson(invalidJson))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Test
|
|
100
|
+
fun fromReactNativePackageJson_withEmptyJson_returnsEmptyObject() {
|
|
101
|
+
val invalidJson = createJsonFile("""{}""")
|
|
102
|
+
|
|
103
|
+
val parsed = JsonUtils.fromPackageJson(invalidJson)
|
|
104
|
+
|
|
105
|
+
assertNotNull(parsed)
|
|
106
|
+
assertNull(parsed?.version)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Test
|
|
110
|
+
fun fromReactNativePackageJson_withValidJson_parsesJsonCorrectly() {
|
|
111
|
+
val validJson =
|
|
112
|
+
createJsonFile(
|
|
113
|
+
"""
|
|
114
|
+
{
|
|
115
|
+
"version": "1000.0.0"
|
|
116
|
+
}
|
|
117
|
+
"""
|
|
118
|
+
.trimIndent())
|
|
119
|
+
val parsed = JsonUtils.fromPackageJson(validJson)!!
|
|
120
|
+
|
|
121
|
+
assertEquals("1000.0.0", parsed.version)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private fun createJsonFile(@Language("JSON") input: String) =
|
|
125
|
+
tempFolder.newFile().apply { writeText(input) }
|
|
126
|
+
}
|
|
@@ -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.junit.Assert.assertEquals
|
|
14
|
+
import org.junit.Test
|
|
15
|
+
|
|
16
|
+
class KotlinStdlibCompatUtilsTest {
|
|
17
|
+
|
|
18
|
+
@Test
|
|
19
|
+
fun lowercaseCompat_withEmptyString() {
|
|
20
|
+
assertEquals("", "".lowercaseCompat())
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
fun lowercaseCompat_withLowercaseString() {
|
|
25
|
+
assertEquals("frodo", "frodo".lowercaseCompat())
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Test
|
|
29
|
+
fun lowercaseCompat_withTitlecaseString() {
|
|
30
|
+
assertEquals("frodo", "Frodo".lowercaseCompat())
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Test
|
|
34
|
+
fun lowercaseCompat_withUppercaseString() {
|
|
35
|
+
assertEquals("frodo", "FRODO".lowercaseCompat())
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
fun capitalizeCompat_withEmptyString() {
|
|
40
|
+
assertEquals("", "".capitalizeCompat())
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Test
|
|
44
|
+
fun capitalizeCompat_withLowercaseString() {
|
|
45
|
+
assertEquals("Bilbo", "bilbo".capitalizeCompat())
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Test
|
|
49
|
+
fun capitalizeCompat_withTitlecaseString() {
|
|
50
|
+
assertEquals("Bilbo", "Bilbo".capitalizeCompat())
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Test
|
|
54
|
+
fun capitalizeCompat_withUppercaseString() {
|
|
55
|
+
assertEquals("BILBO", "BILBO".capitalizeCompat())
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Test
|
|
59
|
+
fun toBooleanStrictOrNullCompat_withEmptyString() {
|
|
60
|
+
assertEquals(null, "".toBooleanStrictOrNullCompat())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test
|
|
64
|
+
fun toBooleanStrictOrNullCompat_withfalse() {
|
|
65
|
+
assertEquals(false, "false".toBooleanStrictOrNullCompat())
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@Test
|
|
69
|
+
fun toBooleanStrictOrNullCompat_withCapitalTrue_returnsNull() {
|
|
70
|
+
assertEquals(null, "True".toBooleanStrictOrNullCompat())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test
|
|
74
|
+
fun toBooleanStrictOrNullCompat_withCapitalFalse_returnsNull() {
|
|
75
|
+
assertEquals(null, "False".toBooleanStrictOrNullCompat())
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Test
|
|
79
|
+
fun toBooleanStrictOrNullCompat_withRandomInput_returnsNull() {
|
|
80
|
+
assertEquals(null, "maybe".toBooleanStrictOrNullCompat())
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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.NdkConfiguratorUtils.getPackagingOptionsForVariant
|
|
11
|
+
import org.junit.Assert.assertFalse
|
|
12
|
+
import org.junit.Assert.assertTrue
|
|
13
|
+
import org.junit.Test
|
|
14
|
+
|
|
15
|
+
class NdkConfiguratorUtilsTest {
|
|
16
|
+
|
|
17
|
+
@Test
|
|
18
|
+
fun getPackagingOptionsForVariant_withHermesEnabled() {
|
|
19
|
+
val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled = true)
|
|
20
|
+
|
|
21
|
+
assertTrue("**/libjsc.so" in excludes)
|
|
22
|
+
assertTrue("**/libjscexecutor.so" in excludes)
|
|
23
|
+
assertFalse("**/libjsc.so" in includes)
|
|
24
|
+
assertFalse("**/libjscexecutor.so" in includes)
|
|
25
|
+
|
|
26
|
+
assertTrue("**/libhermes.so" in includes)
|
|
27
|
+
assertTrue("**/libhermes_executor.so" in includes)
|
|
28
|
+
assertFalse("**/libhermes.so" in excludes)
|
|
29
|
+
assertFalse("**/libhermes_executor.so" in excludes)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Test
|
|
33
|
+
fun getPackagingOptionsForVariant_withHermesDisabled() {
|
|
34
|
+
val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled = false)
|
|
35
|
+
|
|
36
|
+
assertTrue("**/libhermes.so" in excludes)
|
|
37
|
+
assertTrue("**/libhermes_executor.so" in excludes)
|
|
38
|
+
assertFalse("**/libhermes.so" in includes)
|
|
39
|
+
assertFalse("**/libhermes_executor.so" in includes)
|
|
40
|
+
|
|
41
|
+
assertTrue("**/libjsc.so" in includes)
|
|
42
|
+
assertTrue("**/libjscexecutor.so" in includes)
|
|
43
|
+
assertFalse("**/libjsc.so" in excludes)
|
|
44
|
+
assertFalse("**/libjscexecutor.so" in excludes)
|
|
45
|
+
}
|
|
46
|
+
}
|