From 71168e8024fe6c7a41c61db2dacefa978bc1b3b8 Mon Sep 17 00:00:00 2001 From: Alex Nordlund Date: Fri, 27 Nov 2020 12:16:16 +0100 Subject: [PATCH 1/2] Add tests for npm >= 7 --- .../node/npm/task/NpmInstall_integTest.groovy | 22 ++++++++++++ .../yarn/task/YarnInstall_integTest.groovy | 35 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/test/groovy/com/github/gradle/node/npm/task/NpmInstall_integTest.groovy b/src/test/groovy/com/github/gradle/node/npm/task/NpmInstall_integTest.groovy index 782879ec..7b8dcbf8 100644 --- a/src/test/groovy/com/github/gradle/node/npm/task/NpmInstall_integTest.groovy +++ b/src/test/groovy/com/github/gradle/node/npm/task/NpmInstall_integTest.groovy @@ -39,6 +39,28 @@ class NpmInstall_integTest extends AbstractIntegTest { result.task(":npmInstall").outcome == TaskOutcome.UP_TO_DATE } + def 'install packages with npm >= 7'() { + given: + writeBuild(''' + plugins { + id 'com.github.node-gradle.node' + } + + node { + download = true + version = '15.2.1' + npmVersion = '7.0.1' + } + ''') + writeEmptyPackageJson() + + when: + def result = build('npmInstall') + + then: + result.task(":npmInstall").outcome == TaskOutcome.SUCCESS + } + def 'install packages with npm and postinstall task requiring npm and node'() { given: writeBuild(''' diff --git a/src/test/groovy/com/github/gradle/node/yarn/task/YarnInstall_integTest.groovy b/src/test/groovy/com/github/gradle/node/yarn/task/YarnInstall_integTest.groovy index df036d04..7ee6a2db 100644 --- a/src/test/groovy/com/github/gradle/node/yarn/task/YarnInstall_integTest.groovy +++ b/src/test/groovy/com/github/gradle/node/yarn/task/YarnInstall_integTest.groovy @@ -36,6 +36,41 @@ class YarnInstall_integTest extends AbstractIntegTest { result.outcome == TaskOutcome.UP_TO_DATE } + def 'install packages with yarn on npm >= 7'() { + given: + writeBuild(''' + plugins { + id 'com.github.node-gradle.node' + } + + node { + download = true + yarnWorkDir = file('build/yarn') + version = '15.2.1' + npmVersion = '7.0.1' + } + ''') + writeEmptyPackageJson() + + when: + def result = buildTask('yarn') + + then: + result.outcome == TaskOutcome.SUCCESS + + when: + result = buildTask('yarn') + + then: + result.outcome == TaskOutcome.SUCCESS + + when: + result = buildTask('yarn') + + then: + result.outcome == TaskOutcome.UP_TO_DATE + } + def 'install packages with yarn and and postinstall task requiring node and yarn'() { given: writeBuild(''' From c7083642e25ba7667ed3957aeefcf0faf8e7c2b8 Mon Sep 17 00:00:00 2001 From: Alex Nordlund Date: Fri, 27 Nov 2020 15:30:52 +0100 Subject: [PATCH 2/2] Fix npm >= 7 support. --- .../kotlin/com/github/gradle/node/npm/task/NpmSetupTask.kt | 3 ++- .../kotlin/com/github/gradle/node/yarn/task/YarnSetupTask.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/github/gradle/node/npm/task/NpmSetupTask.kt b/src/main/kotlin/com/github/gradle/node/npm/task/NpmSetupTask.kt index 0dd37d5c..588130bc 100644 --- a/src/main/kotlin/com/github/gradle/node/npm/task/NpmSetupTask.kt +++ b/src/main/kotlin/com/github/gradle/node/npm/task/NpmSetupTask.kt @@ -13,6 +13,7 @@ import org.gradle.api.tasks.Internal import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import org.gradle.kotlin.dsl.listProperty +import java.io.File /** * npm install that only gets executed if gradle decides so. @@ -65,7 +66,7 @@ open class NpmSetupTask : DefaultTask() { val version = nodeExtension.npmVersion.get() val directory = npmDir.get().asFile // npm < 7 creates the directory if it's missing, >= 7 fails if it's missing - directory.mkdirs() + File(directory, "lib").mkdirs() return listOf("install", "--global", "--no-save", "--prefix", directory.absolutePath, "npm@$version") + args.get() } diff --git a/src/main/kotlin/com/github/gradle/node/yarn/task/YarnSetupTask.kt b/src/main/kotlin/com/github/gradle/node/yarn/task/YarnSetupTask.kt index 5ceeec88..20b2936a 100644 --- a/src/main/kotlin/com/github/gradle/node/yarn/task/YarnSetupTask.kt +++ b/src/main/kotlin/com/github/gradle/node/yarn/task/YarnSetupTask.kt @@ -6,6 +6,7 @@ import com.github.gradle.node.variant.VariantComputer import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputDirectory +import java.io.File /** * Setup a specific version of Yarn to be used by the build. @@ -33,7 +34,7 @@ open class YarnSetupTask : NpmSetupTask() { val yarnPackage = if (version.isNotBlank()) "yarn@$version" else "yarn" // npm < 7 creates the directory if it's missing, >= 7 fails if it's missing // create the directory since we use npm to install yarn. - yarnDir.asFile.mkdirs() + File(yarnDir.asFile, "lib").mkdirs() return listOf("install", "--global", "--no-save", "--prefix", yarnDir.asFile.absolutePath, yarnPackage) .plus(args.get()) }