node-gradle / node-gradle/gradle-node-plugin
Allow use of corepack to provision yarn, etc.
Nobody has claimed this yet.
- Dominant language
- Groovy
- Stars
- 677
- Forks
- 120
- PR merge metrics
- No merged PRs in 30d
Description
Nowadays the proper way to provision package managers is corepack as the package manager version is codified in the package.json. Some package managers even refuse to launch when another is set up, especially if they are set up by corepack themselves: This project is configured to use yarn because package.json has a "packageManager" field
You can work around it currently by just setting it up like the following, but it's a bit clunky;
val isWindows = providers.systemProperty("os.name").map { it.contains("windows", true) }
node {
yarnCommand = layout.buildDirectory.dir("corepack").flatMap { dir ->
isWindows.map {
if (it) {
dir.file("yarn.CMD")
} else {
dir.file("yarn")
}.toString()
}
}
}
val corepackSetup = tasks.register<NpxTask>("corepackSetup") {
command = "corepack@latest"
val corepackInstallDir = layout.buildDirectory.dir("corepack")
args.set(corepackInstallDir.map { listOf("enable", "--install-directory", it.asFile.absolutePath) })
outputs.dir(corepackInstallDir)
}
tasks.yarnSetup {
dependsOn(corepackSetup)
enabled = false
}
corepack is just shipped by default with current node versions and for older ones and for older version npx should just download it.
This help to properly use the correct package manager version and in general works a lot simpler than any other setup. COREPACK_HOME can be set to control where it downloads the package managers to as well, if needed. The version can of course also be set using npx or it could probably be manually downloaded like yarn or npm currently are.
Alternatively the plugin could try to parse the packageManager field itself, but not sure if that makes a lot of sense.
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 by reviewing the node configuration shown in the issue, the NpxTask usage, and the yarnSetup task that it disables. Define how Corepack provisioning should interact with packageManager settings and existing package-manager setup, then verify that the selected package manager can be provisioned and used through the Gradle plugin.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 40/100