Skip to content

feat: check for nvm version in install script #4621

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions scripts/install-dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ if ($null -eq $node) {
& node --version
}

# Node.js version check
if (Test-Path ".nvmrc") {
$requiredNodeVersion = Get-Content ".nvmrc"
$currentNodeVersion = node -v

# Remove 'v' prefix from versions for comparison
$requiredVersion = $requiredNodeVersion.TrimStart('v')
$currentVersion = $currentNodeVersion.TrimStart('v')

if ($requiredVersion -ne $currentVersion) {
Write-Host "`n⚠️ Warning: Your Node.js version ($currentNodeVersion) does not match the required version ($requiredNodeVersion)" -ForegroundColor Yellow
Write-Host "Please consider switching to the correct version using: nvm use" -ForegroundColor Yellow
Write-Host "Continuing with installation anyway...`n" -ForegroundColor Yellow
}
}


# if ($null -eq $cargo) {
# Write-Host "`n...`n"
# Write-Host "Cargo`n" -ForegroundColor White
Expand Down
17 changes: 17 additions & 0 deletions scripts/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
# - Debug -> Extension
set -e

# Check if node version matches .nvmrc
if [ -f .nvmrc ]; then
required_node_version=$(cat .nvmrc)
current_node_version=$(node -v)

# Remove 'v' prefix from versions for comparison
required_version=${required_node_version#v}
current_version=${current_node_version#v}

if [ "$required_version" != "$current_version" ]; then
echo "⚠️ Warning: Your Node.js version ($current_node_version) does not match the required version ($required_node_version)"
echo "Please consider switching to the correct version using: nvm use"
echo "Continuing with installation anyway..."
echo
Copy link
Contributor

@owtaylor owtaylor Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could easily scroll off, maybe something like:

if [ -t 0 ] ; then
     read "Hit return to continue "
else
     echo "Continuing with installation anyway..."
fi

No idea how to do that in Powershell...

Copy link
Collaborator Author

@Patrick-Erichsen Patrick-Erichsen Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure either but this was what 3.5 Sonnet generated 🤷

if (Test-Path ".nvmrc") {
    $requiredNodeVersion = Get-Content ".nvmrc"
    $currentNodeVersion = node -v

    # Remove 'v' prefix from versions for comparison
    $requiredVersion = $requiredNodeVersion.TrimStart('v')
    $currentVersion = $currentNodeVersion.TrimStart('v')

    if ($requiredVersion -ne $currentVersion) {
        Write-Host "`n⚠️  Warning: Your Node.js version ($currentNodeVersion) does not match the required version ($requiredNodeVersion)" -ForegroundColor Yellow
        Write-Host "Please consider switching to the correct version using: nvm use" -ForegroundColor Yellow
        
        # Check if running in interactive mode
        if ([Environment]::UserInteractive -and [Environment]::GetCommandLineArgs().Count -eq 0) {
            Write-Host "Press Enter to continue with installation anyway..." -NoNewline -ForegroundColor Yellow
            $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
            Write-Host "`n" # Add newline after key press
        } else {
            Write-Host "Continuing with installation anyway...`n" -ForegroundColor Yellow
        }
    }
}

Our CI will at least catch if there are any issues with the install script in a non-interactive mode

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add arch detection for nodejs?

fi
fi

echo "Installing root-level dependencies..."
npm install

Expand Down
Loading