Skip to content

Commit

Permalink
Always use downloaded Yarn as per documentation #284
Browse files Browse the repository at this point in the history
  • Loading branch information
deepy committed Aug 17, 2023
1 parent 0b81b10 commit 2b0eda2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ open class VariantComputer {
fun computeYarnBinDir(yarnDirProvider: Provider<Directory>, platform: Property<Platform>) = computeProductBinDir(yarnDirProvider, platform)

fun computeYarnExec(nodeExtension: NodeExtension, yarnBinDirProvider: Provider<Directory>): Provider<String> {
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
}
}

Expand Down
20 changes: 8 additions & 12 deletions src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ abstract class YarnExecRunner {
yarnBinDirProvider: Provider<Directory>,
variantComputer: VariantComputer
): Provider<List<String>> {
return nodeExtension.download.flatMap { download ->
if (!download) {
providers.provider { listOf<String>() }
}
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 }
}
}
}

0 comments on commit 2b0eda2

Please sign in to comment.