@@ -1275,12 +1275,13 @@ install_homebrew() {
12751275}
12761276
12771277# Check Node.js version
1278- parse_node_version_components () {
1279- if ! command -v node & > /dev/null; then
1278+ parse_node_version_components_for_binary () {
1279+ local node_bin=" ${1:- node} "
1280+ if ! command -v " $node_bin " & > /dev/null && [[ ! -x " $node_bin " ]]; then
12801281 return 1
12811282 fi
12821283 local version major minor
1283- version=" $( node -v 2> /dev/null || true) "
1284+ version=" $( " $node_bin " -v 2> /dev/null || true) "
12841285 major=" ${version# v} "
12851286 major=" ${major%% .* } "
12861287 minor=" ${version# v} "
@@ -1297,6 +1298,13 @@ parse_node_version_components() {
12971298 return 0
12981299}
12991300
1301+ parse_node_version_components () {
1302+ if ! command -v node & > /dev/null; then
1303+ return 1
1304+ fi
1305+ parse_node_version_components_for_binary node
1306+ }
1307+
13001308node_major_version () {
13011309 local version_components major minor
13021310 version_components=" $( parse_node_version_components || true) "
@@ -1324,6 +1332,83 @@ node_is_at_least_required() {
13241332 return 1
13251333}
13261334
1335+ node_binary_is_at_least_required () {
1336+ local node_bin=" $1 "
1337+ local version_components major minor
1338+ version_components=" $( parse_node_version_components_for_binary " $node_bin " || true) "
1339+ read -r major minor <<< " $version_components"
1340+ if [[ ! " $major " =~ ^[0-9]+$ || ! " $minor " =~ ^[0-9]+$ ]]; then
1341+ return 1
1342+ fi
1343+ if [[ " $major " -gt " $NODE_MIN_MAJOR " ]]; then
1344+ return 0
1345+ fi
1346+ if [[ " $major " -eq " $NODE_MIN_MAJOR " && " $minor " -ge " $NODE_MIN_MINOR " ]]; then
1347+ return 0
1348+ fi
1349+ return 1
1350+ }
1351+
1352+ prepend_path_dir () {
1353+ local dir=" ${1%/ } "
1354+ if [[ -z " $dir " || ! -d " $dir " ]]; then
1355+ return 1
1356+ fi
1357+ local current=" :${PATH:- } :"
1358+ current=" ${current//: ${dir} :/: } "
1359+ current=" ${current#: } "
1360+ current=" ${current%: } "
1361+ if [[ -n " $current " ]]; then
1362+ export PATH=" ${dir} :${current} "
1363+ else
1364+ export PATH=" ${dir} "
1365+ fi
1366+ refresh_shell_command_cache
1367+ }
1368+
1369+ promote_supported_node_binary () {
1370+ local candidates=()
1371+ local candidate dir seen_dirs=" :"
1372+
1373+ while IFS= read -r candidate; do
1374+ candidates+=(" $candidate " )
1375+ done < <( type -P -a node 2> /dev/null || true)
1376+
1377+ candidates+=(
1378+ " /usr/bin/node"
1379+ " /usr/local/bin/node"
1380+ " /opt/homebrew/bin/node"
1381+ " /opt/homebrew/opt/node@${NODE_DEFAULT_MAJOR} /bin/node"
1382+ " /usr/local/opt/node@${NODE_DEFAULT_MAJOR} /bin/node"
1383+ )
1384+
1385+ for candidate in " ${candidates[@]} " ; do
1386+ if [[ -z " $candidate " || ! -x " $candidate " ]]; then
1387+ continue
1388+ fi
1389+ if dir=" $( cd " $( dirname " $candidate " ) " && pwd 2> /dev/null) " ; then
1390+ :
1391+ else
1392+ dir=" "
1393+ fi
1394+ if [[ -z " $dir " || " $seen_dirs " == * " :$dir :" * ]]; then
1395+ continue
1396+ fi
1397+ seen_dirs=" ${seen_dirs}${dir} :"
1398+ if node_binary_is_at_least_required " $candidate " ; then
1399+ prepend_path_dir " $dir " || continue
1400+ ui_info " Using Node.js runtime at ${candidate} "
1401+ return 0
1402+ fi
1403+ done
1404+
1405+ return 1
1406+ }
1407+
1408+ activate_supported_node_on_path () {
1409+ promote_supported_node_binary " $@ "
1410+ }
1411+
13271412print_active_node_paths () {
13281413 if ! command -v node & > /dev/null; then
13291414 return 1
@@ -1383,6 +1468,7 @@ ensure_macos_node22_active() {
13831468}
13841469
13851470ensure_default_node_active_shell () {
1471+ promote_supported_node_binary || true
13861472 if node_is_at_least_required; then
13871473 return 0
13881474 fi
@@ -1417,79 +1503,6 @@ ensure_default_node_active_shell() {
14171503 return 1
14181504}
14191505
1420- node_binary_is_at_least_required () {
1421- local node_bin=" $1 "
1422- local major minor
1423- if [[ -z " $node_bin " || ! -x " $node_bin " ]]; then
1424- return 1
1425- fi
1426- read -r major minor < <( " $node_bin " -p ' `${process.versions.node.split(".")[0]} ${process.versions.node.split(".")[1]}`' 2> /dev/null || true)
1427- if [[ ! " $major " =~ ^[0-9]+$ || ! " $minor " =~ ^[0-9]+$ ]]; then
1428- return 1
1429- fi
1430- if [[ " $major " -gt " $NODE_MIN_MAJOR " ]]; then
1431- return 0
1432- fi
1433- if [[ " $major " -eq " $NODE_MIN_MAJOR " && " $minor " -ge " $NODE_MIN_MINOR " ]]; then
1434- return 0
1435- fi
1436- return 1
1437- }
1438-
1439- prepend_path_dir () {
1440- local dir=" ${1%/ } "
1441- if [[ -z " $dir " || ! -d " $dir " ]]; then
1442- return 1
1443- fi
1444- local current=" :${PATH:- } :"
1445- current=" ${current//: ${dir} :/: } "
1446- current=" ${current#: } "
1447- current=" ${current%: } "
1448- if [[ -n " $current " ]]; then
1449- export PATH=" ${dir} :${current} "
1450- else
1451- export PATH=" ${dir} "
1452- fi
1453- refresh_shell_command_cache
1454- }
1455-
1456- activate_supported_node_on_path () {
1457- if node_is_at_least_required; then
1458- return 0
1459- fi
1460-
1461- local -a candidates=()
1462- local candidate=" "
1463- while IFS= read -r candidate; do
1464- [[ -n " $candidate " ]] && candidates+=(" $candidate " )
1465- done < <( type -aP node 2> /dev/null || true)
1466- candidates+=(
1467- " /usr/bin/node"
1468- " /usr/local/bin/node"
1469- " /opt/homebrew/bin/node"
1470- " /opt/homebrew/opt/node@${NODE_DEFAULT_MAJOR} /bin/node"
1471- " /usr/local/opt/node@${NODE_DEFAULT_MAJOR} /bin/node"
1472- )
1473-
1474- local seen=" :"
1475- for candidate in " ${candidates[@]} " ; do
1476- if [[ -z " $candidate " || ! -x " $candidate " ]]; then
1477- continue
1478- fi
1479- case " $seen " in
1480- * " :$candidate :" * ) continue ;;
1481- esac
1482- seen=" ${seen}${candidate} :"
1483- if node_binary_is_at_least_required " $candidate " ; then
1484- prepend_path_dir " $( dirname " $candidate " ) " || continue
1485- ui_info " Using Node.js runtime at ${candidate} "
1486- return 0
1487- fi
1488- done
1489-
1490- return 1
1491- }
1492-
14931506load_nvm_for_node_detection () {
14941507 local nvm_dir=" ${NVM_DIR:- } "
14951508 if [[ -n " $nvm_dir " && ! -s " $nvm_dir /nvm.sh" ]]; then
@@ -1503,7 +1516,7 @@ load_nvm_for_node_detection() {
15031516 fi
15041517
15051518 export NVM_DIR=" $nvm_dir "
1506- # shellcheck disable=SC1090
1519+ # shellcheck disable=SC1090,SC1091
15071520 . " $NVM_DIR /nvm.sh" --no-use > /dev/null 2>&1 || . " $NVM_DIR /nvm.sh" > /dev/null 2>&1 || true
15081521 if command -v nvm > /dev/null 2>&1 ; then
15091522 nvm use default --silent > /dev/null 2>&1 || nvm use node --silent > /dev/null 2>&1 || true
@@ -1564,6 +1577,7 @@ install_node() {
15641577 else
15651578 run_quiet_step " Installing Node.js" sudo pacman -Sy --noconfirm nodejs npm
15661579 fi
1580+ promote_supported_node_binary || true
15671581 ui_success " Node.js v${NODE_DEFAULT_MAJOR} installed"
15681582 print_active_node_paths || true
15691583 return 0
@@ -1609,6 +1623,7 @@ install_node() {
16091623 exit 1
16101624 fi
16111625
1626+ promote_supported_node_binary || true
16121627 ui_success " Node.js v${NODE_DEFAULT_MAJOR} installed"
16131628 print_active_node_paths || true
16141629 fi
@@ -2439,10 +2454,15 @@ load_install_version_helpers() {
24392454 if [[ -z " $source_path " || ! -f " $source_path " ]]; then
24402455 return 0
24412456 fi
2442- script_dir=" $( cd " $( dirname " $source_path " ) " && pwd 2> /dev/null || true) "
2457+ if script_dir=" $( cd " $( dirname " $source_path " ) " && pwd 2> /dev/null) " ; then
2458+ :
2459+ else
2460+ script_dir=" "
2461+ fi
24432462 helper_path=" ${script_dir} /docker/install-sh-common/version-parse.sh"
24442463 if [[ -n " $script_dir " && -r " $helper_path " ]]; then
24452464 # shellcheck source=docker/install-sh-common/version-parse.sh
2465+ # shellcheck disable=SC1091
24462466 source " $helper_path "
24472467 fi
24482468}
@@ -2650,7 +2670,6 @@ main() {
26502670 if ! check_node; then
26512671 install_node
26522672 fi
2653- activate_supported_node_on_path || true
26542673 if ! ensure_default_node_active_shell; then
26552674 exit 1
26562675 fi
0 commit comments