@react-native/gradle-plugin 0.74.84 → 0.74.86

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 (60) hide show
  1. package/build.gradle.kts +2 -75
  2. package/package.json +4 -3
  3. package/react-native-gradle-plugin/build.gradle.kts +84 -0
  4. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/TestReactExtension.kt +12 -0
  5. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/BundleHermesCTaskTest.kt +434 -0
  6. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTaskTest.kt +212 -0
  7. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTaskTest.kt +192 -0
  8. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITaskTest.kt +27 -0
  9. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareBoostTaskTest.kt +105 -0
  10. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareGlogTaskTest.kt +130 -0
  11. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PrepareJSCTaskTest.kt +128 -0
  12. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTaskTest.kt +201 -0
  13. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntryTest.kt +25 -0
  14. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/OsRule.kt +52 -0
  15. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/TaskTestUtils.kt +69 -0
  16. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tests/WithOs.kt +17 -0
  17. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/AgpConfiguratorUtilsTest.kt +65 -0
  18. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/BackwardCompatUtilsTest.kt +43 -0
  19. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt +404 -0
  20. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/FileUtilsTest.kt +45 -0
  21. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/JsonUtilsTest.kt +126 -0
  22. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtilsTest.kt +82 -0
  23. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt +46 -0
  24. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/OsTest.kt +86 -0
  25. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/PathUtilsTest.kt +325 -0
  26. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/ProjectUtilsTest.kt +533 -0
  27. package/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt +77 -0
  28. package/settings-plugin/build.gradle.kts +50 -0
  29. package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsPlugin.kt +24 -0
  30. package/settings.gradle.kts +6 -1
  31. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactExtension.kt +0 -0
  32. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactPlugin.kt +0 -0
  33. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt +0 -0
  34. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/TaskConfiguration.kt +0 -0
  35. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt +0 -0
  36. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfig.kt +0 -0
  37. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfigAndroid.kt +0 -0
  38. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/model/ModelPackageJson.kt +0 -0
  39. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +0 -0
  40. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +0 -0
  41. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +0 -0
  42. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/BuildCodegenCLITask.kt +0 -0
  43. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareBoostTask.kt +0 -0
  44. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareGlogTask.kt +0 -0
  45. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareJSCTask.kt +0 -0
  46. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTask.kt +0 -0
  47. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntry.kt +0 -0
  48. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +0 -0
  49. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +0 -0
  50. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +0 -0
  51. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/FileUtils.kt +0 -0
  52. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt +0 -0
  53. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/JsonUtils.kt +0 -0
  54. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtils.kt +0 -0
  55. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +0 -0
  56. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/Os.kt +0 -0
  57. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PathUtils.kt +0 -0
  58. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +0 -0
  59. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PropertyUtils.kt +0 -0
  60. /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/TaskUtils.kt +0 -0
@@ -0,0 +1,533 @@
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.TestReactExtension
11
+ import com.facebook.react.model.ModelCodegenConfig
12
+ import com.facebook.react.model.ModelPackageJson
13
+ import com.facebook.react.tests.createProject
14
+ import com.facebook.react.utils.ProjectUtils.getReactNativeArchitectures
15
+ import com.facebook.react.utils.ProjectUtils.isHermesEnabled
16
+ import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
17
+ import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
18
+ import com.facebook.react.utils.ProjectUtils.shouldWarnIfNewArchFlagIsSetInPrealpha
19
+ import java.io.File
20
+ import org.junit.Assert.*
21
+ import org.junit.Rule
22
+ import org.junit.Test
23
+ import org.junit.rules.TemporaryFolder
24
+
25
+ class ProjectUtilsTest {
26
+
27
+ @get:Rule val tempFolder = TemporaryFolder()
28
+
29
+ @Test
30
+ fun isNewArchEnabled_returnsFalseByDefault() {
31
+ val project = createProject()
32
+ val extension = TestReactExtension(project)
33
+ assertFalse(createProject().isNewArchEnabled(extension))
34
+ }
35
+
36
+ @Test
37
+ fun isNewArchEnabled_withDisabled_returnsFalse() {
38
+ val project = createProject()
39
+ project.extensions.extraProperties.set("newArchEnabled", "false")
40
+ val extension = TestReactExtension(project)
41
+ assertFalse(project.isNewArchEnabled(extension))
42
+ }
43
+
44
+ @Test
45
+ fun isNewArchEnabled_withEnabled_returnsTrue() {
46
+ val project = createProject()
47
+ project.extensions.extraProperties.set("newArchEnabled", "true")
48
+ val extension = TestReactExtension(project)
49
+ assertTrue(project.isNewArchEnabled(extension))
50
+ }
51
+
52
+ @Test
53
+ fun isNewArchEnabled_withInvalid_returnsFalse() {
54
+ val project = createProject()
55
+ project.extensions.extraProperties.set("newArchEnabled", "¯\\_(ツ)_/¯")
56
+ val extension = TestReactExtension(project)
57
+ assertFalse(project.isNewArchEnabled(extension))
58
+ }
59
+
60
+ @Test
61
+ fun isNewArchEnabled_withRNVersion0_returnFalse() {
62
+ val project = createProject()
63
+ val extension = TestReactExtension(project)
64
+ File(tempFolder.root, "package.json").apply {
65
+ writeText(
66
+ // language=json
67
+ """
68
+ {
69
+ "version": "0.73.0"
70
+ }
71
+ """
72
+ .trimIndent())
73
+ }
74
+ extension.reactNativeDir.set(tempFolder.root)
75
+ assertFalse(project.isNewArchEnabled(extension))
76
+ }
77
+
78
+ @Test
79
+ fun isNewArchEnabled_withRNVersionPrealpha_returnTrue() {
80
+ val project = createProject()
81
+ val extension = TestReactExtension(project)
82
+ File(tempFolder.root, "package.json").apply {
83
+ writeText(
84
+ // language=json
85
+ """
86
+ {
87
+ "version": "0.0.0-prealpha-202310916"
88
+ }
89
+ """
90
+ .trimIndent())
91
+ }
92
+ extension.reactNativeDir.set(tempFolder.root)
93
+ assertTrue(project.isNewArchEnabled(extension))
94
+ }
95
+
96
+ @Test
97
+ fun isNewArchEnabled_withRNVersion1PrereleaseString_returnTrue() {
98
+ val project = createProject()
99
+ val extension = TestReactExtension(project)
100
+ File(tempFolder.root, "package.json").apply {
101
+ writeText(
102
+ // language=json
103
+ """
104
+ {
105
+ "version": "1.2.3-prealpha0"
106
+ }
107
+ """
108
+ .trimIndent())
109
+ }
110
+ extension.reactNativeDir.set(tempFolder.root)
111
+ assertTrue(project.isNewArchEnabled(extension))
112
+ }
113
+
114
+ @Test
115
+ fun isNewArchEnabled_withRNVersion1PrereleaseStringDotNumber_returnTrue() {
116
+ val project = createProject()
117
+ val extension = TestReactExtension(project)
118
+ File(tempFolder.root, "package.json").apply {
119
+ writeText(
120
+ // language=json
121
+ """
122
+ {
123
+ "version": "1.2.3-prealpha.0"
124
+ }
125
+ """
126
+ .trimIndent())
127
+ }
128
+ extension.reactNativeDir.set(tempFolder.root)
129
+ assertTrue(project.isNewArchEnabled(extension))
130
+ }
131
+
132
+ @Test
133
+ fun isNewArchEnabled_withRNVersion1PrereleaseStringDashNumber_returnTrue() {
134
+ val project = createProject()
135
+ val extension = TestReactExtension(project)
136
+ File(tempFolder.root, "package.json").apply {
137
+ writeText(
138
+ // language=json
139
+ """
140
+ {
141
+ "version": "1.2.3-prealpha-0"
142
+ }
143
+ """
144
+ .trimIndent())
145
+ }
146
+ extension.reactNativeDir.set(tempFolder.root)
147
+ assertTrue(project.isNewArchEnabled(extension))
148
+ }
149
+
150
+ @Test
151
+ fun isNewArchEnabled_withRNVersion1000_returnFalse() {
152
+ val project = createProject()
153
+ val extension = TestReactExtension(project)
154
+ File(tempFolder.root, "package.json").apply {
155
+ writeText(
156
+ // language=json
157
+ """
158
+ {
159
+ "version": "1000.0.0"
160
+ }
161
+ """
162
+ .trimIndent())
163
+ }
164
+ extension.reactNativeDir.set(tempFolder.root)
165
+ assertFalse(project.isNewArchEnabled(extension))
166
+ }
167
+
168
+ @Test
169
+ fun isHermesEnabled_returnsTrueByDefault() {
170
+ assertTrue(createProject().isHermesEnabled)
171
+ }
172
+
173
+ @Test
174
+ fun isNewArchEnabled_withDisabledViaProperty_returnsFalse() {
175
+ val project = createProject()
176
+ project.extensions.extraProperties.set("hermesEnabled", "false")
177
+ assertFalse(project.isHermesEnabled)
178
+ }
179
+
180
+ @Test
181
+ fun isHermesEnabled_withEnabledViaProperty_returnsTrue() {
182
+ val project = createProject()
183
+ project.extensions.extraProperties.set("hermesEnabled", "true")
184
+ assertTrue(project.isHermesEnabled)
185
+ }
186
+
187
+ @Test
188
+ fun isHermesEnabled_withInvalidViaProperty_returnsTrue() {
189
+ val project = createProject()
190
+ project.extensions.extraProperties.set("hermesEnabled", "¯\\_(ツ)_/¯")
191
+ assertTrue(project.isHermesEnabled)
192
+ }
193
+
194
+ @Test
195
+ fun isHermesEnabled_withDisabledViaExt_returnsFalse() {
196
+ val project = createProject()
197
+ val extMap = mapOf("enableHermes" to false)
198
+ project.extensions.extraProperties.set("react", extMap)
199
+ assertFalse(project.isHermesEnabled)
200
+ }
201
+
202
+ @Test
203
+ fun isHermesEnabled_withEnabledViaExt_returnsTrue() {
204
+ val project = createProject()
205
+ val extMap = mapOf("enableHermes" to true)
206
+ project.extensions.extraProperties.set("react", extMap)
207
+ assertTrue(project.isHermesEnabled)
208
+ }
209
+
210
+ @Test
211
+ fun isHermesEnabled_withDisabledViaExtAsString_returnsFalse() {
212
+ val project = createProject()
213
+ val extMap = mapOf("enableHermes" to "false")
214
+ project.extensions.extraProperties.set("react", extMap)
215
+ assertFalse(project.isHermesEnabled)
216
+ }
217
+
218
+ @Test
219
+ fun isHermesEnabled_withInvalidViaExt_returnsTrue() {
220
+ val project = createProject()
221
+ val extMap = mapOf("enableHermes" to "¯\\_(ツ)_/¯")
222
+ project.extensions.extraProperties.set("react", extMap)
223
+ assertTrue(project.isHermesEnabled)
224
+ }
225
+
226
+ @Test
227
+ fun needsCodegenFromPackageJson_withCodegenConfigInPackageJson_returnsTrue() {
228
+ val project = createProject()
229
+ val extension = TestReactExtension(project)
230
+ File(tempFolder.root, "package.json").apply {
231
+ writeText(
232
+ // language=json
233
+ """
234
+ {
235
+ "name": "a-library",
236
+ "codegenConfig": {}
237
+ }
238
+ """
239
+ .trimIndent())
240
+ }
241
+ extension.root.set(tempFolder.root)
242
+ assertTrue(project.needsCodegenFromPackageJson(extension.root))
243
+ }
244
+
245
+ @Test
246
+ fun needsCodegenFromPackageJson_withMissingCodegenConfigInPackageJson_returnsFalse() {
247
+ val project = createProject()
248
+ val extension = TestReactExtension(project)
249
+ File(tempFolder.root, "package.json").apply {
250
+ writeText(
251
+ // language=json
252
+ """
253
+ {
254
+ "name": "a-library"
255
+ }
256
+ """
257
+ .trimIndent())
258
+ }
259
+ extension.root.set(tempFolder.root)
260
+ assertFalse(project.needsCodegenFromPackageJson(extension.root))
261
+ }
262
+
263
+ @Test
264
+ fun needsCodegenFromPackageJson_withCodegenConfigInModel_returnsTrue() {
265
+ val project = createProject()
266
+ val model = ModelPackageJson("1000.0.0", ModelCodegenConfig(null, null, null, null, false))
267
+
268
+ assertTrue(project.needsCodegenFromPackageJson(model))
269
+ }
270
+
271
+ @Test
272
+ fun needsCodegenFromPackageJson_withMissingCodegenConfigInModel_returnsFalse() {
273
+ val project = createProject()
274
+ val model = ModelPackageJson("1000.0.0", null)
275
+
276
+ assertFalse(project.needsCodegenFromPackageJson(model))
277
+ }
278
+
279
+ @Test
280
+ fun needsCodegenFromPackageJson_withMissingPackageJson_returnsFalse() {
281
+ val project = createProject()
282
+ val extension = TestReactExtension(project)
283
+
284
+ assertFalse(project.needsCodegenFromPackageJson(extension.root))
285
+ }
286
+
287
+ @Test
288
+ fun getReactNativeArchitectures_withMissingProperty_returnsEmptyList() {
289
+ val project = createProject()
290
+ assertTrue(project.getReactNativeArchitectures().isEmpty())
291
+ }
292
+
293
+ @Test
294
+ fun getReactNativeArchitectures_withEmptyProperty_returnsEmptyList() {
295
+ val project = createProject()
296
+ project.extensions.extraProperties.set("reactNativeArchitectures", "")
297
+ assertTrue(project.getReactNativeArchitectures().isEmpty())
298
+ }
299
+
300
+ @Test
301
+ fun getReactNativeArchitectures_withSingleArch_returnsSingleton() {
302
+ val project = createProject()
303
+ project.extensions.extraProperties.set("reactNativeArchitectures", "x86")
304
+
305
+ val archs = project.getReactNativeArchitectures()
306
+ assertEquals(1, archs.size)
307
+ assertEquals("x86", archs[0])
308
+ }
309
+
310
+ @Test
311
+ fun getReactNativeArchitectures_withMultipleArch_returnsList() {
312
+ val project = createProject()
313
+ project.extensions.extraProperties.set(
314
+ "reactNativeArchitectures", "armeabi-v7a,arm64-v8a,x86,x86_64")
315
+
316
+ val archs = project.getReactNativeArchitectures()
317
+ assertEquals(4, archs.size)
318
+ assertEquals("armeabi-v7a", archs[0])
319
+ assertEquals("arm64-v8a", archs[1])
320
+ assertEquals("x86", archs[2])
321
+ assertEquals("x86_64", archs[3])
322
+ }
323
+
324
+ @Test
325
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToFalseAndOnPrealpha_returnTrue() {
326
+ val project = createProject()
327
+ project.extensions.extraProperties.set("newArchEnabled", "false")
328
+ val extension = TestReactExtension(project)
329
+ File(tempFolder.root, "package.json").apply {
330
+ writeText(
331
+ // language=json
332
+ """
333
+ {
334
+ "version": "0.0.0-prealpha-2023100915"
335
+ }
336
+ """
337
+ .trimIndent())
338
+ }
339
+ extension.reactNativeDir.set(tempFolder.root)
340
+ assertTrue(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
341
+ }
342
+
343
+ @Test
344
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToFalseAndOnPrealpha_returnTrue() {
345
+ val project = createProject()
346
+ project.extensions.extraProperties.set("react.newArchEnabled", "false")
347
+ val extension = TestReactExtension(project)
348
+ File(tempFolder.root, "package.json").apply {
349
+ writeText(
350
+ // language=json
351
+ """
352
+ {
353
+ "version": "0.0.0-prealpha-2023100915"
354
+ }
355
+ """
356
+ .trimIndent())
357
+ }
358
+ extension.reactNativeDir.set(tempFolder.root)
359
+ assertTrue(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
360
+ }
361
+
362
+ @Test
363
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToFalseAndOnPrealpha_returnTrue() {
364
+ val project = createProject()
365
+ project.extensions.extraProperties.set("newArchEnabled", "false")
366
+ project.extensions.extraProperties.set("react.newArchEnabled", "false")
367
+ val extension = TestReactExtension(project)
368
+ File(tempFolder.root, "package.json").apply {
369
+ writeText(
370
+ // language=json
371
+ """
372
+ {
373
+ "version": "0.0.0-prealpha-2023100915"
374
+ }
375
+ """
376
+ .trimIndent())
377
+ }
378
+ extension.reactNativeDir.set(tempFolder.root)
379
+ assertTrue(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
380
+ }
381
+
382
+ @Test
383
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToTrueAndOnPrealpha_returnFalse() {
384
+ val project = createProject()
385
+ project.extensions.extraProperties.set("newArchEnabled", "true")
386
+ val extension = TestReactExtension(project)
387
+ File(tempFolder.root, "package.json").apply {
388
+ writeText(
389
+ // language=json
390
+ """
391
+ {
392
+ "version": "0.0.0-prealpha-2023100915"
393
+ }
394
+ """
395
+ .trimIndent())
396
+ }
397
+ extension.reactNativeDir.set(tempFolder.root)
398
+ assertFalse(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
399
+ }
400
+
401
+ @Test
402
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToTrueAndOnPrealpha_returnFalse() {
403
+ val project = createProject()
404
+ project.extensions.extraProperties.set("react.newArchEnabled", "true")
405
+ val extension = TestReactExtension(project)
406
+ File(tempFolder.root, "package.json").apply {
407
+ writeText(
408
+ // language=json
409
+ """
410
+ {
411
+ "version": "0.0.0-prealpha-2023100915"
412
+ }
413
+ """
414
+ .trimIndent())
415
+ }
416
+ extension.reactNativeDir.set(tempFolder.root)
417
+ assertFalse(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
418
+ }
419
+
420
+ @Test
421
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToTrueAndOnPrealpha_returnFalse() {
422
+ val project = createProject()
423
+ project.extensions.extraProperties.set("newArchEnabled", "true")
424
+ project.extensions.extraProperties.set("react.newArchEnabled", "true")
425
+ val extension = TestReactExtension(project)
426
+ File(tempFolder.root, "package.json").apply {
427
+ writeText(
428
+ // language=json
429
+ """
430
+ {
431
+ "version": "0.0.0-prealpha-2023100915"
432
+ }
433
+ """
434
+ .trimIndent())
435
+ }
436
+ extension.reactNativeDir.set(tempFolder.root)
437
+ assertFalse(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
438
+ }
439
+
440
+ @Test
441
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNoneAreSetAndOnPrealpha_returnFalse() {
442
+ val project = createProject()
443
+ val extension = TestReactExtension(project)
444
+ File(tempFolder.root, "package.json").apply {
445
+ writeText(
446
+ // language=json
447
+ """
448
+ {
449
+ "version": "0.0.0-prealpha-2023100915"
450
+ }
451
+ """
452
+ .trimIndent())
453
+ }
454
+ extension.reactNativeDir.set(tempFolder.root)
455
+ assertFalse(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
456
+ }
457
+
458
+ @Test
459
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNewArchIsSetToTrueAndNotOnPrealpha_returnFalse() {
460
+ val project = createProject()
461
+ project.extensions.extraProperties.set("newxArchEnabled", "true")
462
+ val extension = TestReactExtension(project)
463
+ File(tempFolder.root, "package.json").apply {
464
+ writeText(
465
+ // language=json
466
+ """
467
+ {
468
+ "version": "0.73.0"
469
+ }
470
+ """
471
+ .trimIndent())
472
+ }
473
+ extension.reactNativeDir.set(tempFolder.root)
474
+ assertFalse(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
475
+ }
476
+
477
+ @Test
478
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenScopedNewArchIsSetToTrueAndNotOnPrealpha_returnFalse() {
479
+ val project = createProject()
480
+ project.extensions.extraProperties.set("react.newxArchEnabled", "true")
481
+ val extension = TestReactExtension(project)
482
+ File(tempFolder.root, "package.json").apply {
483
+ writeText(
484
+ // language=json
485
+ """
486
+ {
487
+ "version": "0.73.0"
488
+ }
489
+ """
490
+ .trimIndent())
491
+ }
492
+ extension.reactNativeDir.set(tempFolder.root)
493
+ assertFalse(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
494
+ }
495
+
496
+ @Test
497
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenBothAreSetToTrueAndNotOnPrealpha_returnFalse() {
498
+ val project = createProject()
499
+ project.extensions.extraProperties.set("newArchEnabled", "true")
500
+ project.extensions.extraProperties.set("react.newxArchEnabled", "true")
501
+ val extension = TestReactExtension(project)
502
+ File(tempFolder.root, "package.json").apply {
503
+ writeText(
504
+ // language=json
505
+ """
506
+ {
507
+ "version": "0.73.0"
508
+ }
509
+ """
510
+ .trimIndent())
511
+ }
512
+ extension.reactNativeDir.set(tempFolder.root)
513
+ assertFalse(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
514
+ }
515
+
516
+ @Test
517
+ fun shouldWarnIfNewArchFlagIsSetInPrealpha_whenNoneAreSetAndNotOnPrealpha_returnFalse() {
518
+ val project = createProject()
519
+ val extension = TestReactExtension(project)
520
+ File(tempFolder.root, "package.json").apply {
521
+ writeText(
522
+ // language=json
523
+ """
524
+ {
525
+ "version": "0.73.0"
526
+ }
527
+ """
528
+ .trimIndent())
529
+ }
530
+ extension.reactNativeDir.set(tempFolder.root)
531
+ assertFalse(project.shouldWarnIfNewArchFlagIsSetInPrealpha(extension))
532
+ }
533
+ }
@@ -0,0 +1,77 @@
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 org.junit.Assert.assertEquals
14
+ import org.junit.Assert.assertTrue
15
+ import org.junit.Rule
16
+ import org.junit.Test
17
+
18
+ class TaskUtilsTest {
19
+
20
+ @get:Rule val osRule = OsRule()
21
+
22
+ @Test
23
+ fun windowsAwareCommandLine_withEmptyInput_isEmpty() {
24
+ assertTrue(windowsAwareCommandLine().isEmpty())
25
+ }
26
+
27
+ @Test
28
+ fun windowsAwareCommandLine_withList_isEqualAsVararg() {
29
+ assertEquals(
30
+ windowsAwareCommandLine(listOf("a", "b", "c")), windowsAwareCommandLine("a", "b", "c"))
31
+ }
32
+
33
+ @Test
34
+ @WithOs(OS.MAC)
35
+ fun windowsAwareCommandLine_onMac_returnsTheList() {
36
+ assertEquals(listOf("a", "b", "c"), windowsAwareCommandLine("a", "b", "c"))
37
+ }
38
+
39
+ @Test
40
+ @WithOs(OS.LINUX)
41
+ fun windowsAwareCommandLine_onLinux_returnsTheList() {
42
+ assertEquals(listOf("a", "b", "c"), windowsAwareCommandLine("a", "b", "c"))
43
+ }
44
+
45
+ @Test
46
+ @WithOs(OS.WIN)
47
+ fun windowsAwareCommandLine_onWindows_prependsCmd() {
48
+ assertEquals(listOf("cmd", "/c", "a", "b", "c"), windowsAwareCommandLine("a", "b", "c"))
49
+ }
50
+
51
+ @Test
52
+ @WithOs(OS.MAC)
53
+ fun windowsAwareBashCommandLine_onMac_returnsTheList() {
54
+ assertEquals(
55
+ listOf("a", "b", "c"), windowsAwareBashCommandLine("a", "b", "c", bashWindowsHome = "abc"))
56
+ }
57
+
58
+ @Test
59
+ @WithOs(OS.LINUX)
60
+ fun windowsAwareBashCommandLine_onLinux_returnsTheList() {
61
+ assertEquals(listOf("a", "b", "c"), windowsAwareBashCommandLine("a", "b", "c"))
62
+ }
63
+
64
+ @Test
65
+ @WithOs(OS.WIN)
66
+ fun windowsAwareBashCommandLine_onWindows_prependsBash() {
67
+ assertEquals(listOf("bash", "-c", "a", "b", "c"), windowsAwareBashCommandLine("a", "b", "c"))
68
+ }
69
+
70
+ @Test
71
+ @WithOs(OS.WIN)
72
+ fun windowsAwareBashCommandLine_onWindows_prependsCustomBashPath() {
73
+ assertEquals(
74
+ listOf("/custom/bash", "-c", "a", "b", "c"),
75
+ windowsAwareBashCommandLine("a", "b", "c", bashWindowsHome = "/custom/bash"))
76
+ }
77
+ }
@@ -0,0 +1,50 @@
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
+ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
9
+ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
10
+
11
+ plugins {
12
+ alias(libs.plugins.kotlin.jvm)
13
+ id("java-gradle-plugin")
14
+ }
15
+
16
+ repositories {
17
+ google()
18
+ mavenCentral()
19
+ }
20
+
21
+ gradlePlugin {
22
+ plugins {
23
+ create("react.settings") {
24
+ id = "com.facebook.react.settings"
25
+ implementationClass = "com.facebook.react.ReactSettingsPlugin"
26
+ }
27
+ }
28
+ }
29
+
30
+ group = "com.facebook.react"
31
+
32
+ dependencies {
33
+ implementation(gradleApi())
34
+ }
35
+
36
+ // We intentionally don't build for Java 17 as users will see a cryptic bytecode version
37
+ // error first. Instead we produce a Java 11-compatible Gradle Plugin, so that AGP can print their
38
+ // nice message showing that JDK 11 (or 17) is required first
39
+ java { targetCompatibility = JavaVersion.VERSION_11 }
40
+
41
+ kotlin { jvmToolchain(17) }
42
+
43
+ tasks.withType<KotlinCompile>().configureEach {
44
+ kotlinOptions {
45
+ apiVersion = "1.6"
46
+ // See comment above on JDK 11 support
47
+ jvmTarget = "11"
48
+ allWarningsAsErrors = true
49
+ }
50
+ }
@@ -0,0 +1,24 @@
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
9
+
10
+ import org.gradle.api.Plugin
11
+ import org.gradle.api.initialization.Settings
12
+
13
+ /**
14
+ * This is a stub of the com.facebook.react.settings plugin.
15
+ *
16
+ * The plugin got added in 0.75, but to make it easier for 0.74 users to upgrade to 0.75, we're
17
+ * creating a stub plugin that does nothing. This way, users can include a `id("com.facebook.react.settings")`
18
+ * in their settings.gradle file without causing a build failure on 0.74.
19
+ */
20
+ class ReactSettingsPlugin : Plugin<Settings> {
21
+ override fun apply(settings: Settings) {
22
+ // Do nothing, just register the plugin.
23
+ }
24
+ }
@@ -15,4 +15,9 @@ pluginManagement {
15
15
 
16
16
  plugins { id("org.gradle.toolchains.foojay-resolver-convention").version("0.5.0") }
17
17
 
18
- rootProject.name = "react-native-gradle-plugin"
18
+ include(
19
+ ":react-native-gradle-plugin",
20
+ ":settings-plugin",
21
+ )
22
+
23
+ rootProject.name = "gradle-plugin-root"