Skip to content

Commit 344638a

Browse files
committed
Merge branch '3.x'
2 parents 795c36f + 85d5ff4 commit 344638a

File tree

17 files changed

+109
-46
lines changed

17 files changed

+109
-46
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Version 3.x *(unreleased)*
44

5+
## Version 3.6.0 *(2023-04-20)*
6+
* Allow task rules to be disabled [#116](https://github.com/node-gradle/gradle-node-plugin/issues/116)
7+
* Add `fastNpmInstall` option to only track lock-files #[157](https://github.com/node-gradle/gradle-node-plugin/issues/157)
8+
59
## Version 3.5.1 *(2022-12-26)*
610
* Fix configuration cache support in pnpm
711

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
![Build Status](https://github.com/node-gradle/gradle-node-plugin/workflows/Build/badge.svg?branch=master)
66
[![License](https://img.shields.io/github/license/node-gradle/gradle-node-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
7-
![Version](https://img.shields.io/badge/Version-3.5.1-orange.svg)
7+
![Version](https://img.shields.io/badge/Version-3.6.0-orange.svg)
88

99
This plugin enables you to use a lot of [Node.js](https://nodejs.org)-based technologies as part of your
1010
build without having Node.js installed locally on your system. It integrates the following Node.js-based system
@@ -39,7 +39,8 @@ issue to [GitHub Issues](https://github.com/node-gradle/gradle-node-plugin/issue
3939

4040
Here's the documentation for older releases of the plugin:
4141

42-
* [3.5.1](https://github.com/node-gradle/gradle-node-plugin/blob/3.5.1/README.md) (current)
42+
* [3.6.0](https://github.com/node-gradle/gradle-node-plugin/blob/3.6.0/README.md) (current)
43+
* [3.5.1](https://github.com/node-gradle/gradle-node-plugin/blob/3.5.1/README.md)
4344
* [3.5.0](https://github.com/node-gradle/gradle-node-plugin/blob/3.5.0/README.md)
4445
* [3.4.0](https://github.com/node-gradle/gradle-node-plugin/blob/3.4.0/README.md)
4546
* [3.3.0](https://github.com/node-gradle/gradle-node-plugin/blob/3.3.0/README.md)

docs/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ in your `build.gradle` file:
55

66
```gradle
77
plugins {
8-
id "com.github.node-gradle.node" version "3.5.1"
8+
id "com.github.node-gradle.node" version "3.6.0"
99
}
1010
```
1111

@@ -18,7 +18,7 @@ buildscript {
1818
}
1919
2020
dependencies {
21-
classpath "com.github.node-gradle:gradle-node-plugin:3.5.1"
21+
classpath "com.github.node-gradle:gradle-node-plugin:3.6.0"
2222
}
2323
}
2424

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ file (see [Installing](installation.md) for details):
1818

1919
```gradle
2020
plugins {
21-
id "com.github.node-gradle.node" version "3.5.1"
21+
id "com.github.node-gradle.node" version "3.6.0"
2222
}
2323
```
2424

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ open class NodeExtension(project: Project) {
137137
@Deprecated("Deprecated in version 3.0, please use nodeProjectDir now")
138138
val nodeModulesDir = nodeProjectDir
139139

140+
/**
141+
* Create rules for automatic task creation
142+
*
143+
* Disabling this will prevent the npm_ npx_ yarn_ pnpm_ tasks from being
144+
* automatically created.
145+
* It's recommended to turn this off after you've gotten comfortable
146+
* with the plugin and register your own tasks instead of relying on the rule.
147+
*/
148+
val enableTaskRules = project.objects.property<Boolean>().convention(true)
149+
140150
init {
141151
distBaseUrl.set("https://nodejs.org/dist")
142152
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.github.gradle.node.yarn.task.YarnSetupTask
1515
import com.github.gradle.node.yarn.task.YarnTask
1616
import org.gradle.api.Plugin
1717
import org.gradle.api.Project
18+
import org.gradle.api.provider.Property
1819
import org.gradle.kotlin.dsl.create
1920
import org.gradle.kotlin.dsl.named
2021
import org.gradle.kotlin.dsl.register
@@ -30,9 +31,9 @@ class NodePlugin : Plugin<Project> {
3031
project.extensions.create<PackageJsonExtension>(PackageJsonExtension.NAME, project)
3132
addGlobalTypes()
3233
addTasks()
33-
addNpmRule()
34-
addPnpmRule()
35-
addYarnRule()
34+
addNpmRule(nodeExtension.enableTaskRules)
35+
addPnpmRule(nodeExtension.enableTaskRules)
36+
addYarnRule(nodeExtension.enableTaskRules)
3637
project.afterEvaluate {
3738
if (nodeExtension.download.get()) {
3839
nodeExtension.distBaseUrl.orNull?.let { addRepository(it, nodeExtension.allowInsecureProtocol.orNull) }
@@ -64,10 +65,10 @@ class NodePlugin : Plugin<Project> {
6465
project.tasks.register<YarnSetupTask>(YarnSetupTask.NAME)
6566
}
6667

67-
private fun addNpmRule() { // note this rule also makes it possible to specify e.g. "dependsOn npm_install"
68+
private fun addNpmRule(enableTaskRules: Property<Boolean>) { // note this rule also makes it possible to specify e.g. "dependsOn npm_install"
6869
project.tasks.addRule("Pattern: \"npm_<command>\": Executes an NPM command.") {
6970
val taskName = this
70-
if (taskName.startsWith("npm_")) {
71+
if (taskName.startsWith("npm_") && enableTaskRules.get()) {
7172
project.tasks.create<NpmTask>(taskName) {
7273
val tokens = taskName.split("_").drop(1) // all except first
7374
npmCommand.set(tokens)
@@ -79,10 +80,10 @@ class NodePlugin : Plugin<Project> {
7980
}
8081
}
8182

82-
private fun addPnpmRule() { // note this rule also makes it possible to specify e.g. "dependsOn npm_install"
83+
private fun addPnpmRule(enableTaskRules: Property<Boolean>) { // note this rule also makes it possible to specify e.g. "dependsOn npm_install"
8384
project.tasks.addRule("Pattern: \"pnpm_<command>\": Executes an PNPM command.") {
8485
val taskName = this
85-
if (taskName.startsWith("pnpm_")) {
86+
if (taskName.startsWith("pnpm_") && enableTaskRules.get()) {
8687
project.tasks.register<PnpmTask>(taskName) {
8788
val tokens = taskName.split("_").drop(1) // all except first
8889
pnpmCommand.set(tokens)
@@ -94,10 +95,10 @@ class NodePlugin : Plugin<Project> {
9495
}
9596
}
9697

97-
private fun addYarnRule() { // note this rule also makes it possible to specify e.g. "dependsOn yarn_install"
98+
private fun addYarnRule(enableTaskRules: Property<Boolean>) { // note this rule also makes it possible to specify e.g. "dependsOn yarn_install"
9899
project.tasks.addRule("Pattern: \"yarn_<command>\": Executes an Yarn command.") {
99100
val taskName = this
100-
if (taskName.startsWith("yarn_")) {
101+
if (taskName.startsWith("yarn_") && enableTaskRules.get()) {
101102
project.tasks.create<YarnTask>(taskName) {
102103
val tokens = taskName.split("_").drop(1) // all except first
103104
yarnCommand.set(tokens)

src/main/kotlin/com/github/gradle/node/npm/task/NpmInstallTask.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ abstract class NpmInstallTask : NpmTask() {
2929
dependsOn(NpmSetupTask.NAME)
3030
npmCommand.set(nodeExtension.npmInstallCommand.map { listOf(it) })
3131
fastInstall.set(nodeExtension.fastNpmInstall)
32+
outputs.doNotCacheIf("With fastNpmInstall there's no output to cache") {
33+
fastInstall.get()
34+
}
3235
}
3336

3437
@PathSensitive(RELATIVE)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.github.gradle.node
2+
3+
class Versions {
4+
static TEST_PNPM_DOWNLOAD_VERSION = "8.1.1"
5+
static TEST_PNPM_DOWNLOAD_REGEX = /\n8\.1\.1\n/
6+
static TEST_PNPM_LOCAL_VERSION = "8.2.0"
7+
static TEST_PNPM_LOCAL_REGEX = /\n8\.2\.0\n/
8+
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ class NpmRule_integTest extends AbstractIntegTest {
2727
gv << GRADLE_VERSIONS_UNDER_TEST
2828
}
2929
30+
def 'rules can be disabled (#gv.version)'() {
31+
given:
32+
gradleVersion = gv
33+
writeBuild('''
34+
plugins {
35+
id 'com.github.node-gradle.node'
36+
}
37+
38+
node {
39+
enableTaskRules = false
40+
}
41+
''')
42+
writeEmptyPackageJson()
43+
44+
when:
45+
def result = buildAndFail('npm_install')
46+
47+
then:
48+
result.output.contains("Task 'npm_install' not found")
49+
50+
where:
51+
gv << GRADLE_VERSIONS_UNDER_TEST
52+
}
53+
3054
def 'can configure npm_ rule task (#gv.version)'() {
3155
given:
3256
gradleVersion = gv

src/test/groovy/com/github/gradle/node/pnpm/task/PnpmInstall_integTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PnpmInstall_integTest
2222
}
2323
''' )
2424
writeEmptyPackageJson()
25+
writeFile("pnpm-lock.yaml", "lockfileVersion: '6.0'")
2526
2627
when:
2728
def result = build( 'pnpmInstall' )
@@ -65,6 +66,7 @@ class PnpmInstall_integTest
6566
"postinstall" : "pnpm run versionOutput"
6667
}
6768
""")
69+
writeFile("pnpm-lock.yaml", "lockfileVersion: '6.0'")
6870
6971
when:
7072
def result = build( 'pnpmInstall', '--info' )

src/test/groovy/com/github/gradle/node/pnpm/task/PnpmRule_integTest.groovy

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.github.gradle.node.pnpm.task
22

33
import com.github.gradle.AbstractIntegTest
4+
import com.github.gradle.node.Versions
45
import org.gradle.testkit.runner.TaskOutcome
6+
import spock.lang.Ignore
57

68
import java.util.regex.Pattern
79

@@ -36,48 +38,50 @@ class PnpmRule_integTest extends AbstractIntegTest {
3638
{
3739
given:
3840
gradleVersion = gv
39-
writeBuild( '''
41+
writeBuild( """
4042
plugins {
4143
id 'com.github.node-gradle.node'
4244
}
4345
node {
4446
download = true
45-
pnpmVersion = '4.12.4'
47+
pnpmVersion = '${Versions.TEST_PNPM_DOWNLOAD_VERSION}'
4648
}
47-
''' )
49+
""" )
4850
writeEmptyPackageJson()
4951
5052
when:
5153
def result = build( 'pnpm_--version' )
5254
5355
then:
54-
result.output =~ /\n4\.12\.4\n/
56+
result.output =~ Versions.TEST_PNPM_DOWNLOAD_REGEX
5557
result.task( ':pnpm_--version' ).outcome == TaskOutcome.SUCCESS
5658
5759
where:
5860
gv << GRADLE_VERSIONS_UNDER_TEST
5961
}
6062
63+
@Ignore("https://github.com/node-gradle/gradle-node-plugin/issues/270")
6164
def 'Use local pnpm installation (#gv.version)'()
6265
{
6366
given:
6467
gradleVersion = gv
65-
writeBuild( '''
68+
writeBuild( """
6669
plugins {
6770
id 'com.github.node-gradle.node'
6871
}
6972
node {
7073
download = true
74+
pnpmVersion = '${Versions.TEST_PNPM_DOWNLOAD_VERSION}'
7175
}
72-
''' )
76+
""" )
7377
writeEmptyPackageJson()
7478
7579
when:
76-
build( 'pnpm_install_pnpm@4.12.1' )
80+
build( "pnpm_install_pnpm@${Versions.TEST_PNPM_LOCAL_VERSION}" )
7781
def result = build( 'pnpm_--version' )
7882
7983
then:
80-
result.output =~ /\n4\.12\.1\n/
84+
result.output =~ Versions.TEST_PNPM_LOCAL_REGEX
8185
result.task( ':pnpm_--version' ).outcome == TaskOutcome.SUCCESS
8286
8387
where:
@@ -133,7 +137,7 @@ class PnpmRule_integTest extends AbstractIntegTest {
133137
then:
134138
result.task(":pnpmInstall").outcome == TaskOutcome.SUCCESS
135139
result.task(":pnpm_run_pnpmVersion").outcome == TaskOutcome.SUCCESS
136-
def versionPattern = Pattern.compile(".*Version\\s+4.12.1.*", Pattern.DOTALL)
140+
def versionPattern = Pattern.compile(".*Version\\s+${Versions.TEST_PNPM_LOCAL_VERSION}.*", Pattern.DOTALL)
137141
versionPattern.matcher(result.output).find()
138142
139143
where:
@@ -181,16 +185,16 @@ class PnpmRule_integTest extends AbstractIntegTest {
181185
{
182186
given:
183187
gradleVersion = gv
184-
writeBuild( '''
188+
writeBuild( """
185189
plugins {
186190
id 'com.github.node-gradle.node'
187191
}
188192
node {
189193
download = true
190-
pnpmVersion = '4.12.4'
194+
pnpmVersion = '${Versions.TEST_PNPM_DOWNLOAD_VERSION}'
191195
nodeModulesDir = file("frontend")
192196
}
193-
''' )
197+
""" )
194198
writeFile( 'frontend/package.json', """{
195199
"name": "example",
196200
"dependencies": {},
@@ -203,7 +207,7 @@ class PnpmRule_integTest extends AbstractIntegTest {
203207
def result = build( 'pnpm_run_whatVersion' )
204208
205209
then:
206-
result.output =~ /\n4\.12\.4\n/
210+
result.output =~ Versions.TEST_PNPM_DOWNLOAD_REGEX
207211
result.task( ':pnpm_run_whatVersion' ).outcome == TaskOutcome.SUCCESS
208212
209213
where:

src/test/groovy/com/github/gradle/node/pnpm/task/PnpmSetupTaskTest.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.gradle.node.pnpm.task
22

3+
import com.github.gradle.node.Versions
34
import com.github.gradle.node.task.AbstractTaskTest
45
import org.gradle.process.ExecSpec
56

@@ -27,7 +28,7 @@ class PnpmSetupTaskTest
2728

2829
def "exec pnpmSetup task with pnpm version specified"() {
2930
given:
30-
nodeExtension.pnpmVersion.set('4.12.4')
31+
nodeExtension.pnpmVersion.set(Versions.TEST_PNPM_DOWNLOAD_VERSION)
3132
def task = project.tasks.create('simple', PnpmSetupTask)
3233
mockProjectApiHelperExec(task)
3334

@@ -38,8 +39,8 @@ class PnpmSetupTaskTest
3839
then:
3940
1 * execSpec.setArgs({ args ->
4041
def expectedPnpmInstallPath = projectDir.toPath().resolve('.gradle').resolve('pnpm')
41-
.resolve('pnpm-v4.12.4').toAbsolutePath().toString()
42-
def expectedArgs = ['install', '--global', '--no-save', '--prefix', expectedPnpmInstallPath, 'pnpm@4.12.4']
42+
.resolve("pnpm-v${Versions.TEST_PNPM_DOWNLOAD_VERSION}").toAbsolutePath().toString()
43+
def expectedArgs = ['install', '--global', '--no-save', '--prefix', expectedPnpmInstallPath, "pnpm@${Versions.TEST_PNPM_DOWNLOAD_VERSION}"]
4344
// Workaround a strange issue on Github actions macOS hosts
4445
return args.collect { it.replace("^/private/", "/") } == expectedArgs
4546
})

src/test/groovy/com/github/gradle/node/pnpm/task/PnpmTask_integTest.groovy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.github.gradle.node.pnpm.task
22

33
import com.github.gradle.AbstractIntegTest
4+
import com.github.gradle.node.Versions
45
import org.gradle.testkit.runner.TaskOutcome
56
import org.junit.Rule
67
import org.junit.contrib.java.lang.system.EnvironmentVariables
8+
import spock.lang.Ignore
79

810
class PnpmTask_integTest extends AbstractIntegTest {
911
@Rule
@@ -48,12 +50,13 @@ class PnpmTask_integTest extends AbstractIntegTest {
4850
4951
then:
5052
result4.task(":version").outcome == TaskOutcome.SUCCESS
51-
result4.output.contains("> Task :version${System.lineSeparator()}4.12.4")
53+
result4.output.contains("> Task :version${System.lineSeparator()}${Versions.TEST_PNPM_DOWNLOAD_VERSION}")
5254
5355
where:
5456
gv << GRADLE_VERSIONS_UNDER_TEST
5557
}
5658
59+
@Ignore("https://github.com/node-gradle/gradle-node-plugin/issues/270")
5760
def 'execute pnpm command with custom execution configuration and check up-to-date-detection (#gv.version)'() {
5861
given:
5962
gradleVersion = gv
@@ -146,12 +149,13 @@ class PnpmTask_integTest extends AbstractIntegTest {
146149
147150
then:
148151
result9.task(":version").outcome == TaskOutcome.SUCCESS
149-
result9.output.contains("> Task :version${System.lineSeparator()}4.12.4")
152+
result9.output.contains("> Task :version${System.lineSeparator()}${Versions.TEST_PNPM_DOWNLOAD_VERSION}")
150153
151154
where:
152155
gv << GRADLE_VERSIONS_UNDER_TEST
153156
}
154157
158+
@Ignore("https://github.com/node-gradle/gradle-node-plugin/issues/270")
155159
def 'execute pnpm command using the pnpm version specified in the package.json file (#gv.version)'() {
156160
given:
157161
gradleVersion = gv
@@ -163,7 +167,7 @@ class PnpmTask_integTest extends AbstractIntegTest {
163167
164168
then:
165169
result.task(":version").outcome == TaskOutcome.SUCCESS
166-
result.output.contains("> Task :version${System.lineSeparator()}4.12.1")
170+
result.output.contains("> Task :version${System.lineSeparator()}${Versions.TEST_PNPM_LOCAL_VERSION}")
167171
168172
where:
169173
gv << GRADLE_VERSIONS_UNDER_TEST

src/test/resources/fixtures/pnpm-env/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
node {
88
download = true
99
workDir = file("build/node")
10-
pnpmVersion = '4.12.4'
10+
pnpmVersion = '8.1.1'
1111
}
1212

1313
task env(type: PnpmTask) {

0 commit comments

Comments
 (0)