Skip to content
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

Add Volta Support #2100

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 20 additions & 15 deletions modules/node/functions/node-info
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,32 @@
# Zeh Rizzatti <[email protected]>
#

# function node-info {

local version
local version_format
local version_formatted

unset node_info
typeset -gA node_info

if (( $+commands[nodenv] )); then
version="${${$(nodenv version)#v}[(w)0]}"
elif (( $+functions[nvm_version] )); then
version="${$(nvm_version)#v}"
elif (( $+commands[node] )) ; then
version="${$(node -v)#v}"
fi

if [[ "$version" != (none|system) ]]; then
# Only proceed if we're in a Node.js project
if [[ -f "package.json" || -f ".nvmrc" || -f ".node-version" ]]; then
# Get the format
zstyle -s ':prezto:module:node:info:version' format 'version_format'
zformat -f version_formatted "$version_format" "v:$version"
node_info[version]="$version_formatted"
fi

# }
if [[ -n "$version_format" ]]; then
if (( $+commands[nodenv] )); then
version="${${$(nodenv version)#v}[(w)0]}"
elif (( $+commands[volta] )); then
version="${${$(volta list node | grep 'default')#*@}%% *}"
elif (( $+functions[nvm_version] )); then
version="${$(nvm_version)#v}"
elif (( $+commands[node] )) ; then
version="${$(node -v)#v}"
fi

if [[ -n "$version" && "$version" != "system" ]]; then
zformat -f version_formatted "$version_format" "v:$version"
node_info[version]="$version_formatted"
fi
fi
fi
24 changes: 18 additions & 6 deletions modules/node/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@
# Indrajit Raychaudhuri <[email protected]>
#

# Possible lookup locations for manually installed nodenv and nvm.
# Possible lookup locations for manually installed version managers
local_nodenv_paths=({$NODENV_ROOT,{$XDG_CONFIG_HOME/,$HOME/.}nodenv}/bin/nodenv(N))
local_nvm_paths=({$NVM_DIR,{$XDG_CONFIG_HOME/,$HOME/.}nvm}/nvm.sh(N))
local_volta_paths=({$VOLTA_HOME,$HOME/.volta}/bin/volta(N))

# Load manually installed or package manager installed nodenv into the shell
# session.
if (( $#local_nodenv_paths || $+commands[nodenv] )); then

# Ensure manually installed nodenv is added to path when present.
[[ -s $local_nodenv_paths[1] ]] && path=($local_nodenv_paths[1]:h $path)

eval "$(nodenv init - zsh)"

# Use volta if it's installed
elif (( $#local_volta_paths || $+commands[volta] )); then
export VOLTA_HOME="${VOLTA_HOME:-$HOME/.volta}"
path=("$VOLTA_HOME/bin" $path)

# Load manually installed nvm into the shell session.
elif (( $#local_nvm_paths )); then
source "$local_nvm_paths[1]" --no-use
Expand All @@ -31,10 +35,10 @@ elif (( $+commands[brew] )) \
source "$nvm_path/nvm.sh" --no-use
fi

unset local_n{odenv,vm}_paths nvm_path
unset local_{nodenv,nvm,volta}_paths nvm_path

# Return if requirements are not found.
if (( ! $+commands[node] && ! $#functions[(i)n(odenv|vm)] )); then
if (( ! $+commands[node] && ! $#functions[(i)n(odenv|vm)] && ! $+commands[volta] )); then
return 1
fi

Expand Down Expand Up @@ -64,4 +68,12 @@ if ! zstyle -t ':prezto:module:node:alias' skip; then
alias npmci='npm ci'
alias npmcit='npm cit'
alias npmit='npm it'
fi

# Add Volta-specific aliases if Volta is installed
if (( $+commands[volta] )); then
alias vl='volta list'
alias vla='volta list all'
alias vi='volta install'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Almost every *nix out there has vi as editor command. Also chances are many users just type vi without thinking and expect the editor to show up on the screen.

Copy link
Author

@adamavenir adamavenir Dec 21, 2024

Choose a reason for hiding this comment

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

lol yes I am actually a vim user and just wasn't thinking 😆

I type out volta install myself and was actually just following the existing pattern. I'll make a change to have more sensible aliases here.

alias vp='volta pin'
fi
fi
15 changes: 12 additions & 3 deletions modules/prompt/functions/prompt_sorin_setup
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

# Load dependencies.
pmodload 'helper'
pmodload 'node'

function prompt_sorin_async_callback {
case $1 in
Expand All @@ -57,7 +58,7 @@ function prompt_sorin_async_callback {
"[async]")
# Code is 1 for corrupted worker output and 2 for dead worker.
if [[ $2 -eq 2 ]]; then
# Our worker died unexpectedly.
# Our worker died unexpectedly.
typeset -g prompt_prezto_async_init=0
fi
;;
Expand Down Expand Up @@ -110,6 +111,11 @@ function prompt_sorin_precmd {
python-info
fi

# Run node info
if (( $+functions[node-info] )); then
node-info
fi

prompt_sorin_async_tasks
}

Expand Down Expand Up @@ -155,6 +161,9 @@ function prompt_sorin_setup {
# Set python-info parameters.
zstyle ':prezto:module:python:info:virtualenv' format '%f%F{3}(%v)%F{7} '

# Set node-info parameters
zstyle ':prezto:module:node:info:version' format ' %F{2}⬡ %v%f'

# Set up non-zero return value display
local show_return="✘ "
# Default is to show the return value
Expand All @@ -170,7 +179,7 @@ function prompt_sorin_setup {

# Define prompts.
PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} '
RPROMPT='$python_info[virtualenv]${editor_info[overwrite]}%(?:: %F{1}'
RPROMPT='$python_info[virtualenv]${node_info[version]} ${editor_info[overwrite]}%(?:: %F{1}'
RPROMPT+=${show_return}
RPROMPT+='%f)${VIM:+" %B%F{6}V%f%b"}${_prompt_sorin_git}'
SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? '
Expand All @@ -186,4 +195,4 @@ function prompt_sorin_preview {
}

prompt_sorin_setup "$@"
# vim: ft=zsh
# vim: ft=zsh