Fix yargs --version implementation printing "unknown" for built .exe's

This commit is contained in:
Dillon DuPont
2025-11-18 09:03:22 -05:00
parent 5fa73fb0b1
commit fb55b42920
3 changed files with 59 additions and 2 deletions

View File

@@ -32,11 +32,29 @@ function Install-WithBun {
try {
bun add -g @trycua/cli
# Determine installed version from npm registry
try {
$bunVersion = (npm view @trycua/cli version) 2>$null
if (-not $bunVersion) { $bunVersion = "unknown" }
} catch { $bunVersion = "unknown" }
# Ensure install dir and write version file
$installDir = "$env:USERPROFILE\.cua\bin"
if (-not (Test-Path $installDir)) { New-Item -ItemType Directory -Path $installDir -Force | Out-Null }
Set-Content -Path (Join-Path $installDir ".version") -Value $bunVersion -NoNewline
return $true
} catch {
Write-Host "Warning: Failed to install with Bun, trying npm..." -ForegroundColor Yellow
try {
npm install -g @trycua/cli
# Determine installed version from npm registry
try {
$npmVersion = (npm view @trycua/cli version) 2>$null
if (-not $npmVersion) { $npmVersion = "unknown" }
} catch { $npmVersion = "unknown" }
# Ensure install dir and write version file
$installDir = "$env:USERPROFILE\.cua\bin"
if (-not (Test-Path $installDir)) { New-Item -ItemType Directory -Path $installDir -Force | Out-Null }
Set-Content -Path (Join-Path $installDir ".version") -Value $npmVersion -NoNewline
return $true
} catch {
Write-Host "Error: Installation failed with npm as well." -ForegroundColor Red
@@ -106,6 +124,13 @@ try {
}
}
# Write version file for binary install
try {
Set-Content -Path (Join-Path $installDir ".version") -Value $version -NoNewline
} catch {
# Non-fatal
}
# Add to PATH if not already there
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -notlike "*$installDir*") {

View File

@@ -63,8 +63,15 @@ install_with_bun() {
elif [ -f "$HOME/.profile" ]; then
config_file="$HOME/.profile"
fi
print_success "cua" "$VERSION" "$config_file"
# Determine installed version via npm registry (fallback to unknown)
local VERSION_BUN
VERSION_BUN=$(npm view @trycua/cli version 2>/dev/null || echo "unknown")
# Write version file to ~/.cua/bin/.version
local INSTALL_DIR="$HOME/.cua/bin"
mkdir -p "$INSTALL_DIR"
echo "$VERSION_BUN" > "$INSTALL_DIR/.version"
# Print success and exit
print_success "$(command -v cua)" "$VERSION_BUN" "$config_file"
exit 0
else
echo "❌ Installation failed. Please try installing manually:"
@@ -114,6 +121,7 @@ VERSION=${TAG_NAME#cua-v}
# Find the binary URL in the release assets
BINARY_URL=$(echo "$LATEST_RELEASE" | grep -o 'https://.*/download/[^"]*/'${BINARY_NAME}'"' | head -1)
BINARY_URL="${BINARY_URL%\"}"
printf "\033[90mBINARY_URL: %s\033[0m\n" "$BINARY_URL"
if [ -z "$BINARY_URL" ]; then
echo "⚠️ Could not find ${BINARY_NAME} in release assets, falling back to Bun installation"
@@ -136,6 +144,9 @@ fi
# Make the binary executable
chmod +x "$INSTALL_DIR/cua"
# Write version file
echo "$VERSION" > "$INSTALL_DIR/.version"
# Add ~/.cua/bin to PATH if not already in PATH
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
# Add to .bashrc, .zshrc, or .profile