mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-07-04 03:48:06 +08:00
Compare commits
4 Commits
a6ec739430
...
419ff4efec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
419ff4efec | ||
|
|
7a7908ffa1 | ||
|
|
ce15734300 | ||
|
|
ee4fa818d2 |
2
.github/workflows/nodejs-org.yml
vendored
2
.github/workflows/nodejs-org.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
update-nodejs-org:
|
||||
if: github.repository == 'nvm-sh/nvm' && github.actor == 'ljharb'
|
||||
permissions:
|
||||
contents: none
|
||||
contents: read # for the "Extract and validate version" step's `gh api .../tags` call via the default github.token
|
||||
name: 'Create PR to nodejs/nodejs.org'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
16
.github/workflows/rebase.yml
vendored
16
.github/workflows/rebase.yml
vendored
@@ -2,16 +2,12 @@ name: Automatic Rebase
|
||||
|
||||
on: [pull_request_target]
|
||||
|
||||
permissions: read-all
|
||||
permissions:
|
||||
contents: write # for ljharb/rebase to push code to rebase
|
||||
pull-requests: read # for ljharb/rebase to get info about PR
|
||||
|
||||
jobs:
|
||||
_:
|
||||
name: "Automatic Rebase"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: ljharb/rebase@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
uses: ljharb/actions/.github/workflows/rebase.yml@main
|
||||
secrets:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
6
.github/workflows/require-allow-edits.yml
vendored
6
.github/workflows/require-allow-edits.yml
vendored
@@ -2,10 +2,14 @@ name: Require “Allow Edits”
|
||||
|
||||
on: [pull_request_target]
|
||||
|
||||
permissions: read-all
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
_:
|
||||
permissions:
|
||||
pull-requests: read # for ljharb/require-allow-edits to check 'allow edits' on PR
|
||||
|
||||
name: "Require “Allow Edits”"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -8,7 +8,7 @@ permissions:
|
||||
jobs:
|
||||
tests:
|
||||
permissions:
|
||||
contents: write
|
||||
contents: read # for actions/checkout@v6
|
||||
|
||||
name: "tests"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
4
.github/workflows/windows-npm.yml
vendored
4
.github/workflows/windows-npm.yml
vendored
@@ -94,6 +94,8 @@ jobs:
|
||||
bash.exe "%USERPROFILE%\setup.sh"
|
||||
|
||||
wsl_matrix:
|
||||
permissions:
|
||||
contents: none
|
||||
continue-on-error: true
|
||||
name: 'WSL nvm install'
|
||||
defaults:
|
||||
@@ -187,6 +189,8 @@ jobs:
|
||||
node -v
|
||||
|
||||
wsl_matrix_unofficial:
|
||||
permissions:
|
||||
contents: none
|
||||
continue-on-error: true
|
||||
name: 'WSL nvm install'
|
||||
defaults:
|
||||
|
||||
12
README.md
12
README.md
@@ -31,6 +31,7 @@
|
||||
- [Usage](#usage)
|
||||
- [Long-term Support](#long-term-support)
|
||||
- [Migrating Global Packages While Installing](#migrating-global-packages-while-installing)
|
||||
- [Migrating Global Packages Between Installed Versions](#migrating-global-packages-between-installed-versions)
|
||||
- [Offline Install](#offline-install)
|
||||
- [Default Global Packages From File While Installing](#default-global-packages-from-file-while-installing)
|
||||
- [io.js](#iojs)
|
||||
@@ -483,6 +484,17 @@ nvm install-latest-npm
|
||||
|
||||
If you've already gotten an error to the effect of "npm does not support Node.js", you'll need to (1) revert to a previous node version (`nvm ls` & `nvm use <your latest _working_ version from the ls>`), (2) delete the newly created node version (`nvm uninstall <your _broken_ version of node from the ls>`), then (3) rerun your `nvm install` with the `--latest-npm` flag.
|
||||
|
||||
### Migrating Global Packages Between Installed Versions
|
||||
|
||||
`--reinstall-packages-from` is tied to `nvm install`. To migrate global npm packages between versions you _already_ have installed, without (re)installing anything, `nvm use` the destination and run `nvm reinstall-packages` as a standalone command, pointing at the version you want to copy _from_:
|
||||
|
||||
```sh
|
||||
nvm use 22.22.2
|
||||
nvm reinstall-packages 22.20.0
|
||||
```
|
||||
|
||||
This reinstalls all global packages from `22.20.0` into the currently-active version (`22.22.2`). As with `--reinstall-packages-from`, the npm version itself is not changed.
|
||||
|
||||
|
||||
### Offline Install
|
||||
|
||||
|
||||
6
nvm.sh
6
nvm.sh
@@ -3736,10 +3736,10 @@ nvm() {
|
||||
nvm install-latest-npm
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
if [ $EXIT_CODE -ne 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
|
||||
if [ $EXIT_CODE -eq 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
|
||||
nvm_install_default_packages
|
||||
fi
|
||||
if [ $EXIT_CODE -ne 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
|
||||
if [ $EXIT_CODE -eq 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
|
||||
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
@@ -3757,7 +3757,7 @@ nvm() {
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
|
||||
if [ $EXIT_CODE -ne 0 ] && [ -n "${ALIAS-}" ]; then
|
||||
if [ $EXIT_CODE -eq 0 ] && [ -n "${ALIAS-}" ]; then
|
||||
nvm alias "${ALIAS}" "${provided_version}"
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
"homepage": "https://github.com/nvm-sh/nvm",
|
||||
"devDependencies": {
|
||||
"dockerfile_lint": "^0.3.4",
|
||||
"doctoc": "^2.2.1",
|
||||
"doctoc": "^2.5.0",
|
||||
"eclint": "^2.8.1",
|
||||
"markdown-link-check": "^3.14.2",
|
||||
"replace": "^1.2.2",
|
||||
"semver": "^7.7.3",
|
||||
"semver": "^7.8.5",
|
||||
"urchin": "^0.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
# State touched by the regression section below; cleanup restores it even on failure.
|
||||
DEFAULT_PACKAGES_FILE="${NVM_DIR}/default-packages"
|
||||
DEFAULT_PACKAGES_BACKUP=""
|
||||
DEFAULT_PACKAGES_WROTE=""
|
||||
TEST_ALIAS=""
|
||||
|
||||
cleanup () {
|
||||
if [ -n "${DEFAULT_PACKAGES_WROTE}" ]; then
|
||||
rm -f "${DEFAULT_PACKAGES_FILE}"
|
||||
DEFAULT_PACKAGES_WROTE=""
|
||||
fi
|
||||
if [ -n "${DEFAULT_PACKAGES_BACKUP}" ] && [ -f "${DEFAULT_PACKAGES_BACKUP}" ]; then
|
||||
mv "${DEFAULT_PACKAGES_BACKUP}" "${DEFAULT_PACKAGES_FILE}"
|
||||
DEFAULT_PACKAGES_BACKUP=""
|
||||
fi
|
||||
if [ -n "${TEST_ALIAS}" ]; then
|
||||
nvm unalias "${TEST_ALIAS}" > /dev/null 2>&1 || true
|
||||
TEST_ALIAS=""
|
||||
fi
|
||||
}
|
||||
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
@@ -44,3 +65,54 @@ nvm use --lts=argon
|
||||
node --version | grep v4.9.1 > /dev/null || die "nvm ls --lts=argon didn't use v4.9.1"
|
||||
|
||||
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"
|
||||
|
||||
|
||||
# Regression: `--reinstall-packages-from` must still migrate packages when the
|
||||
# target version is *already installed*. See https://github.com/nvm-sh/nvm/issues/3858
|
||||
|
||||
# install a fresh global package on the source (v9.7.0) only
|
||||
nvm use 9.7.0
|
||||
npm install -g is-nan@1.0.0 || die "npm install -g is-nan failed"
|
||||
npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed on v9.7.0"
|
||||
|
||||
# precondition: the already-installed target (v9.10.0) must not have it yet
|
||||
nvm use 9.10.0
|
||||
npm list --global | grep is-nan > /dev/null && die "is-nan should not be installed on v9.10.0 before reinstall"
|
||||
|
||||
# target is already installed, so this should report so AND still migrate packages
|
||||
OUTPUT="$(nvm install --reinstall-packages-from=9.7.0 9.10.0 2>&1)" || die "nvm install --reinstall-packages-from=9.7.0 9.10.0 failed: ${OUTPUT}"
|
||||
nvm_echo "${OUTPUT}" | grep "is already installed" > /dev/null || die "expected 'already installed' message, got: ${OUTPUT}"
|
||||
|
||||
nvm use 9.10.0
|
||||
npm list --global | grep is-nan > /dev/null || die "is-nan was not migrated to already-installed v9.10.0"
|
||||
|
||||
|
||||
# ...the same is true for default packages: they must install on the already-installed path too.
|
||||
|
||||
# back up any real default-packages file, then point it at a package the target lacks
|
||||
if [ -f "${DEFAULT_PACKAGES_FILE}" ]; then
|
||||
DEFAULT_PACKAGES_BACKUP="${DEFAULT_PACKAGES_FILE}.3858.bak"
|
||||
mv "${DEFAULT_PACKAGES_FILE}" "${DEFAULT_PACKAGES_BACKUP}" || die "could not back up ${DEFAULT_PACKAGES_FILE}"
|
||||
fi
|
||||
DEFAULT_PACKAGES_WROTE=1
|
||||
nvm_echo 'object-inspect@1.0.2' > "${DEFAULT_PACKAGES_FILE}"
|
||||
|
||||
# precondition: the already-installed target must not have the default package yet
|
||||
nvm use 9.10.0
|
||||
npm list --global | grep object-inspect > /dev/null && die "object-inspect should not be installed on v9.10.0 before default-packages test"
|
||||
|
||||
nvm install 9.10.0 > /dev/null 2>&1 || die "nvm install 9.10.0 (already installed, default-packages) failed"
|
||||
nvm use 9.10.0
|
||||
npm list --global | grep object-inspect > /dev/null || die "default packages were not installed on already-installed v9.10.0"
|
||||
|
||||
# restore the default-packages file before the next assertion
|
||||
cleanup
|
||||
|
||||
|
||||
# ...and `--alias` must be set on the already-installed path too.
|
||||
TEST_ALIAS='nvm-3858-already-installed'
|
||||
nvm unalias "${TEST_ALIAS}" > /dev/null 2>&1 || true # ensure a clean precondition
|
||||
nvm install --alias="${TEST_ALIAS}" 9.10.0 > /dev/null 2>&1 || die "nvm install --alias=${TEST_ALIAS} 9.10.0 (already installed) failed"
|
||||
TERM=dumb nvm alias "${TEST_ALIAS}" | grep 'v9.10.0' > /dev/null || die "--alias was not set on already-installed v9.10.0"
|
||||
|
||||
cleanup
|
||||
|
||||
Reference in New Issue
Block a user