From 0ff92724c4d223e96daff88edcc5d696455c7322 Mon Sep 17 00:00:00 2001 From: Rahul Beniwal Date: Sun, 16 Nov 2025 14:48:10 +0530 Subject: [PATCH] updated nvm.sh to use darwin-x64 for all binary on mac where node version < 16.0.0 --- nvm.sh | 13 ++++-------- test/fast/Unit tests/nvm_get_download_slug | 23 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/nvm.sh b/nvm.sh index 01013b822f..415be3676c 100755 --- a/nvm.sh +++ b/nvm.sh @@ -2360,15 +2360,10 @@ nvm_get_download_slug() { fi fi - # If running MAC M1 :: Node v14.17.0 was the first version to offer official experimental support: - # https://github.com/nodejs/node/issues/40126 (although binary distributions aren't available until v16) - if \ - nvm_version_greater '14.17.0' "${VERSION}" \ - || (nvm_version_greater_than_or_equal_to "${VERSION}" '15.0.0' && nvm_version_greater '16.0.0' "${VERSION}") \ - ; then - if [ "_${NVM_OS}" = '_darwin' ] && [ "${NVM_ARCH}" = 'arm64' ]; then - NVM_ARCH=x64 - fi + # If running MAC M1 :: ARM64 binaries are not available for Node < 16.0.0 + # https://github.com/nodejs/node/issues/40126 (binary distributions aren't available until v16) + if nvm_version_greater '16.0.0' "${VERSION}" && [ "_${NVM_OS}" = '_darwin' ] && [ "${NVM_ARCH}" = 'arm64' ]; then + NVM_ARCH=x64 fi if [ "${KIND}" = 'binary' ]; then diff --git a/test/fast/Unit tests/nvm_get_download_slug b/test/fast/Unit tests/nvm_get_download_slug index a4a0bc4cf1..0b4b364c8d 100755 --- a/test/fast/Unit tests/nvm_get_download_slug +++ b/test/fast/Unit tests/nvm_get_download_slug @@ -109,3 +109,26 @@ ACTUAL="$(nvm_get_download_slug iojs source 15.99.99)" EXPECTED="iojs-15.99.99" [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" + +REAL_OS="$(command uname -s 2>/dev/null || echo '')" +REAL_ARCH="$(command uname -m 2>/dev/null || echo '')" +if [ "${REAL_OS}" = "Darwin" ] && [ "${REAL_ARCH}" = "arm64" ]; then + # Node < 16 uses x64 on darwin-arm64 + ACTUAL="$(nvm_get_download_slug node binary 14.21.3)" + EXPECTED='node-14.21.3-darwin-x64' + [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" + ACTUAL="$(nvm_get_download_slug node binary 15.99.99)" + EXPECTED='node-15.99.99-darwin-x64' + [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" + ACTUAL="$(nvm_get_download_slug iojs binary 15.99.99)" + EXPECTED='iojs-15.99.99-darwin-x64' + [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" + + # Test Node >= 16 uses arm64 on darwin-arm64 + ACTUAL="$(nvm_get_download_slug node binary 16.0.0)" + EXPECTED='node-16.0.0-darwin-arm64' + [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" + ACTUAL="$(nvm_get_download_slug node binary 18.0.0)" + EXPECTED='node-18.0.0-darwin-arm64' + [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" +fi