Publish Command

Publish any unpublished packages or package versions in your repository to pub.dev. dry-run is enabled by default.

bash
melos publish

--dry-run

Flags whether to publish the packages as a dry run (validate but do not publish). Defaults to true.

bash
# Publish packages with dry run
melos publish --dry-run

# Publish packages without dry run
melos publish --no-dry-run

Use --no-dry-run to disable.

--server

The URL of the package server to publish to. When set, --server <url> is forwarded to dart pub publish, overriding the per-package publish_to field in pubspec.yaml.

bash
melos publish --no-dry-run --server https://pub.flutter-io.cn

This can also be set workspace-wide in melos.yaml via the pubServer option under command/publish, so you don't have to pass it on every invocation:

yaml
# melos.yaml
command:
  publish:
    pubServer: https://pub.flutter-io.cn

The CLI flag takes precedence over the pubServer config value when both are provided.

--git-tag-version (-t)

Add any missing git tags for release. Tags are only created if --no-dry-run is also set.

bash
melos publish --no-dry-run --git-tag-version

Note that tags are automatically created as part of melos version (unless --no-git-tag-version is specified when running the version command) so this is usually not required on melos publish unless you're doing a manual version and publish of packages.

Hooks

Melos supports various command lifecycle hooks that can be defined in your root pubspec.yaml.

For example, if you need to run something such as a build runner automatically before melos publish is run and then remove the generated files after publishing is done, you can add pre and post hook scripts to your root pubspec.yaml file:

yaml
# root pubspec.yaml
# ...
melos:
  command:
    publish:
      hooks:
        pre: dart pub run build_runner build
        post: dart pub run build_runner clean
# ...

The pre-hook will run before melos publish and the post-hook will run after melos publish is done. It only runs once, even if multiple packages are published and it also runs when you are doing a dry-run publish. You can detect whether it is a dry-run by checking the MELOS_PUBLISH_DRY_RUN environment variable.