Skip to content

Commit

Permalink
rebuild autolinking cache if empty or invalid
Browse files Browse the repository at this point in the history
Summary:
Our test for rebuilding the `autolinking.json` file currently rebuilds everytime if the cached json file ISN'T empty.  This means users who have an empty entry get stuck there.

I've also added more validation that the contents of the cached config have at a minimum the `.project.android.packageName` entry in it, otherwise it rebuilds.

Reviewed By: cortinico

Differential Revision: D61911114
  • Loading branch information
blakef authored and facebook-github-bot committed Aug 28, 2024
1 parent 3077db3 commit 688b344
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.facebook.react

import com.facebook.react.model.ModelAutolinkingConfigJson
import com.facebook.react.utils.JsonUtils
import com.facebook.react.utils.windowsAwareCommandLine
import java.io.File
Expand Down Expand Up @@ -54,7 +55,8 @@ abstract class ReactSettingsExtension @Inject constructor(val settings: Settings
) {
outputFile.parentFile.mkdirs()
val lockFilesChanged = checkAndUpdateLockfiles(lockFiles, outputFolder)
if (lockFilesChanged || outputFile.exists().not() || outputFile.length() != 0L) {
val invalidConfig = !validateConfigModel(JsonUtils.fromAutolinkingConfigJson(outputFile))
if (lockFilesChanged || invalidConfig) {
val process =
ProcessBuilder(command)
.directory(workingDirectory)
Expand Down Expand Up @@ -150,5 +152,8 @@ abstract class ReactSettingsExtension @Inject constructor(val settings: Settings

internal fun computeSha256(lockFile: File) =
String.format("%032x", BigInteger(1, md.digest(lockFile.readBytes())))

internal fun validateConfigModel(model: ModelAutolinkingConfigJson?) =
model?.project?.android?.packageName != null
}
}

0 comments on commit 688b344

Please sign in to comment.