Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): add npm update example #3494

Merged
merged 1 commit into from Jul 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 36 additions & 1 deletion docs/content/commands/npm-update.md
Expand Up @@ -15,7 +15,9 @@ aliases: up, upgrade
### Description

This command will update all the packages listed to the latest version
(specified by the `tag` config), respecting semver.
(specified by the `tag` config), respecting the semver constraints of
both your package and its dependencies (if they also require the same
package).

It will also install missing packages.

Expand Down Expand Up @@ -101,6 +103,39 @@ Then `npm update` will install `dep1@0.4.1`, because that is the highest-sorting
version that satisfies `^0.4.0` (`>= 0.4.0 <0.5.0`)


#### Subdependencies

Suppose your app now also has a dependency on `dep2`

```json
{
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
"name": "my-app",
"dependencies": {
"dep1": "^1.0.0",
"dep2": "1.0.0"
}
}
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
```

and `dep2` itself depends on this limited range of `dep1`

```json
{
"name": "dep2",
"dependencies": {
"dep1": "~1.1.1"
}
}
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
```

Then `npm update` will install `dep1@1.1.2` because that is the highest
version that `dep2` allows. npm will prioritize having a single version
of `dep1` in your tree rather than two when that single version can
satisfy the semver requirements of multiple dependencies in your tree.
In this case if you really did need your package to use a newer version
you would need to use `npm install`.


#### Updating Globally-Installed Packages

`npm update -g` will apply the `update` action to each globally installed
Expand Down