From 2b0eda28810032542d6c4f64ae6e792daf29d020 Mon Sep 17 00:00:00 2001 From: Alex Nordlund Date: Thu, 17 Aug 2023 18:15:41 +0200 Subject: [PATCH] Always use downloaded Yarn as per documentation #284 --- .github/workflows/build-examples.yml | 2 -- .github/workflows/build.yml | 2 -- .github/workflows/publish.yml | 2 -- CHANGELOG.md | 1 + .../gradle/node/variant/VariantComputer.kt | 7 ++++--- .../gradle/node/yarn/exec/YarnExecRunner.kt | 20 ++++++++----------- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build-examples.yml b/.github/workflows/build-examples.yml index d8a2520f..640e7718 100644 --- a/.github/workflows/build-examples.yml +++ b/.github/workflows/build-examples.yml @@ -15,8 +15,6 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 - - name: Install yarn - run: npm install -g yarn@1.22.17 - name: Gradle Version run: ./gradlew --version - name: Build Node.js Scripts Project diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 911cbb02..09d50d77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,8 +22,6 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 - - name: Install yarn - run: npm install -g yarn@1.22.17 - name: Setup Gradle uses: gradle/gradle-build-action@v2 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index afaeb8f9..f31566a2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -20,8 +20,6 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 - - name: Install yarn - run: npm install -g yarn@1.22.17 - name: Build run: ./gradlew build - name: Publish diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e5374d..1bd5d80c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Version 6.x *(unreleased)* * Upgrade default Node to 18.17.1 and npm to 9.6.7 +* Always use downloaded Yarn as per documentation [#284](https://github.com/node-gradle/gradle-node-plugin/issues/284) ## Version 6.0.0 *(2023-08-15)* * Removed deprecated `nodeModulesDir` from `NodeExtension` diff --git a/src/main/kotlin/com/github/gradle/node/variant/VariantComputer.kt b/src/main/kotlin/com/github/gradle/node/variant/VariantComputer.kt index 0a4ebb93..f713ef62 100644 --- a/src/main/kotlin/com/github/gradle/node/variant/VariantComputer.kt +++ b/src/main/kotlin/com/github/gradle/node/variant/VariantComputer.kt @@ -153,12 +153,13 @@ open class VariantComputer { fun computeYarnBinDir(yarnDirProvider: Provider, platform: Property) = computeProductBinDir(yarnDirProvider, platform) fun computeYarnExec(nodeExtension: NodeExtension, yarnBinDirProvider: Provider): Provider { - return zip(nodeExtension.yarnCommand, nodeExtension.download, yarnBinDirProvider).map { - val (yarnCommand, download, yarnBinDir) = it + return zip(nodeExtension.yarnCommand, yarnBinDirProvider).map { + val (yarnCommand, yarnBinDir) = it val command = if (nodeExtension.resolvedPlatform.get().isWindows()) { yarnCommand.mapIf({ it == "yarn" }) { "yarn.cmd" } } else yarnCommand - if (download) yarnBinDir.dir(command).asFile.absolutePath else command + // This is conceptually pretty simple as we per documentation always download yarn + yarnBinDir.dir(command).asFile.absolutePath } } diff --git a/src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt b/src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt index 6189b2e9..2f661b81 100644 --- a/src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt +++ b/src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt @@ -58,17 +58,13 @@ abstract class YarnExecRunner { yarnBinDirProvider: Provider, variantComputer: VariantComputer ): Provider> { - return nodeExtension.download.flatMap { download -> - if (!download) { - providers.provider { listOf() } - } - val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider, nodeExtension.resolvedPlatform) - val npmDirProvider = variantComputer.computeNpmDir(nodeExtension, nodeDirProvider) - val npmBinDirProvider = variantComputer.computeNpmBinDir(npmDirProvider, nodeExtension.resolvedPlatform) - zip(nodeBinDirProvider, npmBinDirProvider, yarnBinDirProvider) - .map { (nodeBinDir, npmBinDir, yarnBinDir) -> - listOf(yarnBinDir, npmBinDir, nodeBinDir).map { file -> file.asFile.absolutePath } - } - } + // This is conceptually pretty simple as we per documentation always download yarn + val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider, nodeExtension.resolvedPlatform) + val npmDirProvider = variantComputer.computeNpmDir(nodeExtension, nodeDirProvider) + val npmBinDirProvider = variantComputer.computeNpmBinDir(npmDirProvider, nodeExtension.resolvedPlatform) + return zip(nodeBinDirProvider, npmBinDirProvider, yarnBinDirProvider) + .map { (nodeBinDir, npmBinDir, yarnBinDir) -> + listOf(yarnBinDir, npmBinDir, nodeBinDir).map { file -> file.asFile.absolutePath } + } } }