Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions home-manager/modules/npm-globals/install-npm-globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ if [ -n "$TRUSTED_DEPS" ]; then
done
fi

# Install global packages
# Install global packages in batches (bun hangs when resolving too many at once)
DEPS=$(jq -r '.dependencies | keys[]' "$PACKAGE_JSON" 2>/dev/null || true)
if [ -n "$DEPS" ]; then
# shellcheck disable=SC2086
bun install --global $DEPS 2>/dev/null || true
BATCH_SIZE=10
BATCH=()
while IFS= read -r dep; do
BATCH+=("$dep")
if [ "${#BATCH[@]}" -ge "$BATCH_SIZE" ]; then
bun add --global "${BATCH[@]}" 2>/dev/null || true
BATCH=()
fi
done <<< "$DEPS"
if [ "${#BATCH[@]}" -gt 0 ]; then
bun add --global "${BATCH[@]}" 2>/dev/null || true
fi
fi

# Apply dependency overrides to the global install
Expand Down
11 changes: 8 additions & 3 deletions spec/npm_globals_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@ When run bash -c "grep 'trustedDependencies' '$SCRIPT'"
The output should include 'trustedDependencies'
End

It 'uses bun install --global'
When run bash -c "grep 'bun install --global' '$SCRIPT'"
The output should include 'bun install --global'
It 'uses bun add --global in batches'
When run bash -c "grep 'bun add --global' '$SCRIPT'"
The output should include 'bun add --global'
End

It 'batches packages to avoid bun resolution hangs'
When run bash -c "grep 'BATCH_SIZE' '$SCRIPT'"
The output should include 'BATCH_SIZE'
End

It 'parses dependencies with jq'
Expand Down
Loading