Skip to content

Commit

Permalink
Test and document upgrade command
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin committed May 18, 2017
1 parent f394572 commit 5b0d80d
Show file tree
Hide file tree
Showing 32 changed files with 363 additions and 103 deletions.
6 changes: 3 additions & 3 deletions doc/ADD.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ADD Command - Node Version Switcher
```
nvs add <version>
```

nvs add <version>

Downloads and extracts a requested node version. An added node version is then ready to activate with a USE command.

A version string consists of a complete or partial semantic version number or version label ("lts", "latest", "Argon", etc.), optionally preceded by a remote name, optionally followed by a processor architecture or bitness ("x86", "x64", "32", "64"), separated by slashes. When a partial version matches multiple available versions, the latest version is automatically selected. Examples: "node/lts", "4.6.0", "6/x86", "node/6.7/x64". An alias may also be used in place of a version string.
Expand Down
58 changes: 29 additions & 29 deletions doc/ALIAS.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
# ALIAS Command - Node Version Switcher
```
nvs alias
nvs alias <name>
nvs alias <name> <version>
nvs alias <name> <directory>
nvs alias -d <name>
```

nvs alias
nvs alias <name>
nvs alias <name> <version>
nvs alias <name> <directory>
nvs alias -d <name>

Queries, sets, or removes version aliases. When no arguments are specified, all alias names and values are listed. When just a name is specified, the value for that alias is shown, if it exists. When a name and value are specified, the alias is added or updated to the persisted list. The `-d` switch removes an item. The alias settings are persisted in `$NVS_HOME/settings.json`.

An alias may refer to a combination of a remote name and a semantic version. (Processor architectures are not aliased.) When setting an alias, the remote name may be omitted, in which case the alias refers to the default remote. For example `nvs alias 6.7.0` is exactly equivalent to `nvs alias default/6.7.0`.

When using an alias with other commands, a processor architecture may be optionally appended to override the system default, the same as with semantic versions. For example:
```
$ nvs alias myalias 6.7.0
$ nvs alias
myalias default/6.7.0
$ nvs run myalias --version
v6.7.0
$ nvs which myalias
~/.nvs/node/6.7.0/x64/bin/node
$ nvs which myalias/32
~/.nvs/node/6.7.0/x86/bin/node
```

$ nvs alias myalias 6.7.0
$ nvs alias
myalias default/6.7.0
$ nvs run myalias --version
v6.7.0
$ nvs which myalias
~/.nvs/node/6.7.0/x64/bin/node
$ nvs which myalias/32
~/.nvs/node/6.7.0/x86/bin/node

## Aliasing directories

An alias may also refer to a local directory containing any node executable. Create an alias like this to enable NVS to switch to/from a version of node that was built locally from source:
```
$ nvs alias dev ~/src/node/out/Release
$ nvs use dev
PATH += ~/src/node/out/Release
$ nvs ls
#node/6.9.1/x64
>/home/username/src/node/out/Release (dev)
$ nvs use lts
PATH -= ~/src/node/out/Release
PATH += ~/.nvs/node/6.9.1/x64/bin
```

$ nvs alias dev ~/src/node/out/Release
$ nvs use dev
PATH += ~/src/node/out/Release
$ nvs ls
#node/6.9.1/x64
>/home/username/src/node/out/Release (dev)
$ nvs use lts
PATH -= ~/src/node/out/Release
PATH += ~/.nvs/node/6.9.1/x64/bin

Note it is not possible to `nvs use` a directory without using an alias.
10 changes: 5 additions & 5 deletions doc/AUTO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# AUTO Command - Node Version Switcher
```
nvs auto
nvs auto on
nvs auto off
```

nvs auto
nvs auto on
nvs auto off

When invoked with no parameters, `nvs auto` searches for the nearest `.node-version` file in the current directory or parent directories. If found, the version specified in the file is then downloaded (if necessary) and used. If no `.node-version` file is found, then the default (linked) version, if any, is used.

The `nvs auto on` command enables automatic switching as needed whenever the current shell's working directory changes; `nvs auto off` disables automatic switching in the current shell. (This feature is not supported in Windows Command Prompt.)
Expand Down
6 changes: 3 additions & 3 deletions doc/EXEC.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# EXEC Command - Node Version Switcher
```
nvs exec <version> <exe> [args...]
```

nvs exec <version> <exe> [args...]

Runs any executable using a `PATH` environment that includes the specified node version, without changing the caller's `PATH`.
8 changes: 4 additions & 4 deletions doc/LINK.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# LINK Command - Node Version Switcher
```
nvs link [version]
nvs ln [version]
```

nvs link [version]
nvs ln [version]

Creates a symbolic directory link at `$NVS_HOME/default` that points to the specified version (or the current version from `PATH` at the time of the command). This sets a "default" node version, which is restored whenever the current version is removed, or when running `nvs use` with no version. It can also be useful when there is a need to configure a fixed path elsewhere (such as in an IDE), allowing the version to be switched without changing the path.

On Windows, this command also updates the profile `PATH` environment variable to include the default (linked) version, so that any newly opened shells will use that default version.
Expand Down
10 changes: 5 additions & 5 deletions doc/LIST-REMOTE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# LIST-REMOTE Command - Node Version Switcher
```
nvs lsr [filter]
nvs ls-remote [filter]
nvs list-remote [filter]
```

nvs lsr [filter]
nvs ls-remote [filter]
nvs list-remote [filter]

Lists node versions available to download.

The optional filter parameter may be a configured remote name, or a partial semantic version such as `6.5`, or a remote name and partial version such as `node/6`. If the filter is or includes a remote name, then available versions from that remote are listed; otherwise versions from the default remote are listed. A remote name is one of the keys from the `remotes` mapping in `$NVS_HOME/settings.json`.
8 changes: 4 additions & 4 deletions doc/LIST.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# LIST Command - Node Version Switcher
```
nvs ls [filter]
nvs list [filter]
```

nvs ls [filter]
nvs list [filter]

Lists local node versions that are immediately available to use.

The optional filter parameter may be a configured remote name, or a partial semantic version such as `6.5`, or a remote name and partial version such as `node/6`. If the filter is omitted then all available versions are listed.
Expand Down
6 changes: 3 additions & 3 deletions doc/MIGRATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MIGRATE Command - Node Version Switcher
```
nvs migrate <sourceversion> [targetversion]
```

nvs migrate <sourceversion> [targetversion]

Migrates globally-installed and globally-linked modules from a source node version to a target node version. Note this ignores any configuration (NPM_CONFIG_PREFIX environment variable or prefix setting in the user's npmrc) that might override the global modules directory location, because that configuration would apply apply to both versions and therefore no migration would be necessary or possible.

The source and target versions must refer to previously-added node versions. The target version optional; if unspecified then the currently used version is the target.
18 changes: 9 additions & 9 deletions doc/REMOTE.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# REMOTE Command - Node Version Switcher
```
nvs remote
nvs remote ls

nvs remote <name>
nvs remote
nvs remote ls

nvs remote <name> <uri>
nvs remote add <name> <uri>
nvs remote <name>

nvs remote <name> <uri>
nvs remote add <name> <uri>

nvs remote -d <name>
nvs remote rm <name>

nvs remote -d <name>
nvs remote rm <name>
```
Queries, sets, or removes URIs for downloading node. When no arguments are specified, all remote names and URIs are listed. When just a name is specified, the URI for that remote is shown, if it exists. When a name and value are specified (optionally with an `add` command), the remote is added or updated to the persisted list. The `-d` or `rm` command removes an item.

A special `default` remote may also be set to refer to the name of another remote. A remote that is pointed to by the default may not be removed; switch the default to another remote first.
Expand Down
8 changes: 4 additions & 4 deletions doc/REMOVE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# REMOVE Command - Node Version Switcher
```
nvs rm <version>
nvs remove <version>
```

nvs rm <version>
nvs remove <version>

Removes a node version that was previously added via an ADD command. Any symlinks or PATH entries (in the calling shell environment only) pointing to that version are also removed.

A version string consists of a semantic version number, optionally preceded by a remote name, optionally followed by a processor architecture or bitness ("x86", "x64", "32", "64"), separated by slashes. Examples: "4.6.0", "6/x86", "node/6.7/x64"
Expand Down
16 changes: 8 additions & 8 deletions doc/RUN.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# RUN Command - Node Version Switcher
```
nvs <module.js> [args...]
nvs run <module.js> [args...]
nvs run auto <module.js> [args...]
nvs <version> <module.js> [args...]
nvs run <version> <module.js> [args...]
```

nvs <module.js> [args...]
nvs run <module.js> [args...]
nvs run auto <module.js> [args...]

nvs <version> <module.js> [args...]
nvs run <version> <module.js> [args...]

Runs a node module using a specified node version, without changing the caller's `PATH`.

If no version (or "auto") is specified, NVS searches for the nearest `.node-version` file in the current directory or parent directories. If found, the version specified in the file is then downloaded (if necessary) and used to run the module. If no `.node-version` file is found, then the current version of node is used to run the module; if there is no current version then the default (linked) version, if any, is used to run the module.
2 changes: 2 additions & 0 deletions doc/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Before installing, decide on either a single-user installation or a system insta
By default, downloaded Node.js files are cached under the NVS installation directory. To override this behavior, set the `NVS_HOME` environment variable to another location.

## Windows
NVS requires PowerShell 3.0, which is included with Windows 8 and later. On Windows 7, get PowerShell 3.0 from [Windows Management Framework 3.0](https://www.microsoft.com/en-us/download/details.aspx?id=34595) (which requires Windows 7 Service Pack 1).

Download and run the Windows Installer (MSI) package from the [Releases page on GitHub](https://github.com/jasongin/nvs/releases). Note the single MSI package supports both x86 and x64 systems and both per-user and per-machine installations.

As an alternative to installing the MSI, the following manual steps may be used to setup NVS on Windows, from either a Command Prompt or PowerShell.
Expand Down
8 changes: 4 additions & 4 deletions doc/UNLINK.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# UNLINK Command - Node Version Switcher
```
nvs unlink [version]
nvs ul [version]
```

nvs unlink [version]
nvs ul [version]

Removes a symbolic directory link if it exists at `$NVS_HOME/default`. If a version is specified, then the link is only removed if it points to that version.

On Windows, this command also removes the default (linked) version from the profile `PATH` environment variable. Afterward, new shell windows will not use any Node.js version.
34 changes: 34 additions & 0 deletions doc/UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# UPGRADE Command - Node Version Switcher

nvs upgrade [fromversion]

Upgrades the specified Node version to the latest available build with the same major version. If no version is specified, the version currently in use is implied, if any.

## Upgrade procedure
The following steps are performed automatically by the upgrade command:

1. Query the remote to identify the latest available version with the same major version as the specified version.
2. Download and install (`nvs add`) the newer version, if not already added.
3. Migrate global packages (`nvs migrate`) from the old to the new version.
4. If the old version was linked, link (`nvs link`) the new version instead.
5. Use (`nvs use`) the new version if the old version was previously in use.
6. Remove the old version.

## Examples

nvs add lts # Adds 6.10.1
# Some time later 6.10.2 is published
nvs use lts # Uses 6.10.1 (nvs use does not check for a newer version)
nvs upgrade # Upgrades from 6.10.1 to 6.10.2

nvs add argon # Adds 4.8.1
# Some time later 4.9.0 is published
nvs upgrade argon # Upgrades from 4.8.1 to 4.9.0

nvs add 7.7 # Adds 7.7.4
nvs add 7 # Adds 7.8.0... forgot to use the upgrade command
nvs upgrade 7.7 # Upgrades from 7.7.4 to 7.8.0

nvs add nightly # Adds the latest build from the "nightly" remote: 8.0.0-nightly20170331...
# One day later
nvs upgrade nightly # Upgrades from 8.0.0-nightly20170331... to 8.0.0-nightly20170401...
13 changes: 6 additions & 7 deletions doc/USE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# USE Command - Node Version Switcher
```
nvs <version>
nvs use <version>

nvs use
nvs use auto
nvs <version>
nvs use <version>

nvs use default
nvs use
nvs use auto

nvs use default

```
Updates the `PATH` of the calling shell to include the specified node version (which must have been already added). If no version (or "auto") is specified, NVS searches for the nearest `.node-version` file in the current directory or parent directories. If found, the version specified in the file is then added (if necessary) and used. If no `.node-version` file is found, then the default (linked) version, if any, is used.

A version string consists of a complete or partial semantic version number or version label ("lts", "latest", "Argon", etc.), optionally preceded by a remote name, optionally followed by a processor architecture or bitness ("x86", "x64", "32", "64"), separated by slashes. When a partial version matches multiple available versions, the latest version is automatically selected. Examples: "node/lts", "4.6.0", "6/x86", "node/6.7/x64". An alias may also be used in place of a version string.
Expand Down
6 changes: 3 additions & 3 deletions doc/WHICH.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WHICH Command - Node Version Switcher
```
nvs which [version]
```

nvs which [version]

Shows the path to a specified local node version, or the current version in the PATH if a version is not specified.
2 changes: 1 addition & 1 deletion lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function help(topic) {
}

if (helpText) {
helpText = helpText.replace(/#+ /g, '');
helpText = helpText.replace(/```[\w+-]*/g, '');
helpText = wrapLines(helpText, process.stdout.columns);
return helpText;
Expand All @@ -40,6 +39,7 @@ function help(topic) {
'nvs add <version> Download and extract a node version',
'nvs rm <version> Remove a node version',
'nvs migrate <fromver> [tover] Migrate global modules',
'nvs upgrade [fromver] Upgrade to latest patch of major version',
'',
'nvs use [version] ' + (canUpdateEnv
? 'Use a node version in the current shell'
Expand Down
31 changes: 21 additions & 10 deletions lib/upgrade.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* global settings */
'use strict';

const NodeVersion = require('./version');
const Error = require('./error');
let nvsUse = require('./use'); // Non-const enables test mocking
let nvsList = require('./list'); // Non-const enables test mocking
let nvsAddRemove = null; // Lazy load
Expand Down Expand Up @@ -31,12 +34,14 @@ function upgradeAsync(version) {

let newVersion = availableVersions[0];
if (!newVersion || NodeVersion.compare(version, newVersion) <= 0) {
throw new Error('No new version found. ' +
return ['No new version found. ' +
`${version.semanticVersion} is the latest ` +
`${version.remoteName}/${majorVersion} version available.`);
`${version.remoteName}/${majorVersion} version available.`];
}

console.log(`Upgrading ${version} to ${newVersion.semanticVersion}...`);
if (!settings.quiet) {
console.log(`Upgrading ${version} to ${newVersion.semanticVersion}...`);
}

newVersion.arch = version.arch;
let newBinPath = nvsUse.getVersionBinary(newVersion);
Expand All @@ -45,7 +50,9 @@ function upgradeAsync(version) {
} else {
nvsAddRemove = nvsAddRemove || require('./addRemove');
return nvsAddRemove.addAsync(newVersion).then(() => {
console.log(`Added at: ${nvsUse.homePath(nvsUse.getVersionBinary(newVersion))}`);
if (!settings.quiet) {
console.log(`Added at: ${nvsUse.homePath(nvsUse.getVersionBinary(newVersion))}`);
}
return upgradeToVersion(version, newVersion);
});
}
Expand All @@ -60,17 +67,21 @@ function upgradeToVersion(oldVersion, newVersion) {

nvsLink = nvsLink || require('./link');
let linkedVersion = nvsLink.getLinkedVersion();
linkedVersion.os = NodeVersion.defaultOs;
if (NodeVersion.equal(oldVersion, linkedVersion)) {
result = result.concat(nvsLink.link(newVersion));
if (linkedVersion) {
linkedVersion.os = NodeVersion.defaultOs;
if (NodeVersion.equal(oldVersion, linkedVersion)) {
result = result.concat(nvsLink.link(newVersion));
}
}

// TODO: Migrate aliases from the old to new version.

let currentVersion = nvsUse.getCurrentVersion();
currentVersion.os = NodeVersion.defaultOs;
if (NodeVersion.equal(oldVersion, currentVersion)) {
result = result.concat(nvsUse.use(newVersion));
if (currentVersion) {
currentVersion.os = NodeVersion.defaultOs;
if (NodeVersion.equal(oldVersion, currentVersion)) {
result = result.concat(nvsUse.use(newVersion));
}
}

nvsAddRemove = nvsAddRemove || require('./addRemove');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/fsUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function removeDirectoryIfEmpty(dir) {
try {
fs.rmdirSync(dir);
} catch (e) {
if (e.code !== 'ENOTEMPTY' && e.code !== 'ENOENT') {
if (e.code !== 'ENOTEMPTY' && e.code !== 'ENOENT' && e.code !== 'EBUSY') {
throw e;
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5b0d80d

Please sign in to comment.