Skip to content

Commit

Permalink
NodeSetupTask should not delete general files, only old node versions #…
Browse files Browse the repository at this point in the history
  • Loading branch information
deepy committed Feb 2, 2024
1 parent c07b5ea commit 5688608
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/com/github/gradle/node/task/NodeSetupTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ abstract class NodeSetupTask : BaseTask() {

private fun deleteExistingNode() {
projectHelper.delete {
delete(nodeDir.get().dir("../"))
delete(nodeDir.get().dir("../").asFileTree.matching {
include("node-v*/**")
})
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/groovy/com/github/gradle/AbstractIntegTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ abstract class AbstractIntegTest extends Specification {
return new File(temporaryFolder.getRoot(), name)
}

protected final void writeFile(final String name, final String text) {
protected final File writeFile(final String name, final String text) {
File file = createFile(name)
file.parentFile.mkdirs()
file << text
return file
}

protected final void writePackageJson(final String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,34 @@ node {
gv << GRADLE_VERSIONS_UNDER_TEST
}
def 'nodeSetup should only delete old node versions (#gv.version)'() {
given:
gradleVersion = gv
def badVersion = "node-v18.17.0"
def goodVersion = "18.17.1"
createFile("build.gradle") << """plugins {
id "com.github.node-gradle.node"
}
node {
version = "${goodVersion}"
download = true
workDir = file("build/node")
}"""
def badFile = writeFile("build/node/$badVersion/bin/node.js", "console.log(\"bad\");")
def goodFile = writeFile("build/node/important.txt", "should not be deleted by nodeSetup")
when:
def result1 = build("nodeSetup")
then:
result1.task(":nodeSetup").outcome == TaskOutcome.SUCCESS
!badFile.exists()
goodFile.exists()
where:
gv << GRADLE_VERSIONS_UNDER_TEST
}
}

0 comments on commit 5688608

Please sign in to comment.