rush dist:package
Published: 2022-10-31 18:38:33

Rush _global_ commands are invoked once for the entire repo. 
> See [Custom commands](https://rushjs.io/pages/maintainer/custom_commands/) for information on writing and using custom commands.

## Publishing prerelease

### Package all as prerelease

```bash
rush dist:package --include-all --prerelease `
  --package-command 'my-bulk-command' `
  --copy-command 'my-bulk-copyCommand'
# if your bulk command accepts parameters:
rush dist:package --include-all --prerelease `
  --package-command 'my-bulk-command --param1 --param2' `
  --copy-command 'my-bulk-copyCommand --param1 --param2'
# package only projects with version policy:
rush dist:package --include-all --prerelease --version-policy 'MyLibraries' `
  --package-command 'my-bulk-command' `
  --copy-command 'my-bulk-copyCommand --param1 --param2'
```

- retrieves a list of **all projects** managed by rush; if `--version-policy` is specified, selects all projects using the version policy
- invokes bulk `--package-command` command
- invokes bulk `--copy-command` (this command is optional)

This approach simplifies testing process, when a solution should be deployed to a testing environment before being released.

### Package changed as prerelease

```bash
rush dist:package --prerelease `
  --package-command 'my-bulk-command'`
  --copy-command 'my-bulk-copyCommand'
# or, if your bulk command accepts parameters:
rush dist:package --prerelease `
  --package-command 'my-bulk-command --param1 --param2'`
   --copy-command 'my-bulk-copyCommand --param1 --param2'
```

- gets **changed projects only**
- invokes bulk `--package-command` command
- invokes bulk `--copy-command` (this command is optional)

### How are changed projects detected in `--prerelease`?

**Changed projects** are detected using [ProjectChangeAnalyzer.getChangedProjectsAsync](https://api.rushstack.io/pages/rush-lib.projectchangeanalyzer.getchangedprojectsasync/) which returns projects that have changed in the current state of the repo when compared to the specified branch.
If `--target-branch` is specified, it compares the checked out branch with the specified branch to determine which projects were changed. Otherwise, the checked out branch is compared against the `main` branch.

## Publishing stable

### Publish all as stable

>Execute this command after `rush version`, to package and deploy release versions of the project.

```bash
# package all projects and copy the resulting files to specified location
rush dist:package --include-all `
  --package-command 'my-bulk-command' `
  --copy-command 'my-bulk-copyCommand'
# or, if your bulk commands accept parameters:
rush dist:package --include-all `
  --package-command 'my-bulk-command --param1 --param2' `
  --copy-command 'my-bulk-copyCommand --param1 --param2'
# package only projects with version policy:
rush dist:package --include-all --version-policy 'MyLibraries' `
  --package-command 'my-bulk-command' `
  --copy-command 'my-bulk-copyCommand'
```

- retrieves a list of **all projects** managed by rush; if `--version-policy` is specified, selects all projects using the version policy
- regenerates `CHANGELOG.md` files in case `CHANGELOG.json` files have been manually updated afer `rush version`,
- invokes bulk `--package-command` command
- invokes bulk `--copy-command` (this command is optional)
- tags the projects
- saves new tag values in `rush.json`
- commits `CHANGELOG.md`, `CHANGELOG.json` and `rush.json` files

### Publish changed as stable

```bash
# package changed projects and copy the resulting files to specified location
rush dist:package `
  --package-command 'my-bulk-command' `
  --copy-command 'my-bulk-copyCommand'
# or, if your bulk command accepts parameters:
rush dist:package `
  --package-command 'my-bulk-command --param1 --param2' `
  --copy-command 'my-bulk-copyCommand --param1 --param2'
# package only projects with version policy:
rush dist:package --version-policy 'MyLibraries' `
  --package-command 'my-bulk-command' `
  --copy-command 'my-bulk-copyCommand'
```

- retrieves a list of **changed projects** comparing project's version with a  `published_v{versionNumber}` tag,
- regenerates `CHANGELOG.md` files in case `CHANGELOG.json` files have been manually updated afer `rush version`,
- invokes bulk `--package-command` command
- invokes bulk `--copy-command` (this command is optional)
- tags changed projects
- saves new tag value for changed projects to `rush.json`
- commits `CHANGELOG.md`, `CHANGELOG.json` and `rush.json` files

### How are changed projects detected?

Since the change files are deleted during `rush version`, `rush dist:package` detects changed projects by comparing versions in each project's `package.json` file with a project's tags in the `rush.json` file. If no appropriate tags are found in `rush.json`, the project will be published.

> This command should be executed after `rush version`, to package and deploy release versions of the projects.

See the `dist:package` documentation on [GitHub](https://github.com/kkazala/generator-rush-publish/blob/main/docs/rush_GlobalCommands.md)