@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.
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
package/build.gradle.kts CHANGED
@@ -5,80 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import org.gradle.api.internal.classpath.ModuleRegistry
9
- import org.gradle.api.tasks.testing.logging.TestExceptionFormat
10
- import org.gradle.configurationcache.extensions.serviceOf
11
- import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
12
-
13
8
  plugins {
14
- alias(libs.plugins.kotlin.jvm)
9
+ alias(libs.plugins.kotlin.jvm).apply(false)
15
10
  id("java-gradle-plugin")
16
- }
17
-
18
- repositories {
19
- google()
20
- mavenCentral()
21
- }
22
-
23
- gradlePlugin {
24
- plugins {
25
- create("react") {
26
- id = "com.facebook.react"
27
- implementationClass = "com.facebook.react.ReactPlugin"
28
- }
29
- create("reactrootproject") {
30
- id = "com.facebook.react.rootproject"
31
- implementationClass = "com.facebook.react.ReactRootProjectPlugin"
32
- }
33
- }
34
- }
35
-
36
- group = "com.facebook.react"
37
-
38
- dependencies {
39
- implementation(gradleApi())
40
-
41
- // The KGP/AGP version is defined by React Native Gradle plugin.
42
- // Therefore we specify an implementation dep rather than a compileOnly.
43
- implementation(libs.kotlin.gradle.plugin)
44
- implementation(libs.android.gradle.plugin)
45
-
46
- implementation(libs.gson)
47
- implementation(libs.guava)
48
- implementation(libs.javapoet)
49
-
50
- testImplementation(libs.junit)
51
-
52
- testRuntimeOnly(
53
- files(
54
- serviceOf<ModuleRegistry>()
55
- .getModule("gradle-tooling-api-builders")
56
- .classpath
57
- .asFiles
58
- .first()))
59
- }
60
-
61
- // We intentionally don't build for Java 17 as users will see a cryptic bytecode version
62
- // error first. Instead we produce a Java 11-compatible Gradle Plugin, so that AGP can print their
63
- // nice message showing that JDK 11 (or 17) is required first
64
- java { targetCompatibility = JavaVersion.VERSION_11 }
65
-
66
- kotlin { jvmToolchain(17) }
67
-
68
- tasks.withType<KotlinCompile>().configureEach {
69
- kotlinOptions {
70
- apiVersion = "1.6"
71
- // See comment above on JDK 11 support
72
- jvmTarget = "11"
73
- allWarningsAsErrors = true
74
- }
75
- }
76
-
77
- tasks.withType<Test>().configureEach {
78
- testLogging {
79
- exceptionFormat = TestExceptionFormat.FULL
80
- showExceptions = true
81
- showCauses = true
82
- showStackTraces = true
83
- }
84
- }
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/gradle-plugin",
3
- "version": "0.74.85",
3
+ "version": "0.74.87",
4
4
  "description": "Gradle Plugin for React Native",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,8 @@
29
29
  "gradle",
30
30
  "gradlew",
31
31
  "gradlew.bat",
32
- "src/main",
33
- "README.md"
32
+ "README.md",
33
+ "react-native-gradle-plugin",
34
+ "settings-plugin"
34
35
  ]
35
36
  }
@@ -0,0 +1,84 @@
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.internal.classpath.ModuleRegistry
9
+ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
10
+ import org.gradle.configurationcache.extensions.serviceOf
11
+ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
12
+
13
+ plugins {
14
+ alias(libs.plugins.kotlin.jvm)
15
+ id("java-gradle-plugin")
16
+ }
17
+
18
+ repositories {
19
+ google()
20
+ mavenCentral()
21
+ }
22
+
23
+ gradlePlugin {
24
+ plugins {
25
+ create("react") {
26
+ id = "com.facebook.react"
27
+ implementationClass = "com.facebook.react.ReactPlugin"
28
+ }
29
+ create("reactrootproject") {
30
+ id = "com.facebook.react.rootproject"
31
+ implementationClass = "com.facebook.react.ReactRootProjectPlugin"
32
+ }
33
+ }
34
+ }
35
+
36
+ group = "com.facebook.react"
37
+
38
+ dependencies {
39
+ implementation(gradleApi())
40
+
41
+ // The KGP/AGP version is defined by React Native Gradle plugin.
42
+ // Therefore we specify an implementation dep rather than a compileOnly.
43
+ implementation(libs.kotlin.gradle.plugin)
44
+ implementation(libs.android.gradle.plugin)
45
+
46
+ implementation(libs.gson)
47
+ implementation(libs.guava)
48
+ implementation(libs.javapoet)
49
+
50
+ testImplementation(libs.junit)
51
+
52
+ testRuntimeOnly(
53
+ files(
54
+ serviceOf<ModuleRegistry>()
55
+ .getModule("gradle-tooling-api-builders")
56
+ .classpath
57
+ .asFiles
58
+ .first()))
59
+ }
60
+
61
+ // We intentionally don't build for Java 17 as users will see a cryptic bytecode version
62
+ // error first. Instead we produce a Java 11-compatible Gradle Plugin, so that AGP can print their
63
+ // nice message showing that JDK 11 (or 17) is required first
64
+ java { targetCompatibility = JavaVersion.VERSION_11 }
65
+
66
+ kotlin { jvmToolchain(17) }
67
+
68
+ tasks.withType<KotlinCompile>().configureEach {
69
+ kotlinOptions {
70
+ apiVersion = "1.6"
71
+ // See comment above on JDK 11 support
72
+ jvmTarget = "11"
73
+ allWarningsAsErrors = true
74
+ }
75
+ }
76
+
77
+ tasks.withType<Test>().configureEach {
78
+ testLogging {
79
+ exceptionFormat = TestExceptionFormat.FULL
80
+ showExceptions = true
81
+ showCauses = true
82
+ showStackTraces = true
83
+ }
84
+ }
@@ -0,0 +1,12 @@
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.Project
11
+
12
+ class TestReactExtension(project: Project) : ReactExtension(project)
@@ -0,0 +1,434 @@
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.tasks
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.tests.createTestTask
14
+ import java.io.File
15
+ import org.junit.Assert.*
16
+ import org.junit.Rule
17
+ import org.junit.Test
18
+ import org.junit.rules.TemporaryFolder
19
+
20
+ class BundleHermesCTaskTest {
21
+
22
+ @get:Rule val tempFolder = TemporaryFolder()
23
+
24
+ @get:Rule val osRule = OsRule()
25
+
26
+ @Test
27
+ fun bundleTask_groupIsSetCorrectly() {
28
+ val task = createTestTask<BundleHermesCTask> {}
29
+ assertEquals("react", task.group)
30
+ }
31
+
32
+ @Test
33
+ fun bundleTask_inputFiles_areSetCorrectly() {
34
+ val rootDir =
35
+ tempFolder.newFolder("js").apply {
36
+ File(this, "file.js").createNewFile()
37
+ File(this, "file.jsx").createNewFile()
38
+ File(this, "file.ts").createNewFile()
39
+ File(this, "file.tsx").createNewFile()
40
+ }
41
+
42
+ val task = createTestTask<BundleHermesCTask> { it.root.set(rootDir) }
43
+
44
+ assertEquals(4, task.sources.files.size)
45
+ assertEquals(
46
+ setOf(
47
+ File(rootDir, "file.js"),
48
+ File(rootDir, "file.jsx"),
49
+ File(rootDir, "file.ts"),
50
+ File(rootDir, "file.tsx")),
51
+ task.sources.files)
52
+ }
53
+
54
+ @Test
55
+ fun bundleTask_inputFilesInExcludedPath_areExcluded() {
56
+ fun File.createFileAndPath() {
57
+ parentFile.mkdirs()
58
+ createNewFile()
59
+ }
60
+
61
+ val rootDir =
62
+ tempFolder.newFolder("js").apply {
63
+ File(this, "afolder/includedfile.js").createFileAndPath()
64
+ // Those files should be excluded due to their filepath
65
+ File(this, "android/excludedfile.js").createFileAndPath()
66
+ File(this, "ios/excludedfile.js").createFileAndPath()
67
+ File(this, "build/excludedfile.js").createFileAndPath()
68
+ File(this, "node_modules/react-native/excludedfile.js").createFileAndPath()
69
+ }
70
+
71
+ val task = createTestTask<BundleHermesCTask> { it.root.set(rootDir) }
72
+
73
+ assertEquals(
74
+ setOf(
75
+ "**/android/**/*",
76
+ "**/ios/**/*",
77
+ "**/build/**/*",
78
+ "**/node_modules/**/*",
79
+ ),
80
+ task.sources.excludes)
81
+ assertEquals(1, task.sources.files.size)
82
+ assertEquals(setOf(File(rootDir, "afolder/includedfile.js")), task.sources.files)
83
+ }
84
+
85
+ @Test
86
+ fun bundleTask_staticInputs_areSetCorrectly() {
87
+ val task =
88
+ createTestTask<BundleHermesCTask> {
89
+ it.nodeExecutableAndArgs.set(listOf("node", "arg1", "arg2"))
90
+ it.bundleCommand.set("bundle")
91
+ it.bundleAssetName.set("myassetname")
92
+ it.minifyEnabled.set(true)
93
+ it.hermesEnabled.set(true)
94
+ it.devEnabled.set(true)
95
+ it.extraPackagerArgs.set(listOf("extra", "arg"))
96
+ it.hermesCommand.set("./my-hermesc")
97
+ it.hermesFlags.set(listOf("flag1", "flag2"))
98
+ }
99
+
100
+ assertEquals(listOf("node", "arg1", "arg2"), task.nodeExecutableAndArgs.get())
101
+ assertEquals("bundle", task.bundleCommand.get())
102
+ assertEquals("myassetname", task.bundleAssetName.get())
103
+ assertTrue(task.minifyEnabled.get())
104
+ assertTrue(task.hermesEnabled.get())
105
+ assertTrue(task.devEnabled.get())
106
+ assertEquals(listOf("extra", "arg"), task.extraPackagerArgs.get())
107
+ assertEquals("./my-hermesc", task.hermesCommand.get())
108
+ assertEquals(listOf("flag1", "flag2"), task.hermesFlags.get())
109
+ }
110
+
111
+ @Test
112
+ fun bundleTask_filesInput_areSetCorrectly() {
113
+ val entryFile = tempFolder.newFile("entry.js")
114
+ val cliFile = tempFolder.newFile("cli.js")
115
+ val jsBundleDir = tempFolder.newFolder("jsbundle")
116
+ val resourcesDir = tempFolder.newFolder("resources")
117
+ val jsIntermediateSourceMapsDir = tempFolder.newFolder("jsIntermediateSourceMaps")
118
+ val jsSourceMapsDir = tempFolder.newFolder("jsSourceMaps")
119
+ val bundleConfig = tempFolder.newFile("bundle.config")
120
+ val reactNativeDir = tempFolder.newFolder("node_modules/react-native")
121
+
122
+ val task =
123
+ createTestTask<BundleHermesCTask> {
124
+ it.entryFile.set(entryFile)
125
+ it.cliFile.set(cliFile)
126
+ it.jsBundleDir.set(jsBundleDir)
127
+ it.resourcesDir.set(resourcesDir)
128
+ it.jsIntermediateSourceMapsDir.set(jsIntermediateSourceMapsDir)
129
+ it.jsSourceMapsDir.set(jsSourceMapsDir)
130
+ it.bundleConfig.set(bundleConfig)
131
+ it.reactNativeDir.set(reactNativeDir)
132
+ }
133
+
134
+ assertEquals(entryFile, task.entryFile.get().asFile)
135
+ assertEquals(cliFile, task.cliFile.get().asFile)
136
+ assertEquals(jsBundleDir, task.jsBundleDir.get().asFile)
137
+ assertEquals(resourcesDir, task.resourcesDir.get().asFile)
138
+ assertEquals(jsIntermediateSourceMapsDir, task.jsIntermediateSourceMapsDir.get().asFile)
139
+ assertEquals(jsSourceMapsDir, task.jsSourceMapsDir.get().asFile)
140
+ assertEquals(bundleConfig, task.bundleConfig.get().asFile)
141
+ assertEquals(reactNativeDir, task.reactNativeDir.get().asFile)
142
+ }
143
+
144
+ @Test
145
+ fun resolvePackagerSourceMapFile_withHermesEnabled_returnsCorrectFile() {
146
+ val jsIntermediateSourceMapsDir = tempFolder.newFolder("jsIntermediateSourceMaps")
147
+ val bundleAssetName = "myassetname"
148
+ val task =
149
+ createTestTask<BundleHermesCTask> {
150
+ it.jsIntermediateSourceMapsDir.set(jsIntermediateSourceMapsDir)
151
+ it.hermesEnabled.set(true)
152
+ it.bundleAssetName.set(bundleAssetName)
153
+ }
154
+
155
+ assertEquals(
156
+ File(jsIntermediateSourceMapsDir, "myassetname.packager.map"),
157
+ task.resolvePackagerSourceMapFile(bundleAssetName))
158
+ }
159
+
160
+ @Test
161
+ fun resolvePackagerSourceMapFile_withHermesDisabled_returnsCorrectFile() {
162
+ val jsSourceMapsDir = tempFolder.newFolder("jsSourceMaps")
163
+ val bundleAssetName = "myassetname"
164
+ val task =
165
+ createTestTask<BundleHermesCTask> {
166
+ it.jsSourceMapsDir.set(jsSourceMapsDir)
167
+ it.hermesEnabled.set(false)
168
+ }
169
+
170
+ assertEquals(
171
+ File(jsSourceMapsDir, "myassetname.map"),
172
+ task.resolvePackagerSourceMapFile(bundleAssetName))
173
+ }
174
+
175
+ @Test
176
+ fun resolveOutputSourceMap_returnsCorrectFile() {
177
+ val jsSourceMapsDir = tempFolder.newFolder("jsSourceMaps")
178
+ val bundleAssetName = "myassetname"
179
+ val task = createTestTask<BundleHermesCTask> { it.jsSourceMapsDir.set(jsSourceMapsDir) }
180
+
181
+ assertEquals(
182
+ File(jsSourceMapsDir, "myassetname.map"), task.resolveOutputSourceMap(bundleAssetName))
183
+ }
184
+
185
+ @Test
186
+ fun resolveCompilerSourceMap_returnsCorrectFile() {
187
+ val jsIntermediateSourceMapsDir = tempFolder.newFolder("jsIntermediateSourceMaps")
188
+ val bundleAssetName = "myassetname"
189
+ val task =
190
+ createTestTask<BundleHermesCTask> {
191
+ it.jsIntermediateSourceMapsDir.set(jsIntermediateSourceMapsDir)
192
+ }
193
+
194
+ assertEquals(
195
+ File(jsIntermediateSourceMapsDir, "myassetname.compiler.map"),
196
+ task.resolveCompilerSourceMap(bundleAssetName))
197
+ }
198
+
199
+ @Test
200
+ fun getBundleCommand_returnsCorrectCommand() {
201
+ val entryFile = tempFolder.newFile("index.js")
202
+ val cliFile = tempFolder.newFile("cli.js")
203
+ val bundleFile = tempFolder.newFile("bundle.js")
204
+ val sourceMapFile = tempFolder.newFile("bundle.js.map")
205
+ val resourcesDir = tempFolder.newFolder("res")
206
+ val bundleConfig = tempFolder.newFile("bundle.config")
207
+ val task =
208
+ createTestTask<BundleHermesCTask> {
209
+ it.nodeExecutableAndArgs.set(listOf("node", "arg1", "arg2"))
210
+ it.root.set(tempFolder.root)
211
+ it.cliFile.set(cliFile)
212
+ it.bundleCommand.set("bundle")
213
+ it.devEnabled.set(true)
214
+ it.entryFile.set(entryFile)
215
+ it.resourcesDir.set(resourcesDir)
216
+ it.bundleConfig.set(bundleConfig)
217
+ it.minifyEnabled.set(true)
218
+ it.extraPackagerArgs.set(listOf("--read-global-cache"))
219
+ }
220
+
221
+ val bundleCommand = task.getBundleCommand(bundleFile, sourceMapFile)
222
+
223
+ assertEquals("node", bundleCommand[0])
224
+ assertEquals("arg1", bundleCommand[1])
225
+ assertEquals("arg2", bundleCommand[2])
226
+ assertEquals(cliFile.absolutePath, bundleCommand[3])
227
+ assertEquals("bundle", bundleCommand[4])
228
+ assertEquals("--platform", bundleCommand[5])
229
+ assertEquals("android", bundleCommand[6])
230
+ assertEquals("--dev", bundleCommand[7])
231
+ assertEquals("true", bundleCommand[8])
232
+ assertEquals("--reset-cache", bundleCommand[9])
233
+ assertEquals("--entry-file", bundleCommand[10])
234
+ assertEquals(entryFile.absolutePath, bundleCommand[11])
235
+ assertEquals("--bundle-output", bundleCommand[12])
236
+ assertEquals(bundleFile.absolutePath, bundleCommand[13])
237
+ assertEquals("--assets-dest", bundleCommand[14])
238
+ assertEquals(resourcesDir.absolutePath, bundleCommand[15])
239
+ assertEquals("--sourcemap-output", bundleCommand[16])
240
+ assertEquals(sourceMapFile.absolutePath, bundleCommand[17])
241
+ assertEquals("--config", bundleCommand[18])
242
+ assertEquals(bundleConfig.absolutePath, bundleCommand[19])
243
+ assertEquals("--minify", bundleCommand[20])
244
+ assertEquals("true", bundleCommand[21])
245
+ assertEquals("--read-global-cache", bundleCommand[22])
246
+ assertEquals("--verbose", bundleCommand[23])
247
+ assertEquals(24, bundleCommand.size)
248
+ }
249
+
250
+ @Test
251
+ @WithOs(OS.WIN)
252
+ fun getBundleCommand_onWindows_returnsWinValidCommandsPaths() {
253
+ val entryFile = tempFolder.newFile("index.js")
254
+ val cliFile = tempFolder.newFile("cli.js")
255
+ val bundleFile = tempFolder.newFile("bundle.js")
256
+ val sourceMapFile = tempFolder.newFile("bundle.js.map")
257
+ val resourcesDir = tempFolder.newFolder("res")
258
+ val bundleConfig = tempFolder.newFile("bundle.config")
259
+ val task =
260
+ createTestTask<BundleHermesCTask> {
261
+ it.nodeExecutableAndArgs.set(listOf("node", "arg1", "arg2"))
262
+ it.root.set(tempFolder.root)
263
+ it.cliFile.set(cliFile)
264
+ it.bundleCommand.set("bundle")
265
+ it.devEnabled.set(true)
266
+ it.entryFile.set(entryFile)
267
+ it.resourcesDir.set(resourcesDir)
268
+ it.bundleConfig.set(bundleConfig)
269
+ it.minifyEnabled.set(true)
270
+ it.extraPackagerArgs.set(listOf("--read-global-cache"))
271
+ }
272
+
273
+ val bundleCommand = task.getBundleCommand(bundleFile, sourceMapFile)
274
+
275
+ assertEquals("cmd", bundleCommand[0])
276
+ assertEquals("/c", bundleCommand[1])
277
+ assertEquals("node", bundleCommand[2])
278
+ assertEquals("arg1", bundleCommand[3])
279
+ assertEquals("arg2", bundleCommand[4])
280
+ assertEquals(cliFile.relativeTo(tempFolder.root).path, bundleCommand[5])
281
+ assertEquals("bundle", bundleCommand[6])
282
+ assertEquals("--platform", bundleCommand[7])
283
+ assertEquals("android", bundleCommand[8])
284
+ assertEquals("--dev", bundleCommand[9])
285
+ assertEquals("true", bundleCommand[10])
286
+ assertEquals("--reset-cache", bundleCommand[11])
287
+ assertEquals("--entry-file", bundleCommand[12])
288
+ assertEquals(entryFile.relativeTo(tempFolder.root).path, bundleCommand[13])
289
+ assertEquals("--bundle-output", bundleCommand[14])
290
+ assertEquals(bundleFile.relativeTo(tempFolder.root).path, bundleCommand[15])
291
+ assertEquals("--assets-dest", bundleCommand[16])
292
+ assertEquals(resourcesDir.relativeTo(tempFolder.root).path, bundleCommand[17])
293
+ assertEquals("--sourcemap-output", bundleCommand[18])
294
+ assertEquals(sourceMapFile.relativeTo(tempFolder.root).path, bundleCommand[19])
295
+ assertEquals("--config", bundleCommand[20])
296
+ assertEquals(bundleConfig.relativeTo(tempFolder.root).path, bundleCommand[21])
297
+ assertEquals("--minify", bundleCommand[22])
298
+ assertEquals("true", bundleCommand[23])
299
+ assertEquals("--read-global-cache", bundleCommand[24])
300
+ assertEquals("--verbose", bundleCommand[25])
301
+ assertEquals(26, bundleCommand.size)
302
+ }
303
+
304
+ @Test
305
+ fun getBundleCommand_withoutConfig_returnsCommandWithoutConfig() {
306
+ val entryFile = tempFolder.newFile("index.js")
307
+ val cliFile = tempFolder.newFile("cli.js")
308
+ val bundleFile = tempFolder.newFile("bundle.js")
309
+ val sourceMapFile = tempFolder.newFile("bundle.js.map")
310
+ val resourcesDir = tempFolder.newFolder("res")
311
+ val task =
312
+ createTestTask<BundleHermesCTask> {
313
+ it.nodeExecutableAndArgs.set(listOf("node", "arg1", "arg2"))
314
+ it.root.set(tempFolder.root)
315
+ it.cliFile.set(cliFile)
316
+ it.bundleCommand.set("bundle")
317
+ it.devEnabled.set(true)
318
+ it.entryFile.set(entryFile)
319
+ it.resourcesDir.set(resourcesDir)
320
+ it.minifyEnabled.set(true)
321
+ it.extraPackagerArgs.set(listOf("--read-global-cache"))
322
+ }
323
+
324
+ val bundleCommand = task.getBundleCommand(bundleFile, sourceMapFile)
325
+
326
+ assertTrue("--config" !in bundleCommand)
327
+ }
328
+
329
+ @Test
330
+ fun getHermescCommand_returnsCorrectCommand() {
331
+ val customHermesc = "hermesc"
332
+ val bytecodeFile = tempFolder.newFile("bundle.js.hbc")
333
+ val bundleFile = tempFolder.newFile("bundle.js")
334
+ val task =
335
+ createTestTask<BundleHermesCTask> {
336
+ it.root.set(tempFolder.root)
337
+ it.hermesFlags.set(listOf("my-custom-hermes-flag"))
338
+ }
339
+
340
+ val hermesCommand = task.getHermescCommand(customHermesc, bytecodeFile, bundleFile)
341
+
342
+ assertEquals(customHermesc, hermesCommand[0])
343
+ assertEquals("-emit-binary", hermesCommand[1])
344
+ assertEquals("-max-diagnostic-width=80", hermesCommand[2])
345
+ assertEquals("-out", hermesCommand[3])
346
+ assertEquals(bytecodeFile.absolutePath, hermesCommand[4])
347
+ assertEquals(bundleFile.absolutePath, hermesCommand[5])
348
+ assertEquals("my-custom-hermes-flag", hermesCommand[6])
349
+ assertEquals(7, hermesCommand.size)
350
+ }
351
+
352
+ @Test
353
+ @WithOs(OS.WIN)
354
+ fun getHermescCommand_onWindows_returnsRelativePaths() {
355
+ val customHermesc = "hermesc"
356
+ val bytecodeFile = tempFolder.newFile("bundle.js.hbc")
357
+ val bundleFile = tempFolder.newFile("bundle.js")
358
+ val task =
359
+ createTestTask<BundleHermesCTask> {
360
+ it.root.set(tempFolder.root)
361
+ it.hermesFlags.set(listOf("my-custom-hermes-flag"))
362
+ }
363
+
364
+ val hermesCommand = task.getHermescCommand(customHermesc, bytecodeFile, bundleFile)
365
+
366
+ assertEquals("cmd", hermesCommand[0])
367
+ assertEquals("/c", hermesCommand[1])
368
+ assertEquals(customHermesc, hermesCommand[2])
369
+ assertEquals("-emit-binary", hermesCommand[3])
370
+ assertEquals("-max-diagnostic-width=80", hermesCommand[4])
371
+ assertEquals("-out", hermesCommand[5])
372
+ assertEquals(bytecodeFile.relativeTo(tempFolder.root).path, hermesCommand[6])
373
+ assertEquals(bundleFile.relativeTo(tempFolder.root).path, hermesCommand[7])
374
+ assertEquals("my-custom-hermes-flag", hermesCommand[8])
375
+ assertEquals(9, hermesCommand.size)
376
+ }
377
+
378
+ @Test
379
+ fun getComposeSourceMapsCommand_returnsCorrectCommand() {
380
+ val packagerMap = tempFolder.newFile("bundle.js.packager.map")
381
+ val compilerMap = tempFolder.newFile("bundle.js.compiler.map")
382
+ val outputMap = tempFolder.newFile("bundle.js.map")
383
+ val reactNativeDir = tempFolder.newFolder("node_modules/react-native")
384
+ val composeSourceMapsFile = File(reactNativeDir, "scripts/compose-source-maps.js")
385
+ val task =
386
+ createTestTask<BundleHermesCTask> {
387
+ it.root.set(tempFolder.root)
388
+ it.nodeExecutableAndArgs.set(listOf("node", "arg1", "arg2"))
389
+ }
390
+
391
+ val composeSourcemapCommand =
392
+ task.getComposeSourceMapsCommand(composeSourceMapsFile, packagerMap, compilerMap, outputMap)
393
+
394
+ assertEquals("node", composeSourcemapCommand[0])
395
+ assertEquals("arg1", composeSourcemapCommand[1])
396
+ assertEquals("arg2", composeSourcemapCommand[2])
397
+ assertEquals(composeSourceMapsFile.absolutePath, composeSourcemapCommand[3])
398
+ assertEquals(packagerMap.absolutePath, composeSourcemapCommand[4])
399
+ assertEquals(compilerMap.absolutePath, composeSourcemapCommand[5])
400
+ assertEquals("-o", composeSourcemapCommand[6])
401
+ assertEquals(outputMap.absolutePath, composeSourcemapCommand[7])
402
+ assertEquals(8, composeSourcemapCommand.size)
403
+ }
404
+
405
+ @Test
406
+ @WithOs(OS.WIN)
407
+ fun getComposeSourceMapsCommand_onWindows_returnsRelativePaths() {
408
+ val packagerMap = tempFolder.newFile("bundle.js.packager.map")
409
+ val compilerMap = tempFolder.newFile("bundle.js.compiler.map")
410
+ val outputMap = tempFolder.newFile("bundle.js.map")
411
+ val reactNativeDir = tempFolder.newFolder("node_modules/react-native")
412
+ val composeSourceMapsFile = File(reactNativeDir, "scripts/compose-source-maps.js")
413
+ val task =
414
+ createTestTask<BundleHermesCTask> {
415
+ it.root.set(tempFolder.root)
416
+ it.nodeExecutableAndArgs.set(listOf("node", "arg1", "arg2"))
417
+ }
418
+
419
+ val composeSourcemapCommand =
420
+ task.getComposeSourceMapsCommand(composeSourceMapsFile, packagerMap, compilerMap, outputMap)
421
+
422
+ assertEquals("cmd", composeSourcemapCommand[0])
423
+ assertEquals("/c", composeSourcemapCommand[1])
424
+ assertEquals("node", composeSourcemapCommand[2])
425
+ assertEquals("arg1", composeSourcemapCommand[3])
426
+ assertEquals("arg2", composeSourcemapCommand[4])
427
+ assertEquals(composeSourceMapsFile.relativeTo(tempFolder.root).path, composeSourcemapCommand[5])
428
+ assertEquals(packagerMap.relativeTo(tempFolder.root).path, composeSourcemapCommand[6])
429
+ assertEquals(compilerMap.relativeTo(tempFolder.root).path, composeSourcemapCommand[7])
430
+ assertEquals("-o", composeSourcemapCommand[8])
431
+ assertEquals(outputMap.relativeTo(tempFolder.root).path, composeSourcemapCommand[9])
432
+ assertEquals(10, composeSourcemapCommand.size)
433
+ }
434
+ }