Skip to content

Commit 5e7341e

Browse files
committed
Fix task rule creation #145
1 parent 961b54f commit 5e7341e

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/main/kotlin/com/github/gradle/node/NodePlugin.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.github.gradle.node.yarn.task.YarnSetupTask
1313
import com.github.gradle.node.yarn.task.YarnTask
1414
import org.gradle.api.Plugin
1515
import org.gradle.api.Project
16+
import org.gradle.kotlin.dsl.create
1617
import org.gradle.kotlin.dsl.named
1718
import org.gradle.kotlin.dsl.register
1819
import java.io.File
@@ -59,7 +60,7 @@ class NodePlugin : Plugin<Project> {
5960
project.tasks.addRule("Pattern: \"npm_<command>\": Executes an NPM command.") {
6061
val taskName = this
6162
if (taskName.startsWith("npm_")) {
62-
project.tasks.register<NpmTask>(taskName) {
63+
project.tasks.create<NpmTask>(taskName) {
6364
val tokens = taskName.split("_").drop(1) // all except first
6465
npmCommand.set(tokens)
6566
if (tokens.first().equals("run", ignoreCase = true)) {
@@ -74,7 +75,7 @@ class NodePlugin : Plugin<Project> {
7475
project.tasks.addRule("Pattern: \"yarn_<command>\": Executes an Yarn command.") {
7576
val taskName = this
7677
if (taskName.startsWith("yarn_")) {
77-
project.tasks.register<YarnTask>(taskName).configure {
78+
project.tasks.create<YarnTask>(taskName) {
7879
val tokens = taskName.split("_").drop(1) // all except first
7980
yarnCommand.set(tokens)
8081
if (tokens.first().equals("run", ignoreCase = true)) {

src/test/groovy/com/github/gradle/node/npm/task/NpmRule_integTest.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ class NpmRule_integTest extends AbstractIntegTest {
2222
result.outcome == TaskOutcome.SUCCESS
2323
}
2424

25+
def 'can configure npm_ rule task'() {
26+
given:
27+
writeBuild('''
28+
plugins {
29+
id 'com.github.node-gradle.node'
30+
}
31+
32+
npm_run_build {
33+
doFirst { project.logger.info('configured') }
34+
}
35+
''')
36+
writeEmptyPackageJson()
37+
38+
when:
39+
def result = buildTask('help')
40+
41+
then:
42+
result.outcome == TaskOutcome.SUCCESS
43+
}
44+
2545
def 'can execute an npm module using npm_run_'() {
2646
given:
2747
writeBuild('''

src/test/groovy/com/github/gradle/node/yarn/task/YarnRule_integTest.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,25 @@ class YarnRule_integTest extends AbstractIntegTest {
4242
result.task(":yarn_run_hello").outcome == TaskOutcome.SUCCESS
4343
result.output.contains("Hello world!")
4444
}
45+
46+
def 'can configure yarn_ rule task'() {
47+
given:
48+
writeBuild("""
49+
plugins {
50+
id 'com.github.node-gradle.node'
51+
}
52+
53+
yarn_run_build {
54+
doFirst { project.logger.info('configured') }
55+
}
56+
""")
57+
58+
copyResources("fixtures/yarn-rule/package.json", "package.json")
59+
60+
when:
61+
def result = buildTask("help")
62+
63+
then:
64+
result.outcome == TaskOutcome.SUCCESS
65+
}
4566
}

0 commit comments

Comments
 (0)