-
Notifications
You must be signed in to change notification settings - Fork 0
fix: skip installed npm globals and prevent nvim lua typechange #1380
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鈥檒l 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,49 @@ if [ -n "$TRUSTED_DEPS" ]; then | |||||
| done | ||||||
| fi | ||||||
|
|
||||||
| # Install global packages in batches (bun hangs when resolving too many at once) | ||||||
| DEPS=$(jq -r '.dependencies | keys[]' "$PACKAGE_JSON" 2>/dev/null || true) | ||||||
| # Build list of packages that need installing or updating | ||||||
| GLOBAL_MODULES="${HOME}/.bun/install/global/node_modules" | ||||||
| DEPS=$(jq -r '.dependencies | to_entries[] | "\(.key)=\(.value)"' "$PACKAGE_JSON" 2>/dev/null || true) | ||||||
| MISSING=() | ||||||
| if [ -n "$DEPS" ]; then | ||||||
| BATCH_SIZE=10 | ||||||
| while IFS= read -r entry; do | ||||||
| dep="${entry%%=*}" | ||||||
| wanted="${entry#*=}" | ||||||
| # Extract minimum version from semver spec (e.g. "^2.1.92" -> "2.1.92") | ||||||
| wanted_ver="${wanted//[^0-9.]/}" | ||||||
| installed_ver="" | ||||||
| pkg_json="${GLOBAL_MODULES}/${dep}/package.json" | ||||||
| if [ -f "$pkg_json" ]; then | ||||||
| installed_ver=$(jq -r '.version // empty' "$pkg_json" 2>/dev/null || true) | ||||||
| fi | ||||||
| if [ -n "$installed_ver" ] && [ -n "$wanted_ver" ] && [ "$installed_ver" = "$wanted_ver" ]; then | ||||||
| echo "$dep@$installed_ver already installed, skipping" | ||||||
| elif [ -n "$installed_ver" ]; then | ||||||
| echo "$dep@$installed_ver installed, want $wanted_ver, updating" | ||||||
| MISSING+=("$dep") | ||||||
|
Comment on lines
+53
to
+64
|
||||||
| else | ||||||
| MISSING+=("$dep") | ||||||
| fi | ||||||
| done <<<"$DEPS" | ||||||
| fi | ||||||
|
|
||||||
| # Install missing packages in small batches | ||||||
| if [ "${#MISSING[@]}" -gt 0 ]; then | ||||||
| echo "Installing ${#MISSING[@]} missing packages..." | ||||||
| BATCH_SIZE=5 | ||||||
| BATCH=() | ||||||
| while IFS= read -r dep; do | ||||||
| for dep in "${MISSING[@]}"; do | ||||||
| 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. Using
Suggested change
|
||||||
| BATCH=() | ||||||
| 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. |
||||||
| fi | ||||||
|
Comment on lines
+47
to
85
|
||||||
| else | ||||||
| echo "All npm global packages already installed" | ||||||
| fi | ||||||
|
|
||||||
| # Apply dependency overrides to the global install | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,6 @@ in | |
|
|
||
| home.file.".config/nvim/lua" = { | ||
| source = ./lua; | ||
| recursive = true; | ||
| force = true; | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,25 +68,69 @@ The output should include 'exit 0' | |
| End | ||
| End | ||
|
|
||
| Describe 'package installation' | ||
| Describe 'trusted dependencies' | ||
| It 'reads trustedDependencies from package.json' | ||
| When run bash -c "grep 'trustedDependencies' '$SCRIPT'" | ||
| The output should include 'trustedDependencies' | ||
| End | ||
|
|
||
| It 'trusts postinstall scripts before installing' | ||
| When run bash -c "grep 'bun pm -g trust' '$SCRIPT'" | ||
| The output should include 'bun pm -g trust' | ||
| End | ||
| End | ||
|
|
||
| Describe 'skip already installed' | ||
| It 'checks global node_modules for installed packages' | ||
| When run bash -c "grep 'GLOBAL_MODULES=' '$SCRIPT' | head -1" | ||
| The output should include '.bun/install/global/node_modules' | ||
| End | ||
|
|
||
| It 'reads installed version from package.json' | ||
| When run bash -c "grep 'installed_ver' '$SCRIPT'" | ||
| The output should include 'installed_ver' | ||
| End | ||
|
|
||
| It 'extracts wanted version from semver spec' | ||
| When run bash -c "grep 'wanted_ver' '$SCRIPT'" | ||
| The output should include 'wanted_ver' | ||
| End | ||
|
|
||
| It 'skips when installed version matches wanted' | ||
| When run bash -c "grep 'already installed, skipping' '$SCRIPT'" | ||
| The output should include 'already installed, skipping' | ||
| End | ||
|
|
||
| It 'detects when update is needed' | ||
| When run bash -c "grep 'updating' '$SCRIPT'" | ||
| The output should include 'updating' | ||
| End | ||
|
|
||
| It 'builds a MISSING array of packages to install' | ||
| When run bash -c "grep 'MISSING' '$SCRIPT'" | ||
| The output should include 'MISSING' | ||
| End | ||
| End | ||
|
|
||
| Describe 'batch installation' | ||
| It 'uses batch size of 5' | ||
| When run bash -c "grep 'BATCH_SIZE=5' '$SCRIPT'" | ||
| The output should include 'BATCH_SIZE=5' | ||
| End | ||
|
|
||
| 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' | ||
| It 'reports batch failures' | ||
| When run bash -c "grep 'Batch install failed' '$SCRIPT'" | ||
| The output should include 'Batch install failed' | ||
| End | ||
|
|
||
| It 'parses dependencies with jq' | ||
| When run bash -c "grep 'dependencies' '$SCRIPT'" | ||
| The output should include 'dependencies' | ||
| It 'reports when all packages are already installed' | ||
| When run bash -c "grep 'All npm global packages already installed' '$SCRIPT'" | ||
| The output should include 'All npm global packages already installed' | ||
| End | ||
|
Comment on lines
+83
to
134
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. These new cases validate strings, not behavior, so skip/update logic is effectively untested. The added specs ( If you want, I can draft a fixture-based ShellSpec block that covers:
馃 Prompt for AI Agents |
||
| End | ||
|
|
||
|
|
||
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.
GLOBAL_MODULESis introduced here but the same variable is redefined later in the script for the override/dedup logic. Consider defining it once near the top (or making it readonly) to avoid accidental divergence if one path is changed later.