Skip to content

Commit 0125322

Browse files
committed
Fix configuration-cache support in Gradle 8.4
1 parent f327f5a commit 0125322

20 files changed

+118
-96
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

3-
## Version 5.x *(unreleased)*
3+
## Version 6.x *(unreleased)*
4+
* Removed deprecated `nodeModulesDir` from `NodeExtension`
5+
* The resolved/computed node directory and platform are stored in `resolvedNodeDir` and `resolvedPlatform` on `NodeExtension`
6+
* Fixes configuration-cache issue in Gradle 8.4
47

58
## Version 5.0.0 *(2023-05-13)*
69
* Support configuration-cache on Gradle 8.1 [#271](https://github.com/node-gradle/gradle-node-plugin/issues/271)

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ open class NodeExtension(project: Project) {
134134
*/
135135
val oldNpm = project.objects.property<Boolean>().convention(false)
136136

137-
@Suppress("unused")
138-
@Deprecated("Deprecated in version 3.0, please use nodeProjectDir now")
139-
val nodeModulesDir = nodeProjectDir
140-
141137
/**
142138
* Create rules for automatic task creation
143139
*
@@ -152,13 +148,25 @@ open class NodeExtension(project: Project) {
152148
/**
153149
* Computed path to nodejs directory
154150
*/
151+
@Deprecated(message = "replaced with resolvedNodeDir", replaceWith = ReplaceWith("resolvedNodeDir"))
155152
val computedNodeDir = project.objects.directoryProperty()
156153

154+
/**
155+
* Computed path to nodejs directory
156+
*/
157+
val resolvedNodeDir = project.objects.directoryProperty()
158+
157159
/**
158160
* Operating system and architecture
159161
*/
162+
@Deprecated(message = "replaced with resolvedPlatform", replaceWith = ReplaceWith("resolvedPlatform"))
160163
val computedPlatform = project.objects.property<Platform>()
161164

165+
/**
166+
* Operating system and architecture
167+
*/
168+
val resolvedPlatform = project.objects.property<Platform>()
169+
162170
init {
163171
distBaseUrl.set("https://nodejs.org/dist")
164172
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ class NodePlugin : Plugin<Project> {
4848
}
4949
}
5050

51+
@SuppressWarnings("deprecation")
5152
private fun configureNodeExtension(extension: NodeExtension) {
5253
addPlatform(extension)
53-
extension.computedNodeDir.set(computeNodeDir(extension))
54-
extension.computedNodeDir.finalizeValueOnRead()
54+
with(extension.resolvedNodeDir) {
55+
set(computeNodeDir(extension))
56+
finalizeValueOnRead()
57+
}
58+
with(extension.computedNodeDir) {
59+
convention(extension.resolvedNodeDir)
60+
finalizeValueOnRead()
61+
}
5562
}
5663

5764
private fun addPlatform(extension: NodeExtension) {
@@ -77,7 +84,8 @@ class NodePlugin : Plugin<Project> {
7784
val name = System.getProperty("os.name")
7885
val arch = System.getProperty("os.arch")
7986
val platform = parsePlatform(name, arch, uname)
80-
extension.computedPlatform.set(platform)
87+
extension.resolvedPlatform.set(platform)
88+
extension.computedPlatform.convention(extension.resolvedPlatform)
8189
}
8290

8391
private fun addGlobalTypes() {
@@ -167,7 +175,7 @@ class NodePlugin : Plugin<Project> {
167175

168176
private fun configureNodeSetupTask(nodeExtension: NodeExtension) {
169177
project.tasks.withType<NodeSetupTask>().configureEach {
170-
nodeDir.set(nodeExtension.computedNodeDir)
178+
nodeDir.set(nodeExtension.resolvedNodeDir)
171179
val archiveFileProvider = computeNodeArchiveDependency(nodeExtension)
172180
.map { nodeArchiveDependency ->
173181
resolveNodeArchiveFile(nodeArchiveDependency)

src/main/kotlin/com/github/gradle/node/exec/NodeExecRunner.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ fun buildExecConfiguration(
1717
nodeExecConfiguration: NodeExecConfiguration,
1818
variantComputer: VariantComputer
1919
):
20-
Provider<ExecConfiguration> {
21-
val nodeDirProvider = nodeExtension.computedNodeDir
20+
Provider<ExecConfiguration> {
21+
val nodeDirProvider = nodeExtension.resolvedNodeDir
2222
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider)
2323
val executableProvider = computeNodeExec(nodeExtension, nodeBinDirProvider)
2424
val additionalBinPathProvider = computeAdditionalBinPath(nodeExtension, nodeBinDirProvider)

src/main/kotlin/com/github/gradle/node/npm/exec/NpmExecRunner.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ abstract class NpmExecRunner {
8080
npmExecConfiguration: NpmExecConfiguration,
8181
variantComputer: VariantComputer
8282
):
83-
Provider<ExecutableAndScript> {
84-
val nodeDirProvider = nodeExtension.computedNodeDir
83+
Provider<ExecutableAndScript> {
84+
val nodeDirProvider = nodeExtension.resolvedNodeDir
8585
val npmDirProvider = variantComputer.computeNpmDir(nodeExtension, nodeDirProvider)
8686
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider)
8787
val npmBinDirProvider = variantComputer.computeNpmBinDir(npmDirProvider)
8888
val nodeExecProvider = computeNodeExec(nodeExtension, nodeBinDirProvider)
8989
val executableProvider =
9090
npmExecConfiguration.commandExecComputer(variantComputer, nodeExtension, npmBinDirProvider)
91-
val isWindows = nodeExtension.computedPlatform.get().isWindows()
91+
val isWindows = nodeExtension.resolvedPlatform.get().isWindows()
9292
val npmScriptFileProvider =
9393
computeNpmScriptFile(nodeDirProvider, npmExecConfiguration.command, isWindows)
9494
return zip(
@@ -120,7 +120,7 @@ abstract class NpmExecRunner {
120120
if (!download) {
121121
providers.provider { listOf<String>() }
122122
}
123-
val nodeDirProvider = variantComputer.computeNodeDir(nodeExtension)
123+
val nodeDirProvider = nodeExtension.resolvedNodeDir
124124
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider)
125125
val npmDirProvider = variantComputer.computeNpmDir(nodeExtension, nodeDirProvider)
126126
val npmBinDirProvider = variantComputer.computeNpmBinDir(npmDirProvider)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ abstract class NpmSetupTask : BaseTask() {
4444

4545
@get:OutputDirectory
4646
val npmDir by lazy {
47-
val nodeDir = variantComputer.computeNodeDir(nodeExtension)
47+
val nodeDir = nodeExtension.resolvedNodeDir
4848
variantComputer.computeNpmDir(nodeExtension, nodeDir)
4949
}
5050

src/main/kotlin/com/github/gradle/node/pnpm/exec/PnpmExecRunner.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ abstract class PnpmExecRunner {
7474
variantComputer: VariantComputer
7575
):
7676
Provider<ExecutableAndScript> {
77-
val nodeDirProvider = variantComputer.computeNodeDir(nodeExtension)
77+
val nodeDirProvider = nodeExtension.resolvedNodeDir
7878
val pnpmDirProvider = variantComputer.computePnpmDir(nodeExtension)
7979
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider)
8080
val pnpmBinDirProvider = variantComputer.computePnpmBinDir(pnpmDirProvider)
@@ -105,7 +105,7 @@ abstract class PnpmExecRunner {
105105
if (!download) {
106106
providers.provider { listOf<String>() }
107107
}
108-
val nodeDirProvider = variantComputer.computeNodeDir(nodeExtension)
108+
val nodeDirProvider = nodeExtension.resolvedNodeDir
109109
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider)
110110
val pnpmDirProvider = variantComputer.computePnpmDir(nodeExtension)
111111
val pnpmBinDirProvider = variantComputer.computePnpmBinDir(pnpmDirProvider)

src/main/kotlin/com/github/gradle/node/task/NodeSetupTask.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ abstract class NodeSetupTask : BaseTask() {
6262

6363
private fun unpackNodeArchive() {
6464
val archiveFile = nodeArchiveFile.get().asFile
65-
val nodeDirProvider = nodeExtension.computedNodeDir
65+
val nodeDirProvider = nodeExtension.resolvedNodeDir
6666
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider)
6767
val archivePath = nodeDirProvider.map { it.dir("../") }
6868
if (archiveFile.name.endsWith("zip")) {
@@ -84,15 +84,15 @@ abstract class NodeSetupTask : BaseTask() {
8484

8585
private fun fixBrokenSymlink(name: String, nodeBinDirPath: Path, nodeDirProvider: Provider<Directory>) {
8686
val script = nodeBinDirPath.resolve(name)
87-
val scriptFile = computeNpmScriptFile(nodeDirProvider, name, nodeExtension.computedPlatform.get().isWindows())
87+
val scriptFile = computeNpmScriptFile(nodeDirProvider, name, nodeExtension.resolvedPlatform.get().isWindows())
8888
if (Files.deleteIfExists(script)) {
8989
Files.createSymbolicLink(script, nodeBinDirPath.relativize(Paths.get(scriptFile.get())))
9090
}
9191
}
9292

9393
private fun setExecutableFlag() {
94-
if (!nodeExtension.computedPlatform.get().isWindows()) {
95-
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeExtension.computedNodeDir)
94+
if (!nodeExtension.resolvedPlatform.get().isWindows()) {
95+
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeExtension.resolvedNodeDir)
9696
val nodeExecProvider = computeNodeExec(nodeExtension, nodeBinDirProvider)
9797
File(nodeExecProvider.get()).setExecutable(true)
9898
}

src/main/kotlin/com/github/gradle/node/variant/VariantComputer.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fun computeNodeExec(nodeExtension: NodeExtension, nodeBinDirProvider: Provider<D
1515
return zip(nodeExtension.download, nodeBinDirProvider).map {
1616
val (download, nodeBinDir) = it
1717
if (download) {
18-
val nodeCommand = if (nodeExtension.computedPlatform.get().isWindows()) "node.exe" else "node"
18+
val nodeCommand = if (nodeExtension.resolvedPlatform.get().isWindows()) "node.exe" else "node"
1919
nodeBinDir.dir(nodeCommand).asFile.absolutePath
2020
} else "node"
2121
}
@@ -28,8 +28,8 @@ fun computeNpmScriptFile(nodeDirProvider: Provider<Directory>, command: String,
2828
}
2929

3030
fun computeNodeDir(nodeExtension: NodeExtension): Provider<Directory> {
31-
val osName = nodeExtension.computedPlatform.get().name
32-
val osArch = nodeExtension.computedPlatform.get().arch
31+
val osName = nodeExtension.resolvedPlatform.get().name
32+
val osArch = nodeExtension.resolvedPlatform.get().arch
3333
return computeNodeDir(nodeExtension, osName, osArch)
3434
}
3535

@@ -46,9 +46,9 @@ fun computeNodeDir(nodeExtension: NodeExtension, osName: String, osArch: String)
4646
* Essentially: org.nodejs:node:$version:$osName-$osArch@tar.gz
4747
*/
4848
fun computeNodeArchiveDependency(extension: NodeExtension): Provider<String> {
49-
val osName = extension.computedPlatform.get().name
50-
val osArch = extension.computedPlatform.get().arch
51-
val type = if (extension.computedPlatform.get().isWindows()) "zip" else "tar.gz"
49+
val osName = extension.resolvedPlatform.get().name
50+
val osArch = extension.resolvedPlatform.get().arch
51+
val type = if (extension.resolvedPlatform.get().isWindows()) "zip" else "tar.gz"
5252
return extension.version.map { version -> "org.nodejs:node:$version:$osName-$osArch@$type" }
5353
}
5454

@@ -112,7 +112,7 @@ open class VariantComputer constructor(
112112
fun computeNpmExec(nodeExtension: NodeExtension, npmBinDirProvider: Provider<Directory>): Provider<String> {
113113
return zip(nodeExtension.download, nodeExtension.npmCommand, npmBinDirProvider).map {
114114
val (download, npmCommand, npmBinDir) = it
115-
val command = if (nodeExtension.computedPlatform.get().isWindows()) {
115+
val command = if (nodeExtension.resolvedPlatform.get().isWindows()) {
116116
npmCommand.mapIf({ it == "npm" }) { "npm.cmd" }
117117
} else npmCommand
118118
if (download) npmBinDir.dir(command).asFile.absolutePath else command
@@ -132,7 +132,7 @@ open class VariantComputer constructor(
132132
fun computeNpxExec(nodeExtension: NodeExtension, npmBinDirProvider: Provider<Directory>): Provider<String> {
133133
return zip(nodeExtension.download, nodeExtension.npxCommand, npmBinDirProvider).map {
134134
val (download, npxCommand, npmBinDir) = it
135-
val command = if (nodeExtension.computedPlatform.get().isWindows()) {
135+
val command = if (nodeExtension.resolvedPlatform.get().isWindows()) {
136136
npxCommand.mapIf({ it == "npx" }) { "npx.cmd" }
137137
} else npxCommand
138138
if (download) npmBinDir.dir(command).asFile.absolutePath else command
@@ -155,7 +155,7 @@ open class VariantComputer constructor(
155155
fun computePnpmExec(nodeExtension: NodeExtension, pnpmBinDirProvider: Provider<Directory>): Provider<String> {
156156
return zip(nodeExtension.pnpmCommand, nodeExtension.download, pnpmBinDirProvider).map {
157157
val (pnpmCommand, download, pnpmBinDir) = it
158-
val command = if (nodeExtension.computedPlatform.get().isWindows()) {
158+
val command = if (nodeExtension.resolvedPlatform.get().isWindows()) {
159159
pnpmCommand.mapIf({ it == "pnpm" }) { "pnpm.cmd" }
160160
} else pnpmCommand
161161
if (download) pnpmBinDir.dir(command).asFile.absolutePath else command
@@ -178,7 +178,7 @@ open class VariantComputer constructor(
178178
fun computeYarnExec(nodeExtension: NodeExtension, yarnBinDirProvider: Provider<Directory>): Provider<String> {
179179
return zip(nodeExtension.yarnCommand, nodeExtension.download, yarnBinDirProvider).map {
180180
val (yarnCommand, download, yarnBinDir) = it
181-
val command = if (nodeExtension.computedPlatform.get().isWindows()) {
181+
val command = if (nodeExtension.resolvedPlatform.get().isWindows()) {
182182
yarnCommand.mapIf({ it == "yarn" }) { "yarn.cmd" }
183183
} else yarnCommand
184184
if (download) yarnBinDir.dir(command).asFile.absolutePath else command

src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ abstract class YarnExecRunner {
2424
nodeExecConfiguration: NodeExecConfiguration,
2525
variantComputer: VariantComputer
2626
): ExecResult {
27-
val nodeDirProvider = variantComputer.computeNodeDir(nodeExtension)
27+
val nodeDirProvider = nodeExtension.resolvedNodeDir
2828
val yarnDirProvider = variantComputer.computeYarnDir(nodeExtension)
2929
val yarnBinDirProvider = variantComputer.computeYarnBinDir(yarnDirProvider)
3030
val yarnExecProvider = variantComputer.computeYarnExec(nodeExtension, yarnBinDirProvider)
3131
val additionalBinPathProvider =
32-
computeAdditionalBinPath(nodeExtension, nodeDirProvider, yarnBinDirProvider, variantComputer)
33-
val execConfiguration = ExecConfiguration(yarnExecProvider.get(),
34-
nodeExecConfiguration.command, additionalBinPathProvider.get(),
35-
addNpmProxyEnvironment(nodeExtension, nodeExecConfiguration), nodeExecConfiguration.workingDir,
36-
nodeExecConfiguration.ignoreExitValue, nodeExecConfiguration.execOverrides)
32+
computeAdditionalBinPath(nodeExtension, nodeDirProvider, yarnBinDirProvider, variantComputer)
33+
val execConfiguration = ExecConfiguration(
34+
yarnExecProvider.get(),
35+
nodeExecConfiguration.command, additionalBinPathProvider.get(),
36+
addNpmProxyEnvironment(nodeExtension, nodeExecConfiguration), nodeExecConfiguration.workingDir,
37+
nodeExecConfiguration.ignoreExitValue, nodeExecConfiguration.execOverrides
38+
)
3739
val execRunner = ExecRunner()
3840

3941
return execRunner.execute(project, nodeExtension, execConfiguration)

0 commit comments

Comments
 (0)