From 6e4e1b078a73bbbcbb190eca6288bb3bde39548c Mon Sep 17 00:00:00 2001 From: Shaik Ahmad Nawaz Date: Thu, 30 Mar 2023 15:18:16 +0530 Subject: [PATCH 01/12] Document 'dart pub add' support for adding dependency overrides --- src/tools/pub/cmd/pub-add.md | 58 ++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/tools/pub/cmd/pub-add.md b/src/tools/pub/cmd/pub-add.md index 268f886635..67eb5422bc 100644 --- a/src/tools/pub/cmd/pub-add.md +++ b/src/tools/pub/cmd/pub-add.md @@ -9,11 +9,11 @@ _Add_ is one of the commands of the [pub tool](/tools/pub/cmd). $ dart pub add [dev:][:] [[dev:][:]... ] [options] ``` -This command adds the specified packages to the `pubspec.yaml` as dependencies, -and then retrieves the dependencies to resolve `pubspec.yaml`. +This command adds the specified packages to the `pubspec.yaml` as dependencies, +and then retrieves the dependencies to resolve `pubspec.yaml`. The following example command is equivalent to -editing `pubspec.yaml` to add the `http` package, +editing `pubspec.yaml` to add the `http` package, and then calling `dart pub get`: ```terminal @@ -39,6 +39,26 @@ $ dart pub add foo:'>2.0.0 <3.0.1' If `dart pub add :` is an existing dependency, it will update the constraint. +### Adding Dependency Overrides + +Starting in Dart 3, `dart pub add` supports adding dependency overrides in a similar fashion to dev dependencies. To add a dependency override, use the following syntax: +`dart pub add override::` + +For example, to add an override for the `foo` package version `1.0.0`, run the following command: + +``` +dart pub add override:foo:1.0.0 +``` + +This will add an override to your `pubspec.yaml` file: + +``` +dependency_overrides: +foo: 1.0.0 +``` + +Note that dependency overrides can conflict with the normal dependency resolution process and should be used with caution. + ## `dev` dependency The `dev:` prefix adds the package as a [dev dependency][], @@ -61,14 +81,14 @@ $ dart pub add --dev foo ## Source descriptor {{site.alert.version-note}} - YAML-formatted descriptor syntax was added in Dart 2.19. - The descriptor replaces arguments like `--path`, `--sdk`, `--git-