node-gradle / node-gradle/gradle-node-plugin
Enabling Yarn 2-4, Yarn and corepack interaction on Windows causes yarn binary not to be found, when it could be
Nobody has claimed this yet.
- Dominant language
- Groovy
- Stars
- 677
- Forks
- 120
- PR merge metrics
- No merged PRs in 30d
Description
Core issue
private fun computeProductBinDir(productDirProvider: Provider<Directory>, platform: Property<Platform>) =
if (platform.get().isWindows()) productDirProvider else productDirProvider.map { it.dir("bin") }
This isn't true. On Windows, corepack also installs yarn.cmd (along with yarn the bash script and yarn.ps1, etc.) to it.dir("bin") too.
This line should be
productDirProvider.map { it.dir("bin") }
related to #176 , this enables Yarn 2-4 and works around the posted issue:
import groovy.json.JsonSlurper
def packageJson = new JsonSlurper().parseText(rootProject.file('package.json').text)
def yarnVersionStr = (packageJson.packageManager as String).split("@")[1]
node {
download = false
yarnVersion = yarnVersionStr
yarnWorkDir.set(rootProject.layout.projectDirectory.dir(".gradle/yarn"))
}
def isWindows = org.gradle.internal.os.OperatingSystem.current().isWindows()
def binExt = isWindows ? ".cmd" : ""
tasks.register("corepack") {
def dirPath = ".gradle/yarn/yarn-v${yarnVersionStr}/${isWindows ? "" : "/bin"}"
outputs.dir(dirPath)
doLast {
mkdir(dirPath)
exec {
commandLine "corepack${binExt}", "enable", "--install-directory", dirPath
}
}
}
tasks.named("yarnSetup").configure {
enabled = false
dependsOn "corepack"
}
// as an alternative to yarn install, which has a lot going on, and also supports workspaces
tasks.register('yarnWorkspace', YarnTask) {
// todo: you don't want to inspect workspaces if you don't use it
description("Installs all the necessary modules to develop ${packageJson.workspaces.join(', ')}")
inputs.files("package.json", "yarn.lock")
.withPropertyName("yarnLock")
.withPathSensitivity(PathSensitivity.RELATIVE)
inputs.files(packageJson.workspaces.collect { "$it/package.json" })
.withPropertyName("workspacePackageJsons")
.withPathSensitivity(PathSensitivity.RELATIVE)
// todo: this only makes sense for node-modules resolution and will need to inspect the .yarnrc.yml file
outputs.file("node_modules/.yarn-state.yml")
outputs.cacheIf { false }
args = ['install', '--immutable']
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the computeProductBinDir function shown in the issue and inspect how its Windows branch chooses the product binary directory. Confirm the directory behavior for Corepack-installed Yarn on Windows; done means the Windows path points to the bin directory where the Yarn binaries are installed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, nodejs
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100