-
-
Notifications
You must be signed in to change notification settings - Fork 121
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.