From fdd7848454c5b3593ba260cb57efb390ef01a9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20B=C3=BCrger?= Date: Mon, 4 Apr 2022 05:53:19 -0700 Subject: [PATCH] Replaced windowsAwareYarn with windowsAwareCommandLine for node calls (#33530) Summary: It is not necessary to call node via yarn. Instead with this commit node is called directly (windows aware). This enables builds on systems that don't have yarn installed. Fixes https://github.com/facebook/react-native/issues/33525 ## Changelog [Android] [Fixed] - Don't require yarn for codegen tasks Pull Request resolved: https://github.com/facebook/react-native/pull/33530 Test Plan: 1. react-native init test 2. cd test 3. enable newArchEnabled=true (gradle.properties) 4. enable enableHermes: true (build.gradle) 5. react-native run-android (when the yarn is not installed on the system) (I have not tested or verified if this works on windows build machines) Reviewed By: sshic Differential Revision: D35279376 Pulled By: cortinico fbshipit-source-id: 430e4a7bcdec7d5377efac747f6b935d634451cc --- .../tasks/GenerateCodegenArtifactsTask.kt | 4 ++-- .../react/tasks/GenerateCodegenSchemaTask.kt | 4 ++-- .../com/facebook/react/utils/TaskUtils.kt | 7 ------- .../com/facebook/react/utils/TaskUtilsTest.kt | 18 ------------------ 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt index f0bda7737be..3818e4085ab 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt @@ -8,7 +8,7 @@ package com.facebook.react.tasks import com.facebook.react.codegen.generator.JavaGenerator -import com.facebook.react.utils.windowsAwareYarn +import com.facebook.react.utils.windowsAwareCommandLine import org.gradle.api.GradleException import org.gradle.api.file.Directory import org.gradle.api.file.DirectoryProperty @@ -93,7 +93,7 @@ abstract class GenerateCodegenArtifactsTask : Exec() { internal fun setupCommandLine() { commandLine( - windowsAwareYarn( + windowsAwareCommandLine( *nodeExecutableAndArgs.get().toTypedArray(), reactNativeDir.file("scripts/generate-specs-cli.js").get().asFile.absolutePath, "--platform", diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt index ee59bc987cb..dea2d8e7dfc 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt @@ -7,7 +7,7 @@ package com.facebook.react.tasks -import com.facebook.react.utils.windowsAwareYarn +import com.facebook.react.utils.windowsAwareCommandLine import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFile import org.gradle.api.provider.ListProperty @@ -49,7 +49,7 @@ abstract class GenerateCodegenSchemaTask : Exec() { internal fun setupCommandLine() { commandLine( - windowsAwareYarn( + windowsAwareCommandLine( *nodeExecutableAndArgs.get().toTypedArray(), codegenDir .file("lib/cli/combine/combine-js-to-schema-cli.js") diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/TaskUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/TaskUtils.kt index 235d92486de..fd557079f59 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/TaskUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/TaskUtils.kt @@ -14,13 +14,6 @@ internal fun windowsAwareCommandLine(vararg args: Any): List = args.toList() } -internal fun windowsAwareYarn(vararg args: Any): List = - if (Os.isWindows()) { - listOf("yarn.cmd") + args - } else { - listOf("yarn") + args - } - internal fun windowsAwareBashCommandLine( vararg args: String, bashWindowsHome: String? = null diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt index 11874321102..8156ef029e7 100644 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt @@ -42,24 +42,6 @@ class TaskUtilsTest { assertEquals(listOf("cmd", "/c", "a", "b", "c"), windowsAwareCommandLine("a", "b", "c")) } - @Test - @WithOs(OS.MAC) - fun windowsAwareYarn_onMac_returnsTheList() { - assertEquals(listOf("yarn", "a", "b", "c"), windowsAwareYarn("a", "b", "c")) - } - - @Test - @WithOs(OS.UNIX) - fun windowsAwareYarn_onLinux_returnsTheList() { - assertEquals(listOf("yarn", "a", "b", "c"), windowsAwareYarn("a", "b", "c")) - } - - @Test - @WithOs(OS.WIN) - fun windowsAwareYarn_onWindows_prependsCmd() { - assertEquals(listOf("yarn.cmd", "a", "b", "c"), windowsAwareYarn("a", "b", "c")) - } - @Test @WithOs(OS.MAC) fun windowsAwareBashCommandLine_onMac_returnsTheList() {