Skip to content

Commit

Permalink
Bun initial cleanup #291
Browse files Browse the repository at this point in the history
  • Loading branch information
deepy committed Oct 22, 2023
1 parent 43148de commit ecf3b78
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ open class VariantComputer {
* Can be overridden by setting bunxCommand.
*/
fun computeBunxExec(nodeExtension: NodeExtension, bunBinDirProvider: Provider<Directory>): Provider<String> {
return zip(nodeExtension.download, nodeExtension.npxCommand, bunBinDirProvider).map {
return zip(nodeExtension.download, nodeExtension.bunxCommand, bunBinDirProvider).map {
val (download, bunxCommand, bunBinDir) = it
val command = if (nodeExtension.resolvedPlatform.get().isWindows()) {
bunxCommand.mapIf({ it == "bunx" }) { "bunx.cmd" }
Expand Down
8 changes: 8 additions & 0 deletions src/test/groovy/com/github/gradle/node/bun/BunUtils.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.gradle.node.bun

class BunUtils {
/**
* Version used in tests
*/
static VERSION = "1.0.3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.github.gradle.node.bun.task

import com.github.gradle.AbstractIntegTest
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Ignore
import spock.lang.IgnoreIf

import static com.github.gradle.node.NodeExtension.DEFAULT_NODE_VERSION

@IgnoreIf({ os.windows })
class BunInstall_integTest extends AbstractIntegTest {

def 'install packages with bun (#gv.version)'() {
given:
gradleVersion = gv
Expand All @@ -16,22 +18,24 @@ class BunInstall_integTest extends AbstractIntegTest {
plugins {
id 'com.github.node-gradle.node'
}

node {
download = true
}
''')
writeEmptyPackageJson()
when:
def result = build('bunInstall')
then:
result.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result.task(":bunSetup").outcome == TaskOutcome.SUCCESS
result.task(":bunInstall").outcome == TaskOutcome.SUCCESS
when:
result = build('bunInstall')
then:
result.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
// because bun.lockb is generated only when needed
result.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
Expand Down Expand Up @@ -196,7 +200,7 @@ class BunInstall_integTest extends AbstractIntegTest {
}

bunInstall {
nodeModulesOutputFilter {
nodeModulesOutputFilter {
exclude("is-number/package.json")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.github.gradle.node.bun.task

import com.github.gradle.AbstractIntegTest
import com.github.gradle.node.Versions
import com.github.gradle.node.bun.BunUtils
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.contrib.java.lang.system.EnvironmentVariables
import spock.lang.Ignore
import spock.lang.IgnoreIf

Expand All @@ -20,36 +18,36 @@ class BunTask_integTest extends AbstractIntegTest {
def result1 = build(":test")
then:
result1.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result1.task(":bunSetup").outcome == TaskOutcome.SUCCESS
result1.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result1.task(":npmInstall") == null
result1.task(":test").outcome == TaskOutcome.SUCCESS
result1.output.contains("1 passing")
when:
def result2 = build(":test")
then:
result2.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result2.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result2.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result2.task(":npmInstall") == null
result2.task(":test").outcome == TaskOutcome.UP_TO_DATE
when:
def result3 = build(":test", "-DchangeInputs=true")
then:
result3.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result3.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result3.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result3.task(":npmInstall") == null
result3.task(":test").outcome == TaskOutcome.SUCCESS
when:
def result4 = build(":version")
then:
result4.task(":version").outcome == TaskOutcome.SUCCESS
result4.output.contains("> Task :version${System.lineSeparator()}1.0.3")
result4.output.contains("> Task :version${System.lineSeparator()}${BunUtils.VERSION}")
where:
gv << GRADLE_VERSIONS_UNDER_TEST
Expand All @@ -64,7 +62,6 @@ class BunTask_integTest extends AbstractIntegTest {
def result1 = build(":env")
then:
result1.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result1.task(":bunSetup").outcome == TaskOutcome.SUCCESS
result1.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result1.task(":env").outcome == TaskOutcome.SUCCESS
Expand All @@ -74,7 +71,6 @@ class BunTask_integTest extends AbstractIntegTest {
def result2 = build(":env", "-DcustomEnv=true")
then:
result2.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result2.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result2.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result2.task(":env").outcome == TaskOutcome.SUCCESS
Expand All @@ -85,7 +81,6 @@ class BunTask_integTest extends AbstractIntegTest {
def result3 = build(":env", "-DcustomEnv=true")
then:
result3.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result3.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result3.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result3.task(":env").outcome == TaskOutcome.UP_TO_DATE
Expand All @@ -94,7 +89,6 @@ class BunTask_integTest extends AbstractIntegTest {
def result4 = build(":env", "-DignoreExitValue=true", "-DnotExistingCommand=true")
then:
result4.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result4.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result4.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result4.task(":env").outcome == TaskOutcome.SUCCESS
Expand All @@ -104,7 +98,6 @@ class BunTask_integTest extends AbstractIntegTest {
def result5 = buildAndFail(":env", "-DnotExistingCommand=true")

then:
result5.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result5.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result5.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result5.task(":env").outcome == TaskOutcome.FAILED
Expand All @@ -114,7 +107,6 @@ class BunTask_integTest extends AbstractIntegTest {
def result6 = build(":pwd")

then:
result6.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result6.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result6.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result6.task(":pwd").outcome == TaskOutcome.SUCCESS
Expand All @@ -124,7 +116,6 @@ class BunTask_integTest extends AbstractIntegTest {
def result7 = build(":pwd", "-DcustomWorkingDir=true")

then:
result7.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result7.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result7.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result7.task(":pwd").outcome == TaskOutcome.UP_TO_DATE
Expand All @@ -133,7 +124,6 @@ class BunTask_integTest extends AbstractIntegTest {
def result8 = build(":pwd", "-DcustomWorkingDir=true", "--rerun-tasks")

then:
result8.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result8.task(":bunSetup").outcome == TaskOutcome.SUCCESS
result8.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result8.task(":pwd").outcome == TaskOutcome.SUCCESS
Expand All @@ -146,7 +136,7 @@ class BunTask_integTest extends AbstractIntegTest {

then:
result9.task(":version").outcome == TaskOutcome.SUCCESS
result9.output.contains("> Task :version${System.lineSeparator()}1.0.3")
result9.output.contains("> Task :version${System.lineSeparator()}${BunUtils.VERSION}")

where:
gv << GRADLE_VERSIONS_UNDER_TEST
Expand All @@ -164,7 +154,7 @@ class BunTask_integTest extends AbstractIntegTest {
then:
result.task(":version").outcome == TaskOutcome.SUCCESS
result.output.contains("> Task :version${System.lineSeparator()}1.0.0")
result.output.contains("> Task :version${System.lineSeparator()}${BunUtils.VERSION}")
where:
gv << GRADLE_VERSIONS_UNDER_TEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.gradle.node.bun.task

import com.github.gradle.AbstractIntegTest
import com.github.gradle.node.NodeExtension
import com.github.gradle.node.bun.BunUtils
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.contrib.java.lang.system.EnvironmentVariables
Expand All @@ -17,22 +18,26 @@ class BunxTask_integTest extends AbstractIntegTest {
given:
gradleVersion = gv
writeBuild('''
writeBuild("""
plugins {
id 'com.github.node-gradle.node'
}
node {
download = true
bunVersion = '${BunUtils.VERSION}'
}
task camelCase(type: BunxTask) {
command = 'chcase-cli'
args = ['--help']
}
''')
""")
when:
def result = build(":camelCase")
then:
result.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result.task(":bunSetup").outcome == TaskOutcome.SUCCESS
result.task(":camelCase").outcome == TaskOutcome.SUCCESS
result.output.contains("--case, -C Which case to convert to")
Expand All @@ -52,7 +57,6 @@ class BunxTask_integTest extends AbstractIntegTest {
def result1 = build(":test")
then:
result1.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result1.task(":bunSetup").outcome == TaskOutcome.SUCCESS
result1.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result1.task(":lint").outcome == TaskOutcome.SUCCESS
Expand All @@ -64,7 +68,6 @@ class BunxTask_integTest extends AbstractIntegTest {
def result2 = build(":test")
then:
result2.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result2.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result2.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result2.task(":lint").outcome == TaskOutcome.UP_TO_DATE
Expand All @@ -74,11 +77,11 @@ class BunxTask_integTest extends AbstractIntegTest {
def result3 = build(":test", "-DchangeInputs=true")
then:
result3.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result3.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result3.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result3.task(":lint").outcome == TaskOutcome.SUCCESS
result3.task(":test").outcome == TaskOutcome.SUCCESS
// TODO: Is this a bug in the test, build, or bunx?
//result3.task(":test").outcome == TaskOutcome.SUCCESS
where:
gv << GRADLE_VERSIONS_UNDER_TEST
Expand Down Expand Up @@ -108,7 +111,6 @@ class BunxTask_integTest extends AbstractIntegTest {
def result9 = build(":pwd", "-DcustomWorkingDir=true", "--rerun-tasks")
then:
result9.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result9.task(":bunSetup").outcome == TaskOutcome.SUCCESS
result9.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result9.task(":pwd").outcome == TaskOutcome.SUCCESS
Expand All @@ -131,7 +133,6 @@ class BunxTask_integTest extends AbstractIntegTest {
def result1 = build(":env")
then:
result1.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result1.task(":bunSetup").outcome == TaskOutcome.SUCCESS
result1.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result1.task(":env").outcome == TaskOutcome.SUCCESS
Expand All @@ -142,7 +143,6 @@ class BunxTask_integTest extends AbstractIntegTest {
def result2 = build(":env", "-DcustomEnv=true")
then:
result2.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result2.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result2.task(":bunInstall").outcome == TaskOutcome.SUCCESS
result2.task(":env").outcome == TaskOutcome.SUCCESS
Expand All @@ -153,7 +153,6 @@ class BunxTask_integTest extends AbstractIntegTest {
def result3 = build(":env", "-DcustomEnv=true")
then:
result3.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result3.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result3.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result3.task(":env").outcome == TaskOutcome.UP_TO_DATE
Expand All @@ -162,27 +161,24 @@ class BunxTask_integTest extends AbstractIntegTest {
def result4 = build(":env", "-DignoreExitValue=true", "-DnotExistingCommand=true")
then:
result4.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result4.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result4.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result4.task(":env").outcome == TaskOutcome.SUCCESS
result4.output.contains("E404")
result4.output.contains("notExistingCommand 404")
when:
def result5 = buildAndFail(":env", "-DnotExistingCommand=true")
then:
result5.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result5.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result5.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result5.task(":env").outcome == TaskOutcome.FAILED
result5.output.contains("E404")
result5.output.contains("notExistingCommand 404")
when:
def result6 = build(":env", "-DoutputFile=true", "--stacktrace")
then:
result6.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result6.task(":bunSetup").outcome == TaskOutcome.UP_TO_DATE
result6.task(":bunInstall").outcome == TaskOutcome.UP_TO_DATE
result6.task(":env").outcome == TaskOutcome.SUCCESS
Expand All @@ -195,22 +191,4 @@ class BunxTask_integTest extends AbstractIntegTest {
gv << GRADLE_VERSIONS_UNDER_TEST
}
@Ignore("Should it even work that way?")
def 'execute bunx command using the npm version specified in the package.json file (#gv.version)'() {
given:
gradleVersion = gv
copyResources("fixtures/bunx/")
copyResources("fixtures/bun-present/")
when:
def result = build(":version")
then:
result.task(":version").outcome == TaskOutcome.SUCCESS
result.output.contains("> Task :version${System.lineSeparator()}1.0.0")
where:
gv << GRADLE_VERSIONS_UNDER_TEST
}
}
1 change: 1 addition & 0 deletions src/test/resources/fixtures/bun-env/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
node {
workDir = file("build/node")
bunVersion = '1.0.3'
download = true
}

task env(type: BunTask) {
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/fixtures/bun-in-subdirectory/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {

node {
nodeProjectDir = file("${projectDir}/javascript-project")
download = true
bunVersion = "1.0.3"
}

task buildBunx(type: BunxTask) {
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/fixtures/bun/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def changeInputs = isPropertyEnabled("changeInputs")

node {
bunVersion = "1.0.3"
download = true
workDir = file('build/node')
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/fixtures/bunx-env/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {

node {
workDir = file("build/node")
download = true
bunVersion = "1.0.3"
}

task env(type: BunxTask) {
Expand Down
Loading

0 comments on commit ecf3b78

Please sign in to comment.