From d8d9c28b482ed294770592ecb75bd6cc7f5c9da7 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 10 Sep 2021 08:35:38 -0700 Subject: [PATCH] Make the `BundleJsAndAssetsTask` Task more Gradle friendly Summary: This Diff is adapting the `BundleJsAndAssetsTask` to be a bit more idiomatic. Here the summary of changes. - Make the task `abstract` to let Gradle properly implement it. - Make all the annotated filed `public` instead of `internal` as they will be easier to access for Gradle + will show up correctly in logs/scans - Update the Task to subclass a `Exec` that is a specificed Task - Do not reference `project.` inside the Task body as that is breaking the Configuration Caching of Gradle Changelog: [Internal] [Changed] - Make the `BundleJsAndAssetsTask` Task more Gradle friendly Reviewed By: mdvacca Differential Revision: D30865159 fbshipit-source-id: 74d4c77f6a2b3fac944e7e0b123726e6a423ba1d --- .../react/tasks/BundleJsAndAssetsTask.kt | 82 +++++++++---------- 1 file changed, 38 insertions(+), 44 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleJsAndAssetsTask.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleJsAndAssetsTask.kt index ec533b2d55e..51c23b32a67 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleJsAndAssetsTask.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleJsAndAssetsTask.kt @@ -10,35 +10,29 @@ package com.facebook.react.tasks import com.facebook.react.utils.recreateDir import com.facebook.react.utils.windowsAwareCommandLine import java.io.File -import org.gradle.api.DefaultTask import org.gradle.api.file.FileTree -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.InputFiles -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.* -open class BundleJsAndAssetsTask : DefaultTask() { +abstract class BundleJsAndAssetsTask : Exec() { - @get:Internal internal lateinit var reactRoot: File + @get:Internal lateinit var reactRoot: File @get:InputFiles @Suppress("UNUSED") // used to invalidate caches - internal lateinit var sources: FileTree - @get:Input internal lateinit var execCommand: List - @get:Input internal lateinit var bundleCommand: String - @get:Input internal var devEnabled: Boolean = true - @get:InputFile internal lateinit var entryFile: File - @get:Input internal var extraArgs: List = emptyList() + lateinit var sources: FileTree - @get:OutputDirectory internal lateinit var jsBundleDir: File - @get:OutputFile internal lateinit var jsBundleFile: File - @get:OutputDirectory internal lateinit var resourcesDir: File - @get:OutputDirectory internal lateinit var jsIntermediateSourceMapsDir: File - @get:OutputDirectory internal lateinit var jsSourceMapsDir: File - @get:OutputFile internal lateinit var jsSourceMapsFile: File + @get:Input lateinit var execCommand: List + @get:Input lateinit var bundleCommand: String + @get:Input var devEnabled: Boolean = true + @get:InputFile lateinit var entryFile: File + @get:Input var extraArgs: List = emptyList() + + @get:OutputDirectory lateinit var jsBundleDir: File + @get:OutputFile lateinit var jsBundleFile: File + @get:OutputDirectory lateinit var resourcesDir: File + @get:OutputDirectory lateinit var jsIntermediateSourceMapsDir: File + @get:OutputDirectory lateinit var jsSourceMapsDir: File + @get:OutputFile lateinit var jsSourceMapsFile: File @TaskAction fun run() { @@ -54,28 +48,28 @@ open class BundleJsAndAssetsTask : DefaultTask() { } private fun executeBundleCommand() { - project.exec { - it.workingDir(reactRoot) + workingDir(reactRoot) - @Suppress("SpreadOperator") - it.commandLine( - windowsAwareCommandLine( - *execCommand.toTypedArray(), - bundleCommand, - "--platform", - "android", - "--dev", - devEnabled, - "--reset-cache", - "--entry-file", - entryFile, - "--bundle-output", - jsBundleFile, - "--assets-dest", - resourcesDir, - "--sourcemap-output", - jsSourceMapsFile, - *extraArgs.toTypedArray())) - } + @Suppress("SpreadOperator") + commandLine( + windowsAwareCommandLine( + *execCommand.toTypedArray(), + bundleCommand, + "--platform", + "android", + "--dev", + devEnabled, + "--reset-cache", + "--entry-file", + entryFile, + "--bundle-output", + jsBundleFile, + "--assets-dest", + resourcesDir, + "--sourcemap-output", + jsSourceMapsFile, + *extraArgs.toTypedArray())) + + super.exec() } }