mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 22:31:51 +00:00
Fall back to .node-version if it exists
This commit is contained in:
parent
811c039e2b
commit
008bf47d3f
@ -40,6 +40,7 @@
|
|||||||
- [Set default node version](#set-default-node-version)
|
- [Set default node version](#set-default-node-version)
|
||||||
- [Use a mirror of node binaries](#use-a-mirror-of-node-binaries)
|
- [Use a mirror of node binaries](#use-a-mirror-of-node-binaries)
|
||||||
- [.nvmrc](#nvmrc)
|
- [.nvmrc](#nvmrc)
|
||||||
|
- [.node-version](#node-version)
|
||||||
- [Deeper Shell Integration](#deeper-shell-integration)
|
- [Deeper Shell Integration](#deeper-shell-integration)
|
||||||
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
|
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
|
||||||
- [bash](#bash)
|
- [bash](#bash)
|
||||||
@ -565,6 +566,14 @@ Now using node v5.9.1 (npm v3.7.3)
|
|||||||
|
|
||||||
The contents of a `.nvmrc` file **must** be the `<version>` (as described by `nvm --help`) followed by a newline. No trailing spaces are allowed, and the trailing newline is required.
|
The contents of a `.nvmrc` file **must** be the `<version>` (as described by `nvm --help`) followed by a newline. No trailing spaces are allowed, and the trailing newline is required.
|
||||||
|
|
||||||
|
### .node-version
|
||||||
|
|
||||||
|
For a little compatability with other node version managers, nvm will also sniff for `.node-version` files. They're the same as `.nmvrc`, they just share a common name.
|
||||||
|
|
||||||
|
$ echo "5.9" > .node-version
|
||||||
|
|
||||||
|
They'll be loaded after `.nvmrc`, and can contain the same values as `.nvmrc`.
|
||||||
|
|
||||||
### Deeper Shell Integration
|
### Deeper Shell Integration
|
||||||
|
|
||||||
You can use [`avn`](https://github.com/wbyoung/avn) to deeply integrate into your shell and automatically invoke `nvm` when changing directories. `avn` is **not** supported by the `nvm` maintainers. Please [report issues to the `avn` team](https://github.com/wbyoung/avn/issues/new).
|
You can use [`avn`](https://github.com/wbyoung/avn) to deeply integrate into your shell and automatically invoke `nvm` when changing directories. `avn` is **not** supported by the `nvm` maintainers. Please [report issues to the `avn` team](https://github.com/wbyoung/avn/issues/new).
|
||||||
|
9
nvm.sh
9
nvm.sh
@ -464,6 +464,11 @@ nvm_find_nvmrc() {
|
|||||||
dir="$(nvm_find_up '.nvmrc')"
|
dir="$(nvm_find_up '.nvmrc')"
|
||||||
if [ -e "${dir}/.nvmrc" ]; then
|
if [ -e "${dir}/.nvmrc" ]; then
|
||||||
nvm_echo "${dir}/.nvmrc"
|
nvm_echo "${dir}/.nvmrc"
|
||||||
|
else
|
||||||
|
dir="$(nvm_find_up '.node-version')"
|
||||||
|
if [ -e "${dir}/.node-version" ]; then
|
||||||
|
nvm_echo "${dir}/.node-version"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,14 +479,14 @@ nvm_rc_version() {
|
|||||||
NVMRC_PATH="$(nvm_find_nvmrc)"
|
NVMRC_PATH="$(nvm_find_nvmrc)"
|
||||||
if [ ! -e "${NVMRC_PATH}" ]; then
|
if [ ! -e "${NVMRC_PATH}" ]; then
|
||||||
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
||||||
nvm_err "No .nvmrc file found"
|
nvm_err "No .nvmrc or .node-version file found"
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf ''
|
NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf ''
|
||||||
if [ -z "${NVM_RC_VERSION}" ]; then
|
if [ -z "${NVM_RC_VERSION}" ]; then
|
||||||
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
||||||
nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\""
|
nvm_err "Warning: empty nvm file found at \"${NVMRC_PATH}\""
|
||||||
fi
|
fi
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
@ -8,3 +8,7 @@ nvm install --lts
|
|||||||
if [ -f ".nvmrc" ]; then
|
if [ -f ".nvmrc" ]; then
|
||||||
mv .nvmrc .nvmrc.bak
|
mv .nvmrc .nvmrc.bak
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f ".node-version" ]; then
|
||||||
|
mv .node-version .node-version.bak
|
||||||
|
fi
|
||||||
|
@ -7,7 +7,12 @@ nvm uninstall v1.0.0
|
|||||||
nvm uninstall --lts
|
nvm uninstall --lts
|
||||||
|
|
||||||
rm .nvmrc
|
rm .nvmrc
|
||||||
|
rm .node-version
|
||||||
|
|
||||||
if [ -f ".nvmrc.bak" ]; then
|
if [ -f ".nvmrc.bak" ]; then
|
||||||
mv .nvmrc.bak .nvmrc
|
mv .nvmrc.bak .nvmrc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f ".node-version.bak" ]; then
|
||||||
|
mv .node-version.bak .node-version
|
||||||
|
fi
|
||||||
|
@ -12,6 +12,21 @@ echo "0.10.7" > .nvmrc
|
|||||||
[ "$(nvm run --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm run\` failed to print out the \"found in .nvmrc\" message"
|
[ "$(nvm run --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm run\` failed to print out the \"found in .nvmrc\" message"
|
||||||
|
|
||||||
|
|
||||||
|
echo "0.12.0" > .node-version
|
||||||
|
|
||||||
|
[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "\`nvm run\` failed to run with the .nvmrc version"
|
||||||
|
|
||||||
|
[ "$(nvm run --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm run\` failed to print out the \"found in .nvmrc\" message"
|
||||||
|
|
||||||
|
rm .nvmrc
|
||||||
|
|
||||||
|
[ "$(nvm run --version | tail -1)" = "v0.12.0" ] || die "\`nvm run\` failed to run with the .node-version version"
|
||||||
|
|
||||||
|
[ "$(nvm run --version | head -1)" = "Found '$PWD/.node-version' with version <0.12.0>" ] || die "\`nvm run\` failed to print out the \"found in .node-version\" message"
|
||||||
|
|
||||||
|
rm .node-version
|
||||||
|
|
||||||
|
|
||||||
echo "foo" > .nvmrc
|
echo "foo" > .nvmrc
|
||||||
|
|
||||||
# running nvm run with .nvmrc should not print the version information when not installed
|
# running nvm run with .nvmrc should not print the version information when not installed
|
||||||
|
Loading…
Reference in New Issue
Block a user