diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5194234..3fb0e8b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,5 +16,15 @@ For pull requests: Even if you don't have all of these items covered, please still feel free to submit a PR/issue! Someone else may be inspired and volunteer to complete it for you. -Thanks again! +## Running the test suite +The most important part of any contribution is running the test suite to make sure the thing you did actually worked! + +``` +npm install +make test +``` + +You might be asked for your password for some tests that require a few extra privileges. If you don't want to enter it, feel free not to, but the related tests will fail. + +Thanks again! diff --git a/README.md b/README.md index 3d0f07d..76640a4 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ - [System version of node](#system-version-of-node) - [Listing versions](#listing-versions) - [.nvmrc](#nvmrc) + - [.node-version](#node-version) - [Deeper Shell Integration](#deeper-shell-integration) - [zsh](#zsh) - [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file) @@ -101,7 +102,7 @@ If you're running a system without prepackaged binary available, which means you - [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell - [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup - [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell - - [fnm](https://github.com/fisherman/fnm) - [fisherman](https://github.com/fisherman/fisherman)-based version manager for fish + - [fnm](https://github.com/fisherman/fnm) - [fisherman](https://github.com/fisherman/fisherman)-based version manager for fish **Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket: - [[#900] [Bug] nodejs on FreeBSD may need to be patched ](https://github.com/creationix/nvm/issues/900) @@ -343,6 +344,17 @@ Found '/path/to/project/.nvmrc' with version <5.9> Now using node v5.9.1 (npm v3.7.3) ``` +### .node-version + +For a little compatability with other node version managers, nvm will also sniff for `.node-version` files, defaulting to `.nvmrc` if both are found in the same folder. + +``` +$ echo "5.9" > .node-version +``` + +Unlike `.nvmrc`, `.node-version` cannot contain a "versionish" (an alias, like `node`, `iojs`, or a custom alias you’ve defined). `.node-version` can only have versions in the format of v1, v1.2, or v1.2.3 (the `v` is optional). + + ### 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` development team. Please [report issues to the `avn` team](https://github.com/wbyoung/avn/issues/new). diff --git a/nvm.sh b/nvm.sh index 472b20d..a4901d1 100644 --- a/nvm.sh +++ b/nvm.sh @@ -274,37 +274,43 @@ nvm_tree_contains_path() { # Traverse up in directory tree to find containing folder nvm_find_up() { local path + local file path="${PWD}" - while [ "${path}" != "" ] && [ ! -f "${path}/${1-}" ]; do - path=${path%/*} - done - nvm_echo "${path}" -} + # Iterate through the multiple files + while [ $# -ne 0 ]; do + # Look for files in turn in this path + while [ "${path}" != "" ]; do + # Is the file here? + if [ ! -f "${path}/${1}" ]; then + file="${path}/${1}" + nvm_echo $file + break 2 + fi + done + shift + done +} nvm_find_nvmrc() { - local dir - dir="$(nvm_find_up '.nvmrc')" - if [ -e "${dir}/.nvmrc" ]; then - nvm_echo "${dir}/.nvmrc" - fi + nvm_echo "$(nvm_find_up '.nvmrc' '.node-version')" } -# Obtain nvm version from rc file nvm_rc_version() { export NVM_RC_VERSION='' local NVMRC_PATH NVMRC_PATH="$(nvm_find_nvmrc)" if [ ! -e "${NVMRC_PATH}" ]; then - nvm_err "No .nvmrc file found" + nvm_err "No .nvmrc or .node-version file found" return 1 fi + NVMRC_BASENAME="$(command basename "$NVMRC_PATH")" read -r NVM_RC_VERSION < "${NVMRC_PATH}" || printf '' if [ ! -n "${NVM_RC_VERSION}" ]; then - nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\"" + nvm_err "Warning: empty \"${NVMRC_BASENAME}\" file found at \"${NVMRC_PATH}\"" return 2 fi - nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>" + nvm_echo "Found \"${NVMRC_BASENAME}\" with version <${NVM_RC_VERSION}>" } nvm_clang_version() { diff --git a/test/slow/nvm exec/setup_dir b/test/slow/nvm exec/setup_dir index e7853d8..5f728e4 100755 --- a/test/slow/nvm exec/setup_dir +++ b/test/slow/nvm exec/setup_dir @@ -9,3 +9,6 @@ if [ -f ".nvmrc" ]; then mv .nvmrc .nvmrc.bak fi +if [ -f ".node-version" ]; then + mv .node-version .node-version.bak +fi diff --git a/test/slow/nvm exec/teardown_dir b/test/slow/nvm exec/teardown_dir index ab6c7fc..b9d6274 100755 --- a/test/slow/nvm exec/teardown_dir +++ b/test/slow/nvm exec/teardown_dir @@ -7,8 +7,11 @@ nvm uninstall v1.0.0 nvm uninstall --lts rm .nvmrc +rm .node-version if [ -f ".nvmrc.bak" ]; then mv .nvmrc.bak .nvmrc fi - +if [ -f ".node-version.bak" ]; then + mv .node-version.bak .node-version +fi diff --git "a/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" "b/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" index c3cb81e..93f0493 100755 --- "a/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" +++ "b/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" @@ -11,3 +11,14 @@ 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" +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"