Skip to content
Myr

[Fix] `nvm_get_arch`: only apply musl suffix on x64 Alpine

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Alpine detection unconditionally set `x64-musl` regardless of actual architecture, which would be incorrect on ARM-based Alpine containers. Bug introduced in https://github.com/nvm-sh/nvm/commit/ef7fc2f2c06ad75fe7fbabf28d427561ae7b007d / #3212. Fixes #3616.

authored by Jordan Harband · committed by Jordan Harband · parent a5de723 · Browse files · 4 files+62 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+62 added−1 removed

  • tests:+58 added−0 removed
  • other:+4 added−1 removed

4 files+62 added−1 removed

added:test/fast/Unit tests/nvm_get_arch alpine+48 added
1#!/bin/sh23ORIG_PATH="${PATH}"45cleanup() {6 rm -f ./uname7 export PATH="${ORIG_PATH}"8}910die () { cleanup; echo "$@" ; exit 1; }1112: nvm.sh13\. ../../../nvm.sh1415MOCKS_DIR="$(pwd)/../../mocks"16export PATH=".:${PATH}"1718# On Alpine (where /etc/alpine-release exists), x64 should get -musl suffix19# and arm64 should NOT get -musl suffix.20# On non-Alpine, neither should get -musl.2122if [ -f "/etc/alpine-release" ]; then23 # x64 on Alpine should produce x64-musl24 ln -sf "${MOCKS_DIR}/uname_linux_x86_64" ./uname25 OUTPUT="$(nvm_get_arch)"26 rm -f ./uname27 [ "_${OUTPUT}" = "_x64-musl" ] || die "x64 on Alpine should be x64-musl, got ${OUTPUT}"2829 # aarch64 on Alpine should produce arm64, NOT arm64-musl30 ln -sf "${MOCKS_DIR}/uname_linux_aarch64" ./uname31 OUTPUT="$(nvm_get_arch)"32 rm -f ./uname33 [ "_${OUTPUT}" = "_arm64" ] || die "aarch64 on Alpine should be arm64 (no musl suffix), got ${OUTPUT}"34else35 # x64 on non-Alpine should produce x64 (no musl suffix)36 ln -sf "${MOCKS_DIR}/uname_linux_x86_64" ./uname37 OUTPUT="$(nvm_get_arch)"38 rm -f ./uname39 [ "_${OUTPUT}" = "_x64" ] || die "x64 on non-Alpine should be x64, got ${OUTPUT}"4041 # aarch64 on non-Alpine should produce arm6442 ln -sf "${MOCKS_DIR}/uname_linux_aarch64" ./uname43 OUTPUT="$(nvm_get_arch)"44 rm -f ./uname45 [ "_${OUTPUT}" = "_arm64" ] || die "aarch64 on non-Alpine should be arm64, got ${OUTPUT}"46fi4748cleanup
added:test/mocks/uname_linux_aarch64+5 added
1if [ "_$1" = "_-m" ]; then2 echo "aarch64"3else4 echo "Linux hostname 5.15.0-1 #1 SMP aarch64 aarch64 aarch64 GNU/Linux"5fi
added:test/mocks/uname_linux_x86_64+5 added
1if [ "_$1" = "_-m" ]; then2 echo "x86_64"3else4 echo "Linux hostname 5.15.0-1 #1 SMP x86_64 x86_64 x86_64 GNU/Linux"5fi
modified:nvm.sh+4 added-1 removed
2169 unmodified lines
2170 HOST_ARCH=armv7l2171 fi21722173 if [ -f "/etc/alpine-release" ]; then2174 NVM_ARCH=x64-musl2174 # Alpine Linux uses musl libc; only x64-musl binaries are available2175 case "${NVM_ARCH}" in2176 x64) NVM_ARCH=x64-musl ;;2177 esac2178 fi21792180 nvm_echo "${NVM_ARCH}"2181}
2639 unmodified lines