Skip to content

Commit

Permalink
Fix broken npm symlink caused by tarTree
Browse files Browse the repository at this point in the history
This fixes #164
  • Loading branch information
s0x committed Dec 19, 2016
1 parent 4f5048b commit e9b8acf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/groovy/com/moowork/gradle/node/task/SetupTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

class SetupTask
extends DefaultTask
Expand Down Expand Up @@ -121,6 +124,11 @@ class SetupTask
from this.project.tarTree( getNodeArchiveFile() )
into getNodeDir().parent
}
// Fix broken symlink
Path npm = Paths.get(variant.nodeBinDir.path, 'npm')
if (Files.deleteIfExists(npm)) {
Files.createSymbolicLink(npm, Paths.get(variant.npmScriptFile))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,37 @@ class NpmRule_integTest
fileExists( 'parent1.txt' )
fileExists( 'parent2.txt' )
}

def 'can execute subtasks using npm'()
{
given:
writeBuild( '''
plugins {
id 'com.moowork.node'
}
node {
download = true
}
''' )
writePackageJson(""" {
"name": "example",
"dependencies": {},
"scripts": {
"parent" : "echo 'parent1' > parent1.txt && npm run child1 && npm run child2 && echo 'parent2' > parent2.txt",
"child1": "echo 'child1' > child1.txt",
"child2": "echo 'child2' > child2.txt"
}
}
""")

when:
def result = buildTask( 'npm_run_parent' )

then:
result.outcome == TaskOutcome.SUCCESS
fileExists( 'parent1.txt' )
fileExists( 'child1.txt' )
fileExists( 'child2.txt' )
fileExists( 'parent2.txt' )
}
}

0 comments on commit e9b8acf

Please # to comment.