Skip to content

Commit

Permalink
Merge pull request #23325 from WordPress/fix_no_jitpack_build
Browse files Browse the repository at this point in the history
Update no jitpack buld for monorepo
  • Loading branch information
hypest authored Jun 22, 2020
2 parents 7ddcaa5 + 857f407 commit 0cddbf0
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions packages/react-native-bridge/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -188,52 +188,47 @@ if (buildGutenbergMobileJSBundle) {
description("Checks if the inputs to the javascript bundle and the bundle itself are unchanged. \
If they are changed, the isBundleUpToDate flag is switched to false. That flag is used by other tasks.")

def isRelevantFile = { it.name.endsWithAny('.js', '.css') || it.name == 'package.json' }
def inputFiles = {
def jsFiles = []
def dirs = []
file(jsRootDir).eachDir { dir ->
if (dir.name != 'node_modules'
&& dir.name != 'bundle'
&& dir.name != 'gutenberg'
&& !dir.name.startsWith('symlinked')) {
dirs << dir
}
}
file("$jsRootDir/gutenberg").eachDir { dir ->
if (dir.name != 'node_modules') {
dirs << dir
}
def dirs = [jsRootDir]
file(jsRootDir).eachDirRecurse { dir ->
def isRelevantDir = !['react-native-bridge/android/build/intermediates',
file("$jsRootDir/bundle").absolutePath,
'node_modules'].any { dir.absolutePath.contains(it) } &&
!dir.name.startsWith('symlinked')
if (isRelevantDir) {
dirs << dir
}
}

dirs.forEach { dir ->
file(dir).eachFileRecurse {
if (isRelevantFile(it)) {
jsFiles << it
}
def isRelevantFile = { it.name.endsWithAny('.js', '.css', '.scss') || it.name == 'package.json' }
def inputFiles = []
dirs.forEach { dir ->
file(dir).eachFile {
if (isRelevantFile(it)) {
inputFiles << it
}
}

def jsRootDirFiles = file(jsRootDir).listFiles().findAll {
isRelevantFile(it)
}
def gutenbergRootDirFiles = file("$jsRootDir/gutenberg").listFiles().findAll {
isRelevantFile(it)
}
return jsFiles + jsRootDirFiles + gutenbergRootDirFiles
}
inputs.files(inputFiles())

inputs.files(inputFiles)

// We cannot use the bundle file itself as an output because it does not yet exist when this
// task finishes. Nevertheless, we have to declare something as an output because only tasks
// with outputs are run incrementally, so we're declaring a file that does not exist as the
// output. Since that file never exists, that "output" will always be considered "up-to-date".
outputs.file("nonexistentfile")

// The bundle file can only be up-to-date if a bundle file exists. If this task runs, that
// means some of the inputs have changed, and the isBundleUpToDate flag is set back to false
// because the bundle should be rebuilt.
project.ext.isBundleUpToDate = file("$buildAssetsFolder/$bundleName").exists()
// Using onlyIf here as a hack to run this check at the time of execution even if the task
// is otherwise up to date. For example, even if the task is up to date the isBundleUpToDate value
// should be false if the bundle file does not exist at the time this task runs. This must be run
// at execution time to catch the case where the clean task is also running and would remove the
// bundle file between the configuration phase and the execution of this task.
onlyIf {
project.ext.isBundleUpToDate = file("$buildAssetsFolder/$bundleName").exists()
true
}

// If this task runs, that means some of the inputs have changed, and the isBundleUpToDate
// flag needs should be false so that the bundle is rebuilt.
doLast {
project.ext.isBundleUpToDate = false
}
Expand Down Expand Up @@ -280,10 +275,20 @@ If they are changed, the isBundleUpToDate flag is switched to false. That flag i
onlyIf { !isBundleUpToDate() }

def origFileName = 'App.js'
def origWithPath = "../../bundle/android/${origFileName}"
def origWithPath = "$jsRootDir/bundle/android/${origFileName}"
from origWithPath
into buildAssetsFolder
rename origFileName, bundleName

// Prevent this task from silently failing
// Using onlyIf as a bit of a hack to perform this check at the time of execution
onlyIf {
if (inputs.sourceFiles.empty) {
throw new StopExecutionException("ERROR: Could not find bundle file to copy.")
}
true
}

doLast {
println "Done copying the Android JS bundle to assets folder"
}
Expand All @@ -293,7 +298,7 @@ If they are changed, the isBundleUpToDate flag is switched to false. That flag i
dependsOn bundleUpToDateCheck
onlyIf { !isBundleUpToDate() }

delete '../../node_modules'
delete "$jsRootDir/node_modules"
}

task resetExtractedRNTools(type: Delete) {
Expand Down

0 comments on commit 0cddbf0

Please sign in to comment.