Giter Club home page Giter Club logo

nvshim's Introduction

NVM Shim

LOGO

Automagically use the correct version of node with nvm exec functionality.

Build Status Coverage Status Pypi Stage Wheel Dependabot badge

No more nvm use

This will use existing .nvmrc file, falling back to the nvm alias default version if no config detected.

Installation

Pip

pip install nvshim

Github

pip install git+git://github.com/iamogbz/nvshim.git

Configuration

Reads all configuration from the environment.

Relies on nvm being installed and configured correctly.

NVSHIM_AUTO_INSTALL

Set to 1 or true to auto install specified version of node if not installed by nvm.

NVSHIM_VERBOSE

Set to 1 or true to show more information on the shimmed node process.

Otherwise set to 0 or false or nothing.

Caveats

  1. To allow the nvshim installed node shim work in all directories, you'll need to stop sourcing nvm.sh in your shell rc i.e. bash_profile, zshrc etc.

    • Just comment out the source /Users/me/.nvm/nvm.sh in your shell startup script. This is optional and prevents nvm from taking control of your shell path on launch.
    • With nvm shimmed, nvm use commands do not have any effect on the shell, the node version is already always gotten from the config automatically.
  2. The scope of this project only shims the node, npm, npx and nvm binaries. Any globally installed modules are not automatically shimmed.

    • It is still easy to run a specific global bin e.g. npx eslint will alway run the version of eslint installed via the node version for the current shell.
    • Indicate your interest in having this tool shim all binaries installed via node by leaving a comment here.

Contribution

All forms of contribution welcome, please see guide.

make install
make tests a="--snapshot-update"

nvshim's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar iamogbz avatar noahnu avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nvshim's Issues

Failing static lint checks

Describe the bug

Revert 0b9c348

To Reproduce
Steps to reproduce the behavior:

  1. Revert 0b9c348
  2. Push and watch build
  3. See error
    Your code has been rated at 10.00/10
    
    src/nvshim/utils/constants.py: error: Source file found twice under different module names: 
    "nvshim.utils.constants" and "src.nvshim.utils.constants"
    Found 1 error in 1 file (errors prevented further checking)
    make: *** [Makefile:120: lint] Error 2

Expected behavior

No error

Screenshots

Screenshot 2023-01-26 at 6 37 52 PM

Additional context

Attempting to remove the src. prefix results in failing make deploy command in GitHub actions CI

Distribute on homebrew

Is your feature request related to a problem? Please describe.

Support homebrew automation

Describe the solution you'd like

brew install iamogbz/ery/nvshim
brew install iamogbz/d/nvshim

Describe alternatives you've considered

Only support pip install ...

Additional context

https://docs.brew.sh/Python-for-Formula-Authors

Instructions for how to use shims along with nvm commands

Is your feature request related to a problem? Please describe.

To get this plugin my .zshrc looks like this

# source /usr/share/nvm/init-nvm.sh
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
export NVSHIM_VERBOSE=true

The shim works well as I switch directories. However if I want to manage my node versions, I no longer have access to the npm command, since was instructed to comment out the init as above.

Describe the solution you'd like

Ideally there would be a way to use the shim and the npm management commands in the same terminal session.

Describe alternatives you've considered

For now I can work around this in my current shell by manually running:
source /usr/share/nvm/init-nvm.sh

Then I can run npm list, install, etc. However that session will no longer work with the shim.

Shim all npm installable binaries

Is your feature request related to a problem? Please describe.

While this shims node, npm and npx to use the current project/global version. The binaries installed after an npm install are not shimmed. The correct bins are still accessible via npx, but that's not as intuitive as just running eslint directly.

Describe the solution you'd like

  • npm install eslint installs eslint using the current project version npm
  • which eslint points to the eslint in the correct npm bin path
  • Launch a new shell
  • which eslint should still be shimmed to the correct bin based on current project version

Describe alternatives you've considered

  1. Shim all binaries post npm installation.
    After the shimmed node binaries run, check the current version npm bin -g and add a shim for any new npm installed binaries that would handle redirecting to the correct version based on the current project.

    • Maybe include an environment variable NVSHIM_AUTO_INSTALL_SHIM=1 that controls if globally installed bins should have specific shims created
    • When a global shim does not exist for the current version of node what is the behaviour? Print warning and instructions?
      Attempting to call global `eslint` but it is not installed for `node` v16.2.1.
      Run `npm -g install eslint` to install for your current version.
      Or switch your `nvm` config to a version that has it installed.
      Available local node versions are `18.9.0`, `16.2.1`, `14.7.1`.
  2. Configure the PATH to include npm binaries.
    After nvshim is installed, configure the shell to set up dynamic environment PATH. Although at this point how is it different from the other solutions that modify the shell on directory change.

  3. Do nothing.
    npx is sufficient, just document that this is not within the scope of the project.

Additional context

Killing a node process prints a KeyboardInterrupt stack trace from the shim

Describe the bug

Killing a node process prints a KeyboardInterrupt stack trace. It's noisy.

To Reproduce

Run webpack dev server via nvshim. Use Ctrl+C to kill the process. See stack trace.

Expected behavior

No stack trace. nvshim should be "invisible" to the user.

Screenshots

image

Desktop (please complete the following information):

  • OS: Mac OS Catalina 10.15.3
  • nvshim 1.0.4

Add support for n

Is your feature request related to a problem? Please describe.

Currently only supports nvm

Describe the solution you'd like

Detect and support node version manager installed be it n or nvm

Describe alternatives you've considered

n/a

Additional context

Version 'default' not found - try `nvm ls-remote` to browse available versions.

Describe the bug
After installing on ubuntu server 20, not in a specific project folder, when I want to add log rotate to pm2 or just do node -v
I get the following error.

Version 'default' not found - try `nvm ls-remote` to browse available versions.

So it seems like it doen not pickup the default alias ...

Expected behavior
I expect nvm to work normally .. now it does not..

Screenshots
image

Additional context
my env is

SHELL=/bin/bash
LANGUAGE=en_US:
NVSHIM_AUTO_INSTALL=1
PWD=/home/<redacted>
LOGNAME=<redacted>
HOME=/home/<redacted>
LANG=en_US.UTF-8
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
NVM_DIR=/home/<redacted>/.nvm
LESSCLOSE=/usr/bin/lesspipe %s %s
TERM=xterm-256color
LESSOPEN=| /usr/bin/lesspipe %s
USER=de_oase
SHLVL=1
NVM_CD_FLAGS=
NPM_PACKAGES=/home/<redacted>/.npm-packages
NODE_PATH=/home/<redacted>/.npm-packages/lib/node_modules:/home/<redacted>/.npm-packages/lib/node_modules
PATH=/home/de_oase/.npm-packages/bin:/home/de_oase/.local/bin:/home/<redacted>/.npm-packages/bin:/RunCloud/Packages/apache2-rc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
MAIL=/var/mail/<redacted>
OLDPWD=/home/de_oase/webapps/app-<redacted>/current
_=/usr/bin/env

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.