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' )

0 commit comments

Comments
 (0)