NVM is a great tool to allow us to change Node versions at will. I am trying to develop something good that will allow users to change NPM versions at will, mostly for the purposes of testing library code, before release.
So I am working on '@oresoftware/npm.version', which has an executable called npmv which will change out the current npm version in the $PATH.
The user runs:
npmv use 5.3
and if 5.3 is not installed, it will install it to a directory with the user home, then it will symlink that version to the global space.
Here is what I have:
#!/usr/bin/env bash
set -e;
desired_npm_version="$1"
if [ -z "$desired_npm_version" ]; then
echo >&2 "No desired npm version provided.";
exit 1;
fi
desired_v="$npmvv/$desired_npm_version"
if [ ! -d "$desired_v" ]; then
mkdir -p "$desired_v";
cd "$desired_v";
npm init -f --silent;
npm install "npm@$desired_npm_version" -f --silent
fi
cd "$npmvv/$desired_npm_version";
npm_root="$(npm root -g)";
npm_bin="$(npm bin -g)";
rm -rf "$npm_root/npm";
rm -rf "$npm_bin/npm";
rm -rf "$npm_bin/npx";
ln -sf node_modules/npm "$npm_root"
ln -sf node_modules/.bin/npm "$npm_bin/npm"
ln -sf node_modules/.bin/npx "$npm_bin/npx"
# end
don't run it, because it will probably break your NPM installation. I cannot figure out why it doesn't work, but it doesn't play well with NVM (Node Version Manager) at the very least.
Note that NPM only comes with two executables (npm, npx).
If you know what you are doing and see something that might be missing in the script, please let me know. The only thing I can think of, is that perhaps running ln -s <source-file> <target-link>
against a that is itself a symlink, doesn't work?