tj / n

Node version management

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Preserve corepack with --preserve (or env variable)

Mitsunee opened this issue · comments

Problem

corepack is not preserved, thus installed node16 reverts me back to corepack@0.10.0 every time.

Short Version

corepack should be preserved when npm is getting preserved

Long Version

When --preserve or N_PRESERVE_NPM=1 are given npm is preserved, but corepack should also be preserved in that case. Alternatively a N_PRESERVE_COREPACK env variable would be acceptable.

My ideal outcome is that none of the globally installed packages should be touched at all by switching node versions as this possibly hinders my workflow.

Configuration Details

$ n --version
v8.2.0

$ command -v node
/home/mitsu/.local/bin/node # as intended using a symlink to $N_PREFIX/bin/node

$ node -p process.platform
linux # Fedora 36 KDE Spin

# .bashrc
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"

export N_PREFIX="$XDG_DATA_HOME/node"
export N_CACHE_PREFIX="$XDG_CACHE_HOME"
export N_PRESERVE_NPM=1
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/npmrc"
export NODE_REPL_HISTORY="$XDG_STATE_HOME/node_repl/history"

I did wonder about how to treat corepack when it was added. I decided at the time that it was an additional part of the Node.js install and not part of npm as such.

So for the environment variable, I think a separate environment variable N_PRESERVE_COREPACK is more appropriate than using the "npm" named one.

I'm unsure about --preserve. I'm currently leaning towards --preserve being preserve-all-the-things so covering both npm and corepack.

Shipped in v9.0.0