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
15 changes: 15 additions & 0 deletions home-manager/modules/npm-globals/install-npm-globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ if [ -n "$OVERRIDES" ]; then
fi
fi

# Deduplicate overridden packages from nested node_modules
# Bun can install the same package at both top-level and nested locations.
# When packages use Symbols (like pino), two copies create incompatible
# instances. Remove nested copies of any overridden package so everything
# resolves to the single top-level version.
GLOBAL_MODULES="${HOME}/.bun/install/global/node_modules"
for pkg in $(echo "$OVERRIDES" | jq -r 'keys[]' 2>/dev/null); do
find "$GLOBAL_MODULES" -mindepth 3 -maxdepth 4 -type d -name "$pkg" \
-path "*/node_modules/$pkg" \
! -path "$GLOBAL_MODULES/$pkg" 2>/dev/null | while read -r nested; do
rm -r "$nested"
echo "Deduplicated nested $pkg: $nested"
done
done

echo "npm globals installation complete"
10 changes: 10 additions & 0 deletions spec/npm_globals_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,15 @@ It 'runs bun install in global dir after applying overrides'
When run bash -c "grep 'cd.*bun/install/global.*bun install' '$SCRIPT'"
The output should include 'bun install'
End

It 'deduplicates nested copies of overridden packages'
When run bash -c "grep 'Deduplicated nested' '$SCRIPT'"
The output should include 'Deduplicated'
End

It 'finds nested node_modules with find command'
When run bash -c "grep 'find.*GLOBAL_MODULES.*node_modules' '$SCRIPT'"
The output should include 'find'
End
End
End
Loading