Update tutorial to mention the new "rush add" command

This commit is contained in:
pgonzal 2018-09-27 19:50:18 -07:00
Родитель 80280bd15e
Коммит 0c689479a6
1 изменённых файлов: 37 добавлений и 10 удалений

Просмотреть файл

@ -4,20 +4,47 @@ title: Modifying package.json
navigation_source: docs_nav
---
Let's say you need to add a new dependency on a library "**example-lib**". Without Rush, you would do something like this: `npm install --save example-lib`. Currently Rush doesn't have a handy command for this (it's in our backlog, PR's welcome!).
Fortunately there's a pretty great alternative if you use Visual Studio Code as your editor. Simply start typing `"example-lib":` into the **package.json** file, and VS Code will query the NPM registry and show autocomplete suggestions for the latest version number. Easy!
After saving the file, then we need Rush to update your shrinkwrap file and perform the installation:
Let's say you need to add a new dependency on a library "**example-lib**". Without Rush, you would do something like this:
```sh
# Always run this command after editing package.json
$ rush update
# If there are changes to the shrinkwrap file, commit them to your branch
$ git commit -m "Ran 'rush update'"
# DON'T DO THIS IN A RUSH REPO:
~/my-repo$ cd apps/my-app
~/my-repo/apps/my-app$ npm install --save example-lib
```
In a Rush repo, you should instead use the [rush add]({% link pages/commands/rush_add.md %}) command:
```sh
~/my-repo$ cd apps/my-app
# Add "example-lib" as a dependency of "my-app", and then automatically run "rush update":
~/my-repo/apps/my-app$ rush add example-lib
```
The `rush add` command can also be used to update the version of an existing dependency:
```sh
# Update "my-app" to use "example-lib" version "~1.2.3":
~/my-repo/apps/my-app$ rush add example-lib@1.2.3
# Or if you want the version specifier "^1.2.3":
~/my-repo/apps/my-app$ rush add example-lib@1.2.3 --caret
# If any other projects in the repo are using "example-lib", you can update them all together:
~/my-repo/apps/my-app$ rush add example-lib@1.2.3 --make-consistent
```
The [command-line help]({% link pages/commands/rush_add.md %}) for `rush add` describes other options that you can use to customize the behavior.
> **Tip: A cool VS Code feature**
>
> By the way, if you use Visual Studio Code as your editor, another option is to simply edit the **package.json** file directly. If you start typing `"example-lib":`, VS Code will automatically query the NPM registry and show autocomplete suggestions for the latest published version. For simple additions, this can be even quicker than `rush add`.
>
> If you modify **package.json** manually, don't forget to run `rush update` afterwards.
## Upgrading to newer versions of your NPM packages
Today, Rush does not yet have an integrated equivalent of `npm update` or [npm-check-updates](https://www.npmjs.com/package/npm-check-updates). So you if you want to update the SemVer patterns across all your package.json files, you'll need to use an external tool.