This is a plugin for nodenv that detects
the Node.js version based on the
engines
field of the
current tree's package.json
file. The $NODENV_VERSION
environment variable
(set with nodenv shell
) and .node-version
files still take precedence.
When engines
is configured with a range this plugin chooses the greatest
installed version matching the range, or exits with an error if none match.
git clone https://github.com/nodenv/nodenv-package-json-engine.git $(nodenv root)/plugins/nodenv-package-json-engine
MacOS users can install many nodenv plugins with Homebrew.
This is the recommended method of installation if you installed nodenv with Homebrew.
brew tap nodenv/nodenv
brew install nodenv-package-json-engine
Once you've installed the plugin you can verify that it's working by cd
ing
into a project that has a package.json
file with engines
and does not have
a .node-version
file. From anywhere in the project's tree, run nodenv which node
.
npm install
and npm test
from within the project.
package.json
inspection and SemVer integration heavily inspired by nvmish
[1]
[2] and
rbenv-bundler-ruby-version.
Shell SemVer range support provided by sh-semver.
package.json
parsing provided by JSON.sh.