-
Notifications
You must be signed in to change notification settings - Fork 0
fix: skip already-installed npm globals to prevent bun hang #1379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,21 +42,37 @@ if [ -n "$TRUSTED_DEPS" ]; then | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Install global packages in batches (bun hangs when resolving too many at once) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build list of packages that are not yet installed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GLOBAL_MODULES="${HOME}/.bun/install/global/node_modules" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DEPS=$(jq -r '.dependencies | keys[]' "$PACKAGE_JSON" 2>/dev/null || true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
47
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MISSING=() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$DEPS" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BATCH_SIZE=10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BATCH=() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while IFS= read -r dep; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ ! -d "${GLOBAL_MODULES}/${dep}" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking only for the existence of the directory will cause the script to skip version updates. If a package version is updated in |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MISSING+=("$dep") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$dep already installed, skipping" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done <<< "$DEPS" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
47
to
+56
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
PACKAGE_JSON="$HOME/dotfiles/package.json"
GLOBAL_PKG="$HOME/.bun/install/global/package.json"
if [[ ! -f "$PACKAGE_JSON" || ! -f "$GLOBAL_PKG" ]]; then
echo "Missing $PACKAGE_JSON or $GLOBAL_PKG; cannot compare desired vs installed specs."
exit 0
fi
jq -n --argfile desired "$PACKAGE_JSON" --argfile global "$GLOBAL_PKG" '
($desired.dependencies // {}) as $d |
($global.dependencies // {}) as $g |
[$d | to_entries[] |
select(($g[.key] // "") != .value) |
{package: .key, desired: .value, installed: ($g[.key] // "<missing>")}
]
'Repository: shunkakinoki/dotfiles Length of output: 204 🏁 Script executed: find . -type f -name "install-npm-globals.sh" | head -20Repository: shunkakinoki/dotfiles Length of output: 122 🏁 Script executed: fd -t f "install-npm-globals.sh"Repository: shunkakinoki/dotfiles Length of output: 120 🏁 Script executed: git ls-files | grep -E "(npm-globals|package\.json)" | head -20Repository: shunkakinoki/dotfiles Length of output: 178 🏁 Script executed: cat -n ./home-manager/modules/npm-globals/install-npm-globals.shRepository: shunkakinoki/dotfiles Length of output: 4393 🏁 Script executed: cat -n ./package.jsonRepository: shunkakinoki/dotfiles Length of output: 4404 🏁 Script executed: cat -n ./home-manager/modules/npm-globals/default.nixRepository: shunkakinoki/dotfiles Length of output: 1850 🌐 Web query:
💡 Result: Bun supports global package installation via bun install -g or bun add -g . Global packages are stored in ~/.bun/install/global, which acts like a project directory with its own package.json and bun.lockb. Binaries are symlinked to ~/.bun/bin, which must be in your PATH (add export PATH="$HOME/.bun/bin:$PATH" to ~/.zshrc or equivalent if needed). Unlike npm's npm update -g, Bun initially did not fully support bun update -g—it often failed to update all packages or crashed (e.g., issues in 2025 like Citations:
Directory-only install check misses required version/range changes. At line 51, the script checks only whether To fix this, compare the desired version spec in Suggested fix GLOBAL_MODULES="${HOME}/.bun/install/global/node_modules"
+GLOBAL_PKG="${HOME}/.bun/install/global/package.json"
DEPS=$(jq -r '.dependencies | keys[]' "$PACKAGE_JSON" 2>/dev/null || true)
MISSING=()
if [ -n "$DEPS" ]; then
while IFS= read -r dep; do
- if [ ! -d "${GLOBAL_MODULES}/${dep}" ]; then
- MISSING+=("$dep")
+ desired=$(jq -r --arg dep "$dep" '.dependencies[$dep] // empty' "$PACKAGE_JSON")
+ installed=$(jq -r --arg dep "$dep" '.dependencies[$dep] // empty' "$GLOBAL_PKG" 2>/dev/null || true)
+ if [ ! -d "${GLOBAL_MODULES}/${dep}" ] || [ "$installed" != "$desired" ]; then
+ MISSING+=("$dep")
else
echo "$dep already installed, skipping"
fi
done <<< "$DEPS"
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Install missing packages in small batches with a timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ "${#MISSING[@]}" -gt 0 ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Installing ${#MISSING[@]} missing packages..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BATCH_SIZE=5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BATCH=() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for dep in "${MISSING[@]}"; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+64
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BATCH+=("$dep") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ "${#BATCH[@]}" -ge "$BATCH_SIZE" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bun add --global "${BATCH[@]}" 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bun add --global "${BATCH[@]}" 2>/dev/null || echo "Batch install failed: ${BATCH[*]}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suppressing
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BATCH=() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+59
to
68
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done <<< "$DEPS" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ "${#BATCH[@]}" -gt 0 ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bun add --global "${BATCH[@]}" 2>/dev/null || true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bun add --global "${BATCH[@]}" 2>/dev/null || echo "Batch install failed: ${BATCH[*]}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the batch installation above, suppressing
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
73
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "All npm global packages already installed" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Apply dependency overrides to the global install | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
GLOBAL_MODULESpath is hardcoded to$HOME/.bun. It is better to respect theBUN_INSTALLenvironment variable if it is set, as this variable is explicitly configured in the Nix module and ensures consistency across different environments.References