mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-09-20 00:00:08 +08:00
Compare commits
5
Commits
cd84623ab2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4f801ed72 | ||
|
|
7fc22fc9c7 | ||
|
|
b6d7823bce | ||
|
|
3fb99c652b | ||
|
|
74bb42ee23 |
@@ -44,6 +44,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)
|
||||||
- [Pass Authorization header to mirror](#pass-authorization-header-to-mirror)
|
- [Pass Authorization header to mirror](#pass-authorization-header-to-mirror)
|
||||||
|
- [Platforms without official binaries](#platforms-without-official-binaries)
|
||||||
- [.nvmrc](#nvmrc)
|
- [.nvmrc](#nvmrc)
|
||||||
- [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)
|
||||||
@@ -122,7 +123,7 @@ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || pr
|
|||||||
|
|
||||||
#### Additional Notes
|
#### Additional Notes
|
||||||
|
|
||||||
- If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.</sub>
|
- If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.
|
||||||
|
|
||||||
- You can add `--no-use` to the end of the above script to postpone using `nvm` until you manually [`use`](#usage) it:
|
- You can add `--no-use` to the end of the above script to postpone using `nvm` until you manually [`use`](#usage) it:
|
||||||
|
|
||||||
@@ -646,6 +647,8 @@ nvm install iojs-v1.0.3
|
|||||||
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3
|
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Some platforms and architectures have no binary on the default host at all; see [Platforms without official binaries](#platforms-without-official-binaries).
|
||||||
|
|
||||||
`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. Note that using `nvm` in multiple shell tabs with this environment variable enabled can cause race conditions.
|
`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. Note that using `nvm` in multiple shell tabs with this environment variable enabled can cause race conditions.
|
||||||
|
|
||||||
#### Pass Authorization header to mirror
|
#### Pass Authorization header to mirror
|
||||||
@@ -655,6 +658,31 @@ To pass an Authorization header through to the mirror url, set `$NVM_AUTH_HEADER
|
|||||||
NVM_AUTH_HEADER="Bearer secret-token" nvm install node
|
NVM_AUTH_HEADER="Bearer secret-token" nvm install node
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Platforms without official binaries
|
||||||
|
|
||||||
|
nodejs.org does not publish a binary for every platform and architecture nvm can detect. Where it does not, `nvm install` falls back by default to compiling from source, which is slow and needs a C++ toolchain (see [Important Notes](#important-notes)); set `$NVM_NO_SOURCE_FALLBACK` to `1` to make a missing binary an error instead.
|
||||||
|
|
||||||
|
[unofficial-builds.nodejs.org](https://unofficial-builds.nodejs.org/download/release/) ([nodejs/unofficial-builds](https://github.com/nodejs/unofficial-builds)) publishes binaries for platforms the Node.js project does not officially support. To use them, point [`$NVM_NODEJS_ORG_MIRROR`](#use-a-mirror-of-node-binaries) at it:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release
|
||||||
|
```
|
||||||
|
|
||||||
|
| platform | binaries on nodejs.org | binaries on unofficial-builds |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `freebsd`, `openbsd` (any arch) | none | none |
|
||||||
|
| `sunos` (Solaris, illumos) | v13.x and earlier | none |
|
||||||
|
| `linux-x86` (32-bit) | v9.x and earlier | v8.16.0 through v21.x |
|
||||||
|
| `linux-armv6l` | v11.x and earlier | v8.16.0 through v22.x |
|
||||||
|
| `linux-armv7l` | v23.x and earlier | none |
|
||||||
|
| `linux-x64-musl` (Alpine) | v24.20.0+ and v26.8.0+ only | v8.16.0 and later |
|
||||||
|
| `linux-arm64-musl` (Alpine) | none | v20.20.1 and later |
|
||||||
|
| `linux-loong64` | none | v18.18.0 and later |
|
||||||
|
| `linux-riscv64` | none | v17.7.1 through v26.0.0 |
|
||||||
|
| `win-x86` (32-bit) | v22.x and earlier | none |
|
||||||
|
|
||||||
|
Neither host is gapless, and both change over time; the `index.tab` at the root of each is authoritative. Where neither has a binary, `nvm install` compiles from source, except on non-WSL Windows, which nvm cannot build on; on FreeBSD and OpenBSD it skips the download and goes straight to source. Alpine has its own section: [Installing nvm on Alpine Linux](#installing-nvm-on-alpine-linux).
|
||||||
|
|
||||||
### .nvmrc
|
### .nvmrc
|
||||||
|
|
||||||
You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).
|
You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).
|
||||||
@@ -957,7 +985,7 @@ set -e
|
|||||||
|
|
||||||
In order to provide the best performance (and other optimizations), nvm will download and install pre-compiled binaries for Node (and npm) when you run `nvm install X`. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, [CentOS](https://www.centos.org), [RedHat](https://www.redhat.com) et al).
|
In order to provide the best performance (and other optimizations), nvm will download and install pre-compiled binaries for Node (and npm) when you run `nvm install X`. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, [CentOS](https://www.centos.org), [RedHat](https://www.redhat.com) et al).
|
||||||
|
|
||||||
[Alpine Linux](https://www.alpinelinux.org), unlike mainstream/traditional Linux distributions, is based on [BusyBox](https://www.busybox.net/), a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - [musl](https://www.musl-libc.org/). This makes binary programs built for such mainstream/traditional incompatible with Alpine Linux, thus we cannot simply `nvm install X` on Alpine Linux and expect the downloaded binary to run correctly - you'll likely see "...does not exist" errors if you try that.
|
[Alpine Linux](https://www.alpinelinux.org), unlike mainstream/traditional Linux distributions, is based on [BusyBox](https://www.busybox.net/), a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - [musl](https://www.musl-libc.org/). This makes binary programs built for such mainstream/traditional distributions incompatible with Alpine Linux, so on `x64` and `arm64` nvm requests a `musl` build instead. nodejs.org publishes those only for some recent `x64` releases, so for anything else the download 404s and `nvm install X` falls back to compiling from source, unless you point it at a mirror that has one (see [Platforms without official binaries](#platforms-without-official-binaries)).
|
||||||
|
|
||||||
There is a `-s` flag for `nvm install` which requests nvm download Node source and compile it locally.
|
There is a `-s` flag for `nvm install` which requests nvm download Node source and compile it locally.
|
||||||
|
|
||||||
@@ -977,7 +1005,7 @@ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.7/install.sh | bash
|
|||||||
|
|
||||||
_Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package [`python2`](https://www.python.org/) to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._
|
_Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package [`python2`](https://www.python.org/) to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._
|
||||||
|
|
||||||
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
|
The Node project now publishes an official `linux-x64-musl` binary for some recent releases (v24.20.0+ and v26.8.0+; no v25 release has one). There is no official `arm64` musl binary.
|
||||||
|
|
||||||
As a potential alternative, [@mhart](https://github.com/mhart) (a Node contributor) has some [Docker images for Alpine Linux with Node and optionally, npm, pre-installed](https://github.com/mhart/alpine-node).
|
As a potential alternative, [@mhart](https://github.com/mhart) (a Node contributor) has some [Docker images for Alpine Linux with Node and optionally, npm, pre-installed](https://github.com/mhart/alpine-node).
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -496,7 +496,7 @@ nvm_do_install() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then
|
if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then
|
||||||
nvm_echo "=> Please also append the following lines to the if you are using bash/zsh shell:"
|
nvm_echo "=> Please also append the following lines to the correct file if you are using bash/zsh shell:"
|
||||||
command printf "${COMPLETION_STR}"
|
command printf "${COMPLETION_STR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ if [ -n "$NODE_VERSION" ]; then
|
|||||||
else
|
else
|
||||||
{ NVM_RC_VERSION="$(nvm_rc_version 3>&1 1>&4)"; } 4>&1 && nvm_ensure_version_installed "$NVM_RC_VERSION";
|
{ NVM_RC_VERSION="$(nvm_rc_version 3>&1 1>&4)"; } 4>&1 && nvm_ensure_version_installed "$NVM_RC_VERSION";
|
||||||
if ! nvm use >/dev/null 2>&1; then
|
if ! nvm use >/dev/null 2>&1; then
|
||||||
echo "No NODE_VERSION provided; no .nvmrc file found" >&2
|
nvm_err 'nvm-exec: unable to select a node version'
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
nvm_err ' Set `NODE_VERSION` (e.g. `NODE_VERSION=default`), or add an `.nvmrc` file.'
|
||||||
exit 127
|
exit 127
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -2877,6 +2877,16 @@ nvm_get_make_jobs() {
|
|||||||
"_aix")
|
"_aix")
|
||||||
NVM_CPU_CORES="$(pmcycles -m | wc -l)"
|
NVM_CPU_CORES="$(pmcycles -m | wc -l)"
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
# `_NPROCESSORS_ONLN` is how glibc, FreeBSD, macOS, and Cygwin spell it;
|
||||||
|
# the unprefixed name is what POSIX.1-2024 standardizes, and what NetBSD
|
||||||
|
# and Solaris answer to. Windows shells inherit `NUMBER_OF_PROCESSORS`;
|
||||||
|
# the smallest ones ship neither `getconf` nor `nproc`.
|
||||||
|
NVM_CPU_CORES="$(command getconf _NPROCESSORS_ONLN 2>/dev/null \
|
||||||
|
|| command getconf NPROCESSORS_ONLN 2>/dev/null \
|
||||||
|
|| command nproc 2>/dev/null \
|
||||||
|
|| nvm_echo "${NUMBER_OF_PROCESSORS-}")"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
if ! nvm_is_natural_num "${NVM_CPU_CORES}"; then
|
if ! nvm_is_natural_num "${NVM_CPU_CORES}"; then
|
||||||
nvm_err 'Can not determine how many core(s) are available, running in single-threaded mode.'
|
nvm_err 'Can not determine how many core(s) are available, running in single-threaded mode.'
|
||||||
|
|||||||
@@ -1,14 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
|
export NVM_DIR="$(cd ../.. && pwd)"
|
||||||
|
|
||||||
|
# an ambient value would send nvm-exec down its `NODE_VERSION` branch
|
||||||
|
unset NODE_VERSION
|
||||||
|
|
||||||
: nvm.sh
|
: nvm.sh
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
|
|
||||||
cleanup() { rm -f .nvmrc; }
|
ORIG_PWD="$(pwd)"
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
cd "${ORIG_PWD}" 2>/dev/null || true
|
||||||
|
rm -f .nvmrc
|
||||||
|
[ -n "${TMP_DIR-}" ] && rm -rf "${TMP_DIR}"
|
||||||
|
}
|
||||||
die () { echo "$@" ; cleanup ; exit 1; }
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
NVM_TEST_VERSION=v0.42
|
NVM_TEST_VERSION=v0.42
|
||||||
|
|
||||||
|
HINT="nvm-exec: unable to select a node version
|
||||||
|
Set \`NODE_VERSION\` (e.g. \`NODE_VERSION=default\`), or add an \`.nvmrc\` file."
|
||||||
|
|
||||||
# Write it to nvmrc
|
# Write it to nvmrc
|
||||||
echo "$NVM_TEST_VERSION" > .nvmrc
|
echo "$NVM_TEST_VERSION" > .nvmrc
|
||||||
|
|
||||||
@@ -17,9 +31,26 @@ EXPECTED="Found '$(pwd)/.nvmrc' with version <${NVM_TEST_VERSION}>
|
|||||||
N/A: version \"${NVM_TEST_VERSION}\" is not yet installed.
|
N/A: version \"${NVM_TEST_VERSION}\" is not yet installed.
|
||||||
|
|
||||||
You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.
|
You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.
|
||||||
No NODE_VERSION provided; no .nvmrc file found";
|
${HINT}";
|
||||||
|
|
||||||
# Skip install, we want to test the error message
|
# Skip install, we want to test the error message
|
||||||
[ "${EXPECTED}" = "${OUTPUT}" ] || die "expected >${EXPECTED}<, got >${OUTPUT}<"
|
[ "${EXPECTED}" = "${OUTPUT}" ] || die "expected >${EXPECTED}<, got >${OUTPUT}<"
|
||||||
|
|
||||||
|
rm -f .nvmrc
|
||||||
|
|
||||||
|
NVM_EXEC="$(cd ../.. && pwd)/nvm-exec"
|
||||||
|
|
||||||
|
# Run from a fresh, empty directory so no ambient .nvmrc above the test dir
|
||||||
|
# can satisfy the lookup and mask the hint.
|
||||||
|
TMP_DIR="$(mktemp -d)"
|
||||||
|
cd "${TMP_DIR}" || die "could not cd to temp dir"
|
||||||
|
|
||||||
|
OUTPUT="$("${NVM_EXEC}" node </dev/null 2>&1)";
|
||||||
|
EXIT_CODE=$?
|
||||||
|
EXPECTED="No version provided and no .nvmrc file found
|
||||||
|
${HINT}";
|
||||||
|
|
||||||
|
[ "${EXPECTED}" = "${OUTPUT}" ] || die "expected >${EXPECTED}<, got >${OUTPUT}<"
|
||||||
|
[ "${EXIT_CODE}" = 127 ] || die "expected exit code 127, got >${EXIT_CODE}<"
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|||||||
Executable
+147
@@ -0,0 +1,147 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# `nvm_get_make_jobs` sets the global `NVM_MAKE_JOBS` instead of echoing it, so
|
||||||
|
# every case runs it in this shell, with its output captured to files.
|
||||||
|
|
||||||
|
ORIG_PATH="${PATH}"
|
||||||
|
TMP_DIR="$(mktemp -d)"
|
||||||
|
|
||||||
|
# the probe shims live under `mktemp -d` rather than `.`, because this directory
|
||||||
|
# is shared with every other unit test and a leaked `getconf` would poison them
|
||||||
|
SHIMS="${TMP_DIR}/bin"
|
||||||
|
OUT="${TMP_DIR}/out"
|
||||||
|
ERR="${TMP_DIR}/err"
|
||||||
|
|
||||||
|
cleanup () {
|
||||||
|
export PATH="${ORIG_PATH}"
|
||||||
|
rm -rf "${TMP_DIR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
die () { cleanup; echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
: nvm.sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
mkdir -p "${SHIMS}"
|
||||||
|
|
||||||
|
shim () {
|
||||||
|
{
|
||||||
|
echo '#!/bin/sh'
|
||||||
|
echo "$2"
|
||||||
|
} > "${SHIMS}/$1"
|
||||||
|
chmod +x "${SHIMS}/$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# a probe that behaves as if it were not installed, and whose complaint must
|
||||||
|
# never reach the user
|
||||||
|
shim_absent () {
|
||||||
|
shim "$1" "echo 'PROBE_NOISE: $1' >&2; exit 127"
|
||||||
|
}
|
||||||
|
|
||||||
|
REAL_OS="$(nvm_get_os)"
|
||||||
|
|
||||||
|
FAKE_OS=''
|
||||||
|
nvm_get_os () {
|
||||||
|
nvm_echo "${FAKE_OS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
run () {
|
||||||
|
FAKE_OS="$1"
|
||||||
|
shift
|
||||||
|
NVM_MAKE_JOBS=''
|
||||||
|
nvm_get_make_jobs "$@" >"${OUT}" 2>"${ERR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_jobs () {
|
||||||
|
[ "_${NVM_MAKE_JOBS}" = "_$1" ] \
|
||||||
|
|| die "${2}: expected NVM_MAKE_JOBS ${1}, got '${NVM_MAKE_JOBS}'"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_stdout () {
|
||||||
|
ACTUAL="$(cat "${OUT}")"
|
||||||
|
[ "_${ACTUAL}" = "_$1" ] \
|
||||||
|
|| die "${2}: expected stdout '${1}', got '${ACTUAL}'"
|
||||||
|
}
|
||||||
|
|
||||||
|
# deliberately narrower than "stderr is empty": ksh93 has no `local`, so every
|
||||||
|
# nvm.sh function already sprays `local: not found` here (see #574)
|
||||||
|
assert_no_probe_noise () {
|
||||||
|
! nvm_grep -q 'PROBE_NOISE' "${ERR}" \
|
||||||
|
|| die "${1}: a failed probe leaked to stderr: '$(cat "${ERR}")'"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_not_nagged () {
|
||||||
|
! nvm_grep -q 'Please report an issue on GitHub' "${ERR}" \
|
||||||
|
|| die "${1}: unexpected report-an-issue message"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_nagged () {
|
||||||
|
nvm_grep -q 'Please report an issue on GitHub' "${ERR}" \
|
||||||
|
|| die "${1}: expected the report-an-issue message, got '$(cat "${ERR}")'"
|
||||||
|
}
|
||||||
|
|
||||||
|
export PATH="${SHIMS}:${ORIG_PATH}"
|
||||||
|
|
||||||
|
# an OS the `case` does not name still gets a real core count
|
||||||
|
shim getconf 'echo 4'
|
||||||
|
shim_absent nproc
|
||||||
|
|
||||||
|
run win
|
||||||
|
assert_jobs 3 'win'
|
||||||
|
assert_stdout 'Detected that you have 4 CPU core(s)
|
||||||
|
Running with 3 threads to speed up the build' 'win'
|
||||||
|
assert_not_nagged 'win'
|
||||||
|
assert_no_probe_noise 'win'
|
||||||
|
|
||||||
|
run ''
|
||||||
|
assert_jobs 3 'unknown OS'
|
||||||
|
assert_not_nagged 'unknown OS'
|
||||||
|
|
||||||
|
# Solaris and NetBSD spell the `getconf` variable without the leading underscore
|
||||||
|
shim getconf 'case "$1" in NPROCESSORS_ONLN) echo 4 ;; *) exit 1 ;; esac'
|
||||||
|
run win
|
||||||
|
assert_jobs 3 'unprefixed getconf name'
|
||||||
|
assert_not_nagged 'unprefixed getconf name'
|
||||||
|
|
||||||
|
# with no `getconf`, `nproc` answers
|
||||||
|
shim_absent getconf
|
||||||
|
shim nproc 'echo 4'
|
||||||
|
run win
|
||||||
|
assert_jobs 3 'nproc'
|
||||||
|
assert_not_nagged 'nproc'
|
||||||
|
assert_no_probe_noise 'nproc'
|
||||||
|
|
||||||
|
# Cygwin/MSYS/MinGW inherit `NUMBER_OF_PROCESSORS` from Windows
|
||||||
|
shim_absent nproc
|
||||||
|
NUMBER_OF_PROCESSORS=4
|
||||||
|
run win
|
||||||
|
assert_jobs 3 'NUMBER_OF_PROCESSORS'
|
||||||
|
assert_not_nagged 'NUMBER_OF_PROCESSORS'
|
||||||
|
assert_no_probe_noise 'NUMBER_OF_PROCESSORS'
|
||||||
|
|
||||||
|
# with nothing to probe, nvm still says so instead of guessing
|
||||||
|
unset NUMBER_OF_PROCESSORS
|
||||||
|
run win
|
||||||
|
assert_jobs 1 'no probes'
|
||||||
|
assert_nagged 'no probes'
|
||||||
|
|
||||||
|
# the named arms keep priority: darwin asks `sysctl`, not `getconf`
|
||||||
|
shim getconf 'echo 99'
|
||||||
|
shim sysctl 'echo 4'
|
||||||
|
run darwin
|
||||||
|
assert_jobs 3 'darwin uses sysctl'
|
||||||
|
assert_not_nagged 'darwin uses sysctl'
|
||||||
|
|
||||||
|
export PATH="${ORIG_PATH}"
|
||||||
|
|
||||||
|
# an explicit count short-circuits detection entirely
|
||||||
|
run '' 7
|
||||||
|
assert_jobs 7 'explicit jobs'
|
||||||
|
assert_stdout 'number of `make` jobs: 7' 'explicit jobs'
|
||||||
|
|
||||||
|
# on the real host, detected or not, the result is always usable
|
||||||
|
run "${REAL_OS}"
|
||||||
|
nvm_is_natural_num "${NVM_MAKE_JOBS}" \
|
||||||
|
|| die "real host: expected a natural number, got '${NVM_MAKE_JOBS}'"
|
||||||
|
|
||||||
|
cleanup
|
||||||
Reference in New Issue
Block a user