unjs / unjs/jup

shell setup for better performance

Open
#11 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
68
Forks
0
Avg merge
30m
Merged PRs (30d)
1

Description

Describe the feature

Currently jup use a simple shim to map node version, it works well but it will cost about 26ms in my environment to run the node (~2.5x time to run native node)

Inspired by nvm and fnm, we can add a hook to shell, update the PATH to the selected node bin on each cd, e.g. on zsh:

# .zshrc
jup-env() {
  (( $+commands[jup] )) || return 0
  local jup_node_store="${JUP_HOME:-$HOME/.cache/jup}/v1/node"

  # drop entries a previous run prepended so each directory re-resolves
  path=(${path:#$jup_node_store/*})

  local node_version node_bin_dir
  node_version=$(jup node -v 2>/dev/null) || return 0
  [[ $node_version == v*.* ]] || return 0
  node_bin_dir="$jup_node_store/${node_version#v}/bin"
  [[ -x $node_bin_dir/node ]] && path=("$node_bin_dir" $path)
}

autoload -Uz add-zsh-hook
add-zsh-hook chpwd jup-env
jup-env

Then the node can be run as fast as native. It may works on other commands.

Can we have a official document or something like jup env --use-on-cd --shell zsh to do that?

Additional information
  • Would you be willing to help implement this feature?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the CLI entry point for jup node -v and examine how commands resolve the selected Node version. Compare the proposed zsh chpwd hook with the alternative jup env --use-on-cd --shell zsh, then clarify whether the deliverable is official documentation, a command, or both. Done means the chosen approach updates PATH on directory changes and preserves fast native-like node startup.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell, typescript, zsh
Domain
cli, developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.