Skip to content

Commit 588aeed

Browse files
AI Assistantclaude
andcommitted
fix(yarn): use corepack/npm instead of apt, prevent cmdtest conflict
Problem: yarn update tried to use apt and installed wrong package - catalog used install_method: "package_manager" with apt: "yarnpkg" - Ubuntu's "yarn" package is actually "cmdtest" (naming conflict!) - Installed cmdtest (Python testing tool) instead of yarn - yarn 1.22.22 (nvm) wasn't updated to 4.10.3 - Wrong approach: should use corepack/npm, not apt Root cause: apt yarn package naming conflict - Debian/Ubuntu: package "yarn" → cmdtest (legacy) - Debian/Ubuntu: package "yarnpkg" → yarn (workaround) - But catalog said "yarnpkg" and apt installed "cmdtest" anyway Solution: Use dedicated installer with corepack/npm Changes: - catalog/yarn.json: Changed to dedicated_script method - scripts/install_yarn.sh: New installer using corepack/npm - Checks if Node.js is nvm-managed (like gem checks rbenv) - Updates via: corepack prepare yarn@stable --activate - Fallback: npm install -g yarn@latest - Removes cmdtest if present (apt conflict cleanup) Expected workflow: 1. Ensure Node.js is nvm-managed (scripts/install_node.sh reconcile) 2. Update yarn via corepack: scripts/install_yarn.sh update 3. Falls back to npm if corepack unavailable Manual cleanup required: sudo apt remove cmdtest python3-cliapp python3-ttystatus python3-zombie-imp Note: Order in guide.sh: - Node.js: order 40 - npm: order 141 - pnpm: order 142 - yarn: order 151 (processes after Node.js/npm) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 91cb449 commit 588aeed

2 files changed

Lines changed: 110 additions & 8 deletions

File tree

catalog/yarn.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "yarn",
3-
"install_method": "package_manager",
3+
"install_method": "dedicated_script",
44
"description": "Alternative Node.js package manager with offline mode and deterministic installs",
55
"homepage": "https://yarnpkg.com/",
66
"binary_name": "yarn",
7-
"packages": {
8-
"apt": "yarnpkg",
9-
"brew": "yarn",
10-
"dnf": "yarnpkg",
11-
"pacman": "yarn"
12-
},
13-
"notes": "Can also be installed via npm: npm install -g yarn. Some distros use 'yarnpkg' package name to avoid conflicts."
7+
"script": "install_yarn.sh",
8+
"notes": "Installed via Node.js corepack or npm. Requires Node.js to be installed via nvm. Do NOT install via apt (conflicts with cmdtest package)."
9+
,"guide": {
10+
"display_name": "Yarn",
11+
"install_action": "update",
12+
"order": 151
13+
}
1414
}

scripts/install_yarn.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
. "$DIR/lib/common.sh"
6+
7+
ACTION="${1:-update}"
8+
9+
check_nvm_node() {
10+
# Check if Node.js is nvm-managed
11+
local node_path
12+
node_path="$(command -v node 2>/dev/null || echo '')"
13+
14+
case "$node_path" in
15+
"$HOME/.nvm/"*)
16+
return 0 # nvm-managed
17+
;;
18+
*)
19+
return 1 # not nvm-managed (apt, system, or missing)
20+
;;
21+
esac
22+
}
23+
24+
update_yarn() {
25+
ensure_nvm_loaded
26+
27+
if ! command -v node >/dev/null 2>&1; then
28+
echo "[yarn] Error: Node.js not found. Install Node.js first via 'make install-node' or 'scripts/install_node.sh'" >&2
29+
return 1
30+
fi
31+
32+
# Check if Node.js is nvm-managed before trying to update yarn
33+
if ! check_nvm_node; then
34+
echo "[yarn] Error: Node.js is not nvm-managed (currently apt/system)" >&2
35+
echo "[yarn] Cannot update yarn for system Node.js" >&2
36+
echo "[yarn] Please install Node.js via nvm first:" >&2
37+
echo "[yarn] make install-node" >&2
38+
echo "[yarn] or: scripts/install_node.sh reconcile" >&2
39+
return 1
40+
fi
41+
42+
local before after path
43+
before="$(yarn --version 2>/dev/null || echo '<none>')"
44+
45+
# Try corepack first (modern approach)
46+
if command -v corepack >/dev/null 2>&1; then
47+
echo "[yarn] Updating yarn via corepack..." >&2
48+
corepack enable || true
49+
corepack prepare yarn@stable --activate || true
50+
else
51+
# Fallback to npm global install
52+
echo "[yarn] Updating yarn via npm..." >&2
53+
npm install -g yarn@latest || true
54+
fi
55+
56+
after="$(yarn --version 2>/dev/null || echo '<none>')"
57+
path="$(command -v yarn 2>/dev/null || echo '<none>')"
58+
59+
printf "[%s] before: %s\n" "yarn" "$before"
60+
printf "[%s] after: %s\n" "yarn" "$after"
61+
printf "[%s] path: %s\n" "yarn" "$path"
62+
}
63+
64+
install_yarn() {
65+
echo "[yarn] yarn should be installed via Node.js corepack/npm. Installing/updating Node.js first..."
66+
"$DIR/install_node.sh" install || true
67+
update_yarn
68+
}
69+
70+
reconcile_yarn() {
71+
ensure_nvm_loaded
72+
73+
if ! command -v node >/dev/null 2>&1; then
74+
echo "[yarn] Node.js not found. Installing Node.js (which includes yarn via corepack)..."
75+
"$DIR/install_node.sh" reconcile || true
76+
elif ! check_nvm_node; then
77+
echo "[yarn] Node.js is not nvm-managed. Installing Node.js via nvm first..."
78+
"$DIR/install_node.sh" reconcile || true
79+
fi
80+
81+
# Remove apt-installed cmdtest if present (Ubuntu's yarn package conflict)
82+
if command -v dpkg >/dev/null 2>&1 && dpkg -l | grep -q "^ii.*cmdtest"; then
83+
echo "[yarn] Removing apt package 'cmdtest' (conflicts with yarn)..." >&2
84+
apt_remove_if_present cmdtest yarnpkg || true
85+
fi
86+
87+
update_yarn
88+
}
89+
90+
uninstall_yarn() {
91+
echo "[yarn] yarn is managed by Node.js/npm. To remove:" >&2
92+
echo "[yarn] npm uninstall -g yarn" >&2
93+
echo "[yarn] or: corepack disable" >&2
94+
}
95+
96+
case "$ACTION" in
97+
install) install_yarn ;;
98+
update) update_yarn ;;
99+
uninstall) uninstall_yarn ;;
100+
reconcile) reconcile_yarn ;;
101+
*) echo "Usage: $0 {install|update|uninstall|reconcile}" ; exit 2 ;;
102+
esac

0 commit comments

Comments
 (0)