@@ -1349,6 +1349,23 @@ node_binary_is_at_least_required() {
13491349 return 1
13501350}
13511351
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+
13521369promote_supported_node_binary () {
13531370 local candidates=()
13541371 local candidate dir seen_dirs=" :"
@@ -1379,15 +1396,19 @@ promote_supported_node_binary() {
13791396 fi
13801397 seen_dirs=" ${seen_dirs}${dir} :"
13811398 if node_binary_is_at_least_required " $candidate " ; then
1382- export PATH= " $dir : $PATH "
1383- refresh_shell_command_cache
1399+ prepend_path_dir " $dir " || continue
1400+ ui_info " Using Node.js runtime at ${candidate} "
13841401 return 0
13851402 fi
13861403 done
13871404
13881405 return 1
13891406}
13901407
1408+ activate_supported_node_on_path () {
1409+ promote_supported_node_binary " $@ "
1410+ }
1411+
13911412print_active_node_paths () {
13921413 if ! command -v node & > /dev/null; then
13931414 return 1
@@ -1482,79 +1503,6 @@ ensure_default_node_active_shell() {
14821503 return 1
14831504}
14841505
1485- node_binary_is_at_least_required () {
1486- local node_bin=" $1 "
1487- local major minor
1488- if [[ -z " $node_bin " || ! -x " $node_bin " ]]; then
1489- return 1
1490- fi
1491- read -r major minor < <( " $node_bin " -p ' `${process.versions.node.split(".")[0]} ${process.versions.node.split(".")[1]}`' 2> /dev/null || true)
1492- if [[ ! " $major " =~ ^[0-9]+$ || ! " $minor " =~ ^[0-9]+$ ]]; then
1493- return 1
1494- fi
1495- if [[ " $major " -gt " $NODE_MIN_MAJOR " ]]; then
1496- return 0
1497- fi
1498- if [[ " $major " -eq " $NODE_MIN_MAJOR " && " $minor " -ge " $NODE_MIN_MINOR " ]]; then
1499- return 0
1500- fi
1501- return 1
1502- }
1503-
1504- prepend_path_dir () {
1505- local dir=" ${1%/ } "
1506- if [[ -z " $dir " || ! -d " $dir " ]]; then
1507- return 1
1508- fi
1509- local current=" :${PATH:- } :"
1510- current=" ${current//: ${dir} :/: } "
1511- current=" ${current#: } "
1512- current=" ${current%: } "
1513- if [[ -n " $current " ]]; then
1514- export PATH=" ${dir} :${current} "
1515- else
1516- export PATH=" ${dir} "
1517- fi
1518- refresh_shell_command_cache
1519- }
1520-
1521- activate_supported_node_on_path () {
1522- if node_is_at_least_required; then
1523- return 0
1524- fi
1525-
1526- local -a candidates=()
1527- local candidate=" "
1528- while IFS= read -r candidate; do
1529- [[ -n " $candidate " ]] && candidates+=(" $candidate " )
1530- done < <( type -aP node 2> /dev/null || true)
1531- candidates+=(
1532- " /usr/bin/node"
1533- " /usr/local/bin/node"
1534- " /opt/homebrew/bin/node"
1535- " /opt/homebrew/opt/node@${NODE_DEFAULT_MAJOR} /bin/node"
1536- " /usr/local/opt/node@${NODE_DEFAULT_MAJOR} /bin/node"
1537- )
1538-
1539- local seen=" :"
1540- for candidate in " ${candidates[@]} " ; do
1541- if [[ -z " $candidate " || ! -x " $candidate " ]]; then
1542- continue
1543- fi
1544- case " $seen " in
1545- * " :$candidate :" * ) continue ;;
1546- esac
1547- seen=" ${seen}${candidate} :"
1548- if node_binary_is_at_least_required " $candidate " ; then
1549- prepend_path_dir " $( dirname " $candidate " ) " || continue
1550- ui_info " Using Node.js runtime at ${candidate} "
1551- return 0
1552- fi
1553- done
1554-
1555- return 1
1556- }
1557-
15581506load_nvm_for_node_detection () {
15591507 local nvm_dir=" ${NVM_DIR:- } "
15601508 if [[ -n " $nvm_dir " && ! -s " $nvm_dir /nvm.sh" ]]; then
@@ -2717,7 +2665,6 @@ main() {
27172665 if ! check_node; then
27182666 install_node
27192667 fi
2720- activate_supported_node_on_path || true
27212668 if ! ensure_default_node_active_shell; then
27222669 exit 1
27232670 fi
0 commit comments