Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ abstract class ReactExtension @Inject constructor(val project: Project) {
*/
val enableSoCleanup: Property<Boolean> = objects.property(Boolean::class.java).convention(true)

/**
* Whether to pass `--reset-cache` to the [bundleCommand]. Disable it to keep the Metro cache
* between release builds. Default: true
*/
val resetCache: Property<Boolean> = objects.property(Boolean::class.java).convention(true)

/** Extra args that will be passed to the [bundleCommand] Default: [] */
val extraPackagerArgs: ListProperty<String> =
objects.listProperty(String::class.java).convention(emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ internal fun Project.configureReactTasks(variant: Variant, config: ReactExtensio
task.cliFile.set(cliFile)
task.bundleCommand.set(config.bundleCommand)
task.entryFile.set(detectedEntryFile(config, entryFileEnvVariable))
task.resetCache.set(config.resetCache)
task.extraPackagerArgs.set(config.extraPackagerArgs)
task.bundleConfig.set(config.bundleConfig)
task.bundleAssetName.set(config.bundleAssetName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ abstract class BundleHermesCTask : DefaultTask() {

@get:Input abstract val devEnabled: Property<Boolean>

@get:Input abstract val resetCache: Property<Boolean>

@get:Input abstract val extraPackagerArgs: ListProperty<String>

@get:Input abstract val hermesCommand: Property<String>
Expand Down Expand Up @@ -152,7 +154,9 @@ abstract class BundleHermesCTask : DefaultTask() {
add("android")
add("--dev")
add(devEnabled.get().toString())
add("--reset-cache")
if (resetCache.get()) {
add("--reset-cache")
}
add("--entry-file")
add(entryFile.get().asFile.cliPath(rootFile))
add("--bundle-output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class BundleHermesCTaskTest {
it.minifyEnabled.set(true)
it.hermesEnabled.set(true)
it.devEnabled.set(true)
it.resetCache.set(true)
it.extraPackagerArgs.set(listOf("extra", "arg"))
it.hermesCommand.set("./my-hermesc")
it.hermesFlags.set(listOf("flag1", "flag2"))
Expand All @@ -102,6 +103,7 @@ class BundleHermesCTaskTest {
assertThat(task.minifyEnabled.get()).isTrue()
assertThat(task.hermesEnabled.get()).isTrue()
assertThat(task.devEnabled.get()).isTrue()
assertThat(task.resetCache.get()).isTrue()
assertThat(task.extraPackagerArgs.get()).isEqualTo(listOf("extra", "arg"))
assertThat(task.hermesCommand.get()).isEqualTo("./my-hermesc")
assertThat(task.hermesFlags.get()).isEqualTo(listOf("flag1", "flag2"))
Expand Down Expand Up @@ -211,6 +213,7 @@ class BundleHermesCTaskTest {
it.resourcesDir.set(resourcesDir)
it.bundleConfig.set(bundleConfig)
it.minifyEnabled.set(true)
it.resetCache.set(true)
it.extraPackagerArgs.set(listOf("--read-global-cache"))
}

Expand Down Expand Up @@ -265,6 +268,7 @@ class BundleHermesCTaskTest {
it.resourcesDir.set(resourcesDir)
it.bundleConfig.set(bundleConfig)
it.minifyEnabled.set(true)
it.resetCache.set(true)
it.extraPackagerArgs.set(listOf("--read-global-cache"))
}

Expand Down Expand Up @@ -318,6 +322,7 @@ class BundleHermesCTaskTest {
it.entryFile.set(entryFile)
it.resourcesDir.set(resourcesDir)
it.minifyEnabled.set(true)
it.resetCache.set(true)
it.extraPackagerArgs.set(listOf("--read-global-cache"))
}

Expand All @@ -326,6 +331,32 @@ class BundleHermesCTaskTest {
assertThat(bundleCommand).doesNotContain("--config")
}

@Test
fun getBundleCommand_withResetCacheDisabled_returnsCommandWithoutResetCache() {
val entryFile = tempFolder.newFile("index.js")
val cliFile = tempFolder.newFile("cli.js")
val bundleFile = tempFolder.newFile("bundle.js")
val sourceMapFile = tempFolder.newFile("bundle.js.map")
val resourcesDir = tempFolder.newFolder("res")
val task =
createTestTask<BundleHermesCTask> {
it.nodeExecutableAndArgs.set(listOf("node", "arg1", "arg2"))
it.root.set(tempFolder.root)
it.cliFile.set(cliFile)
it.bundleCommand.set("bundle")
it.devEnabled.set(true)
it.entryFile.set(entryFile)
it.resourcesDir.set(resourcesDir)
it.minifyEnabled.set(true)
it.resetCache.set(false)
it.extraPackagerArgs.set(listOf("--read-global-cache"))
}

val bundleCommand = task.getBundleCommand(bundleFile, sourceMapFile)

assertThat(bundleCommand).doesNotContain("--reset-cache")
}

@Test
fun getHermescCommand_returnsCorrectCommand() {
val customHermesc = "hermesc"
Expand Down
Loading