Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
7 changes: 6 additions & 1 deletion src/node/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"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.",
Expand Down Expand Up @@ -36,6 +36,11 @@
],
"default": "latest",
"description": "Version of NVM to install."
},
"yarnFromApt": {
hoechenberger marked this conversation as resolved.
Show resolved Hide resolved
"type": "boolean",
"default": true,
"description": "Whether to install yarn globally via APT on Debian-based systems (Debian, Ubuntu). If false, will set up yarn via corepack. This setting is ignored on other Linux images, where yarn is always installed via corepack."
hoechenberger marked this conversation as resolved.
Show resolved Hide resolved
}
},
"customizations": {
Expand Down
8 changes: 5 additions & 3 deletions src/node/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 YARN_FROM_APT="${YARNFROMAPT:-true}" # only concerns Debian-based systems
hoechenberger marked this conversation as resolved.
Show resolved Hide resolved

# Comma-separated list of node versions to be installed (with nvm)
# alongside NODE_VERSION, but not set as default.
Expand Down Expand Up @@ -188,7 +189,7 @@ find_version_from_git_tags() {
}

install_yarn() {
if [ "${ADJUSTED_ID}" = "debian" ]; then
if [ "${ADJUSTED_ID}" = "debian" ] && [ "${YARN_FROM_APT}" = "true" ]; then
hoechenberger marked this conversation as resolved.
Show resolved Hide resolved
# for backward compatiblity with existing devcontainer features, install yarn
# via apt-get on Debian systems
if ! type yarn >/dev/null 2>&1; then
Expand All @@ -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
Expand Down
Loading