Unverified Commit 62f7f7f4 authored by Richard Höchenberger's avatar Richard Höchenberger Committed by GitHub

Allow installing `yarn` via `corepack` on Debian-based systems, too (#1009)

* Allow installing `yarn` via `corepack` on Debian-based systems, too

The default behavior remains unchanged, but users can now opt-out from the APT-based installation to get the latest `yarn` via `corepack`.

Closes #1004

* Update src/node/devcontainer-feature.json
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>

* Update src/node/devcontainer-feature.json
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>

* Rename variable

* Expand comment

* Add test scenario

* Improve tests

* Update test/node/debian_yarn_from_corepack.sh

* Betetr comments

* Update src/node/devcontainer-feature.json

---------
Co-authored-by: 's avatarSamruddhi Khandale <samruddhikhandale@github.com>
parent 7953318c
{
"id": "node",
"version": "1.4.1",
"version": "1.5.0",
"name": "Node.js (via nvm), yarn and pnpm",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/node",
"description": "Installs Node.js, nvm, yarn, pnpm, and needed dependencies.",
......@@ -36,6 +36,11 @@
],
"default": "latest",
"description": "Version of NVM to install."
},
"installYarnUsingApt": {
"type": "boolean",
"default": true,
"description": "On Debian and Ubuntu systems, you have the option to install Yarn globally via APT. If you choose not to use this option, Yarn will be set up using Corepack instead. This choice is specific to Debian and Ubuntu; for other Linux distributions, Yarn is always installed using Corepack, with a fallback to installation via NPM if an error occurs."
}
},
"customizations": {
......
......@@ -11,6 +11,7 @@ export NODE_VERSION="${VERSION:-"lts"}"
export NVM_VERSION="${NVMVERSION:-"latest"}"
export NVM_DIR="${NVMINSTALLPATH:-"/usr/local/share/nvm"}"
INSTALL_TOOLS_FOR_NODE_GYP="${NODEGYPDEPENDENCIES:-true}"
export INSTALL_YARN_USING_APT="${INSTALLYARNUSINGAPT:-true}" # only concerns Debian-based systems
# Comma-separated list of node versions to be installed (with nvm)
# alongside NODE_VERSION, but not set as default.
......@@ -188,7 +189,7 @@ find_version_from_git_tags() {
}
install_yarn() {
if [ "${ADJUSTED_ID}" = "debian" ]; then
if [ "${ADJUSTED_ID}" = "debian" ] && [ "${INSTALL_YARN_USING_APT}" = "true" ]; then
# for backward compatiblity with existing devcontainer features, install yarn
# via apt-get on Debian systems
if ! type yarn >/dev/null 2>&1; then
......@@ -202,8 +203,9 @@ install_yarn() {
fi
else
local _ver=${1:-node}
# on non-debian systems, prefer corepack, fallback to npm based installation of yarn...
# Try to leverage corepack if possible
# on non-debian systems or if user opted not to use APT, prefer corepack
# Fallback to npm based installation of yarn.
# But try to leverage corepack if possible
# From https://yarnpkg.com:
# The preferred way to manage Yarn is by-project and through Corepack, a tool
# shipped by default with Node.js. Modern releases of Yarn aren't meant to be
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
YARN_VERSION="4.3.0"
# Corepack provides shims for package managers like yarn. The first time yarn is invoked via the "yarn"
# command, corepack will interactively request permission to download the yarn binary. To
# avoid this interactive mode and download the binary automatically, we explicitly call "corepack use yarn"
# instead (doesn't require user input). Once that command completes, "yarn" can be used in a non-interactive mode.
check "yarn shim location" bash -c ". /usr/local/share/nvm/nvm.sh && type yarn &> /dev/null"
check "download yarn" bash -c ". /usr/local/share/nvm/nvm.sh && corepack use yarn@${YARN_VERSION}"
check "yarn version" bash -c ". /usr/local/share/nvm/nvm.sh && yarn --version | grep ${YARN_VERSION}"
# Report result
reportResults
......@@ -185,5 +185,13 @@
"version": "lts"
}
}
},
"debian_yarn_from_corepack": {
"image": "debian:11",
"features": {
"node": {
"installYarnUsingApt": false
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment