diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 944bffadca5..52e4f8b2adf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,6 +49,19 @@ Please refer to the [README](README.md) for complete instructions how to install 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. +## 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! + #### How to create a pull request Create a new branch @@ -107,7 +120,6 @@ Fixes #1234 Co-authored-by: Name Here ``` - # Code of Conduct [Code of Conduct](https://github.com/nvm-sh/nvm/blob/HEAD/CODE_OF_CONDUCT.md) diff --git a/README.md b/README.md index 14b4b64a183..9a21f05c34a 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ - [Set default node version](#set-default-node-version) - [Use a mirror of node binaries](#use-a-mirror-of-node-binaries) - [.nvmrc](#nvmrc) + - [.node-version](#node-version) - [Deeper Shell Integration](#deeper-shell-integration) - [bash](#bash) - [Automatically call `nvm use`](#automatically-call-nvm-use) @@ -554,6 +555,16 @@ Now using node v5.9.1 (npm v3.7.3) The contents of a `.nvmrc` file **must** be the `` (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, 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` maintainers. Please [report issues to the `avn` team](https://github.com/wbyoung/avn/issues/new). diff --git a/nvm.sh b/nvm.sh index c37df6b9152..8ad7e26a87a 100644 --- a/nvm.sh +++ b/nvm.sh @@ -451,43 +451,46 @@ nvm_find_project_dir() { # Traverse up in directory tree to find containing folder nvm_find_up() { - local path_ - path_="${PWD}" - while [ "${path_}" != "" ] && [ "${path_}" != '.' ] && [ ! -f "${path_}/${1-}" ]; do - path_=${path_%/*} + local path + local file + path="${PWD}" + + # 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_echo "${path_}" } 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 if [ "${NVM_SILENT:-0}" -ne 1 ]; then - nvm_err "No .nvmrc file found" + nvm_err "No .nvmrc or .node-version file found" fi return 1 fi - NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf '' - if [ -z "${NVM_RC_VERSION}" ]; then - if [ "${NVM_SILENT:-0}" -ne 1 ]; then - nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\"" - 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_BASENAME}\" file found at \"${NVMRC_PATH}\"" return 2 fi - if [ "${NVM_SILENT:-0}" -ne 1 ]; then - nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>" - fi + 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 79217427336..5f728e433a3 100755 --- a/test/slow/nvm exec/setup_dir +++ b/test/slow/nvm exec/setup_dir @@ -8,3 +8,7 @@ nvm install --lts 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 b16b41695a1..d1955c40d9a 100755 --- a/test/slow/nvm exec/teardown_dir +++ b/test/slow/nvm exec/teardown_dir @@ -7,7 +7,12 @@ 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" new file mode 100755 index 00000000000..93f04937730 --- /dev/null +++ "b/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" @@ -0,0 +1,24 @@ +#!/bin/sh + + +die () { echo "$@" ; exit 1; } + +\. ../../../nvm.sh + +echo "0.10.7" > .nvmrc + +[ "$(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" + +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"