Skip to content

Commit 2223726

Browse files
hadronomyCopilot
andauthored
fix(install): avoid false musl detection on WSL/glibc systems (#823)
Fixes a false `musl` detection in the install script on glibc-based Linux systems, especially WSL environments where musl happens to be installed. The previous logic treated the presence of a musl loader file such as `/lib/ld-musl-x86_64.so.1` as proof that the system was musl-based. On WSL/Ubuntu, that can be a false positive, which causes the installer to request the wrong platform package: `vite-plus-cli-linux-x64-musl-<version>.tgz` instead of: `vite-plus-cli-linux-x64-gnu-<version>.tgz` This then fails during extraction with: ```text gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now ``` ## Minimal reproduction Environment used for reproduction: - WSL - glibc-based distro (Ubuntu) - musl also installed, so `/lib/ld-musl-x86_64.so.1` exists ### 1. Verify the environment is actually glibc-based Run: ```bash ldd --version | head -1 getconf GNU_LIBC_VERSION ``` Expected output is something like: ```text ldd (Ubuntu GLIBC 2.39-0ubuntu8.7) 2.39 Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper. glibc 2.39 ``` This shows the correct target should be `linux-x64-gnu`, not `linux-x64-musl`. ### 2. Run the installer as-is ```bash curl -fsSL https://vite.plus | bash ``` Observed output: ```text Setting up VITE+... gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now ``` At this point the installer does not show which tarball URL failed, because the download path uses a silent `curl` and `tar` only reports the extraction error. ### 3. To see the actual failing package URL, patch the installer locally Save the installer locally, then change the `curl` line inside `download_and_extract()` from: ```bash curl -sL "$url" -o "$temp_file" ``` to: ```bash echo "Downloading: $url" >&2 curl -fsSL "$url" -o "$temp_file" ``` Then run the local copy: ```bash bash install.sh ``` Expected output now shows the real issue: ```text Setting up VITE+... Downloading: https://registry.npmjs.org/@voidzero-dev/vite-plus-cli-linux-x64-musl/-/vite-plus-cli-linux-x64-musl-0.1.11.tgz error: Network error (curl exit code 22) This may be caused by: - Network connectivity issues - Firewall or proxy blocking the connection - DNS configuration problems Failed URL: https://registry.npmjs.org/@voidzero-dev/vite-plus-cli-linux-x64-musl/-/vite-plus-cli-linux-x64-musl-0.1.11.tgz To debug, run: curl -v "https://registry.npmjs.org/@voidzero-dev/vite-plus-cli-linux-x64-musl/-/vite-plus-cli-linux-x64-musl-0.1.11.tgz" ``` This reveals that the installer is incorrectly inferring `linux-x64-musl`, and fails because there's no `musl` package in the registry. ### 4. Expected behavior For the same environment, the installer should resolve the GNU package instead: ```text https://registry.npmjs.org/@voidzero-dev/vite-plus-cli-linux-x64-gnu/-/vite-plus-cli-linux-x64-gnu-0.1.11.tgz ``` --------- Signed-off-by: Pablo Hernández <17086478+hadronomy@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent bc3657f commit 2223726

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

packages/cli/install.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,40 @@ curl_with_error_handling() {
141141

142142
# Detect libc type on Linux (gnu or musl)
143143
detect_libc() {
144-
# Check for musl dynamic linker (most reliable method)
145-
if [ -e /lib/ld-musl-x86_64.so.1 ] || [ -e /lib/ld-musl-aarch64.so.1 ]; then
146-
echo "musl"
147-
return
144+
# Prefer positive glibc detection first.
145+
# This avoids false musl detection on systems where musl is installed
146+
# but the distro itself is glibc-based (common on WSL/Ubuntu).
147+
if command -v getconf &> /dev/null; then
148+
if getconf GNU_LIBC_VERSION > /dev/null 2>&1; then
149+
echo "gnu"
150+
return
151+
fi
148152
fi
149153

150-
# Check if ldd exists and is musl-based
154+
# Check ldd output for musl/glibc
151155
if command -v ldd &> /dev/null; then
152-
if ldd --version 2>&1 | grep -qi musl; then
156+
ldd_out="$(ldd --version 2>&1 || true)"
157+
if echo "$ldd_out" | grep -qi musl; then
153158
echo "musl"
154159
return
155160
fi
161+
if echo "$ldd_out" | grep -qi 'gnu libc'; then
162+
echo "gnu"
163+
return
164+
fi
165+
if echo "$ldd_out" | grep -qi 'glibc'; then
166+
echo "gnu"
167+
return
168+
fi
156169
fi
157170

158-
# Default to gnu (glibc)
159-
echo "gnu"
171+
# Final fallback: musl loader present usually indicates musl-based distro,
172+
# but only check this after glibc detection to avoid false positives.
173+
if [ -e /lib/ld-musl-x86_64.so.1 ] || [ -e /lib/ld-musl-aarch64.so.1 ]; then
174+
echo "musl"
175+
else
176+
echo "gnu"
177+
fi
160178
}
161179

162180
# Detect platform

0 commit comments

Comments
 (0)