From 871615702b8c70f27fe6d75c67bb6c6579506f51 Mon Sep 17 00:00:00 2001 From: akastijn Date: Wed, 30 Jul 2025 00:08:00 +0200 Subject: [PATCH] Update Node.js to v20.19.0 and npm to v10.2.3; refactor `npmBuild` task to use plugin-provided `npmCommand` and add `nodeVersionCheck` task for environment validation. --- frontend/build.gradle.kts | 54 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/frontend/build.gradle.kts b/frontend/build.gradle.kts index 8c1631f..af2d437 100644 --- a/frontend/build.gradle.kts +++ b/frontend/build.gradle.kts @@ -8,8 +8,9 @@ plugins { node { download.set(true) - version.set("22.14.0") - npmVersion.set("10.9.2") + // Update to the version that's compatible with your environment requirements + version.set("20.19.0") + npmVersion.set("10.2.3") // A compatible npm version for Node.js 20.19.0 workDir.set(file("${project.projectDir}/node")) npmWorkDir.set(file("${project.projectDir}/node")) } @@ -21,38 +22,37 @@ tasks.register("cleanDist") { } // Create a task that will run npm build -tasks.register("npmBuild") { +tasks.register("npmBuild") { description = "Run 'npm run build'" group = "build" - doLast { - // Use nodeCommand directly from the plugin - project.exec { - workingDir(project.projectDir) - - // Use node's npm to ensure it works on all environments - val nodeDir = "${project.projectDir}/node" - val isWindows = System.getProperty("os.name").lowercase().contains("windows") - - if (isWindows) { - val npmCmd = file(nodeDir).listFiles()?.find { it.name.startsWith("npm") && it.isDirectory }?.let { - "${it.absolutePath}/npm.cmd" - } ?: "$nodeDir/node_modules/npm/bin/npm.cmd" - - commandLine(npmCmd, "run", "build:dev") - } else { - val npmExecutable = file(nodeDir).listFiles()?.find { it.name.startsWith("npm") && it.isDirectory }?.let { - "${it.absolutePath}/bin/npm" - } ?: "$nodeDir/node_modules/npm/bin/npm" - - commandLine(npmExecutable, "run", "build:beta") - } - } - } + // Determine which build script to run based on the OS + val isWindows = System.getProperty("os.name").lowercase().contains("windows") + npmCommand.set(listOf("run", if (isWindows) "build:dev" else "build:beta")) dependsOn("npmInstall") } +// Add a new task to check Node.js and npm versions +tasks.register("nodeVersionCheck") { + description = "Check Node.js and npm versions" + script.set(file("${projectDir}/node-version-check.js")) + + doFirst { + // Create a temporary script to check versions + file("${projectDir}/node-version-check.js").writeText(""" + console.log('Node.js version:', process.version); + console.log('npm version:', require('npm/package.json').version); + console.log('Build command that would be used:', process.platform === 'win32' ? 'build:dev' : 'build:beta'); + """.trimIndent()) + } + + doLast { + // Clean up the temporary script + delete("${projectDir}/node-version-check.js") + } +} + tasks.named("assemble") { dependsOn("npmBuild") }