Skip to content

Commit 00c6ebe

Browse files
committed
fix: sync installer cleanup from core
1 parent 85565f2 commit 00c6ebe

4 files changed

Lines changed: 29 additions & 1073 deletions

File tree

.github/workflows/install-smoke.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ jobs:
6565
- name: Checkout
6666
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
6767

68-
- name: Unit tests (install.sh)
69-
run: bash scripts/test-install-sh-unit.sh
68+
- name: Installer syntax
69+
run: bash -n public/install.sh public/install-cli.sh
7070

71-
- name: Unit tests (install-cli.sh)
72-
run: bash scripts/test-install-cli-unit.sh
71+
- name: Installer help
72+
run: |
73+
bash public/install.sh --help >/tmp/install-help.txt
74+
bash public/install-cli.sh --help >/tmp/install-cli-help.txt
7375
7476
install-smoke:
7577
runs-on: ubuntu-latest

public/install.sh

Lines changed: 23 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
13521369
promote_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+
13911412
print_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-
15581506
load_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

Comments
 (0)