Open mnquintana opened 9 years ago
Can anyone write a shell script to automatically load a.node-version file like a.nvmrc file in nvm readme?
@ljharb
I very much appreciate everyone who contributes their own free time to maintain open-source software. Respect. That said, I really don't see why you actively try to prevent small, useful features (that certainly would improve lifes of people who use the tools you maintain) from being implemented, for example:
.node-version
by nvm (this issue)Is this really the hill you want to die on?
@bartekpacia XDG isn't a small feature (and "useful" is quite subjective), and the very comment you link explains why i'm not actually opposing it (or i'd close the issue), i'm just not yet convinced to support it.
I've basically made an entire career of dying on hills (for the betterment of humanity, one hopes), so I don't think that's going to be an effective tree to bark up.
Somehow both n and fnm are able to support both .nvmrc and .node-version files. I would love to not need to create both files, when using any of the many other tools that recognize .node-version. This seems like such an inconsequential thing, and absolutely improves the nvm user's experience, that it's pretty surprising to me that this discussion has been ongoing for almost 9 years. Whether there are ongoing discussions around what standards .node-version should take or not, it's already become a defacto standard for many libraries.
Add this to your .bashrc
after your nvm
configuration, and then run nvm-use
when there's a '.node-version' file in your folder:
nvm-use() {
# Print usage on -h or --help
if [[ "$#" -eq 1 && ("$1" == "-h" || "$1" == "--help") ]]; then
echo "Usage: nvm-use [nvm use options]"
echo ""
echo "- This function will look for a .node-version file in the current directory,"
echo " and run 'nvm use' with the version specified in that file."
echo "- If no .node-version file is found, it will run 'nvm use' with"
echo " the arguments passed to this function."
echo "- Note: This function might no longer be needed when this issue is solved:"
echo " https://github.com/nvm-sh/nvm/issues/794"
echo ""
echo "Options:"
echo " -h, --help Show this help message and exit."
return 0
fi
# Check for .node-version file and use its version if available
if [[ $# -eq 0 && -f .node-version ]]; then
local node_version
node_version=$(<.node-version)
node_version="${node_version//v/}" # Optionally remove 'v' prefix
nvm use "$node_version"
else
echo "No .node-version file found. Falling back to 'nvm use' with default arguments."
nvm use "$@"
fi
}
Looks like every other tool supports simple
.node-version
except nvm
https://github.com/shadowspawn/node-version-usage?tab=readme-ov-file#compatibility-testing
Is the lack of specification the only reason?
There were good examples like JSON
or markdown
mentioned. Typescript
also doesn't have active specification and still, it's wildly used
If everyone else agrees to the format, who is NVM waiting for?
Rather than try and debate this, we gave in and shifted to fnm
. It's been relatively painless.
I do think that @ljharb is digging their heels in unnecessarily on this issue, but it's their project and their maintenance burden etc., so I'd suggest just using an alternate version manager that supports the features you need.
Since moved to ASDF.
It uses a single .tool-versions
file to provision Node.js as well as dozens of other programming languages besides.
Forgive me if this has been discussed before, but I didn't find anything beyond https://github.com/creationix/nvm/issues/110#issuecomment-40525629.
It would be really nice to see the various Node version managing tools coalesce around a common "version config file", analogous to Ruby's
.ruby-version
for RVM and rbenv -.node-version
. This would basically just be an alias for.nvmrc
, since that functionality's already been added. Sincen
already supports.node-version
, this would make it so that regardless of the Node version manager used, there could be some degree of guarantee that the correct version will be used.