Skip to content

Commit 008bf47

Browse files
Phil Sturgeonmcaskill
authored andcommitted
Fall back to .node-version if it exists
1 parent 811c039 commit 008bf47

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- [Set default node version](#set-default-node-version)
4141
- [Use a mirror of node binaries](#use-a-mirror-of-node-binaries)
4242
- [.nvmrc](#nvmrc)
43+
- [.node-version](#node-version)
4344
- [Deeper Shell Integration](#deeper-shell-integration)
4445
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
4546
- [bash](#bash)
@@ -565,6 +566,14 @@ Now using node v5.9.1 (npm v3.7.3)
565566

566567
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.
567568

569+
### .node-version
570+
571+
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.
572+
573+
$ echo "5.9" > .node-version
574+
575+
They'll be loaded after `.nvmrc`, and can contain the same values as `.nvmrc`.
576+
568577
### Deeper Shell Integration
569578

570579
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).

nvm.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ nvm_find_nvmrc() {
464464
dir="$(nvm_find_up '.nvmrc')"
465465
if [ -e "${dir}/.nvmrc" ]; then
466466
nvm_echo "${dir}/.nvmrc"
467+
else
468+
dir="$(nvm_find_up '.node-version')"
469+
if [ -e "${dir}/.node-version" ]; then
470+
nvm_echo "${dir}/.node-version"
471+
fi
467472
fi
468473
}
469474

@@ -474,14 +479,14 @@ nvm_rc_version() {
474479
NVMRC_PATH="$(nvm_find_nvmrc)"
475480
if [ ! -e "${NVMRC_PATH}" ]; then
476481
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
477-
nvm_err "No .nvmrc file found"
482+
nvm_err "No .nvmrc or .node-version file found"
478483
fi
479484
return 1
480485
fi
481486
NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf ''
482487
if [ -z "${NVM_RC_VERSION}" ]; then
483488
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
484-
nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\""
489+
nvm_err "Warning: empty nvm file found at \"${NVMRC_PATH}\""
485490
fi
486491
return 2
487492
fi

test/slow/nvm exec/setup_dir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ nvm install --lts
88
if [ -f ".nvmrc" ]; then
99
mv .nvmrc .nvmrc.bak
1010
fi
11+
12+
if [ -f ".node-version" ]; then
13+
mv .node-version .node-version.bak
14+
fi

test/slow/nvm exec/teardown_dir

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ nvm uninstall v1.0.0
77
nvm uninstall --lts
88

99
rm .nvmrc
10+
rm .node-version
1011

1112
if [ -f ".nvmrc.bak" ]; then
1213
mv .nvmrc.bak .nvmrc
1314
fi
15+
16+
if [ -f ".node-version.bak" ]; then
17+
mv .node-version.bak .node-version
18+
fi

test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ echo "0.10.7" > .nvmrc
1212
[ "$(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"
1313

1414

15+
echo "0.12.0" > .node-version
16+
17+
[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "\`nvm run\` failed to run with the .nvmrc version"
18+
19+
[ "$(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"
20+
21+
rm .nvmrc
22+
23+
[ "$(nvm run --version | tail -1)" = "v0.12.0" ] || die "\`nvm run\` failed to run with the .node-version version"
24+
25+
[ "$(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"
26+
27+
rm .node-version
28+
29+
1530
echo "foo" > .nvmrc
1631

1732
# running nvm run with .nvmrc should not print the version information when not installed

0 commit comments

Comments
 (0)