dart-lang / pub

The pub command line tool
https://dart.dev/tools/pub/cmd
BSD 3-Clause "New" or "Revised" License
1.04k stars 229 forks source link

Dependency override in pubspec.yaml ignored when pubspec_overrides.yaml exists #4387

Open scopendo opened 2 months ago

scopendo commented 2 months ago

Environment

Problem

We commonly use a pubspec_overrides.yaml file during development to set a relative path to internal packages (in different repositories) that our app depends on, leaving the pubspec.yaml set to a git URL to not break builds on our CI server. We don't commit pubspec_overrides.yaml.

Occasionally, we use the dependency_overrides section of the pubspec.yaml to force a later version of a third-party dependency, which is needed on our CI server. This override is ignored by dart pub get|upgrade unless it is repeated in the pubspec_overrides.yaml file. This is cumbersome and can be error-prone.

pubspec.yaml ```yaml name: example description: Example App publish_to: "none" version: 1.0.0 environment: sdk: ">=3.0.0 <4.0.0" dependencies: ... firebase_core: ^2.32.0 flutter: sdk: flutter example_common: git: url: ssh://git@bitbucket.org/example/example-common.git ref: v1.0.0 ... dependency_overrides: # This override will be ignored if it's not specified in pubspec_overrides.yaml firebase_core: ^3.2.0 ```
pubspec_overrides ```yaml dependency_overrides: example_common: path: ../example_common # The override of firebase_core in pubspec.yaml will be ignored unless also specified here firebase_core: ^3.2.0 ```

Expected behavior

I expected that the dependency overrides in pubspec_overrides.yaml would complement overrides in pubspec.yaml.

Actual behavior

The dependency overrides in pubspec.yaml are ignored.

sigurdm commented 1 month ago

This is working as intended. (Otherwise you could not remove overrides with a pubspec_overrides.yaml file).

Maybe we could communicate better if there are overrides in both places.

scopendo commented 1 month ago

With respect, that seems to be optimising for the less likely case, which could also be handled by setting the override accordingly.

On Thu, 26 Sept 2024, 09:24 Sigurd Meldgaard, @.***> wrote:

This is working as intended. (Otherwise you could not remove overrides with a pubspec_overrides.yaml file).

Maybe we could communicate better if there are overrides in both places.

— Reply to this email directly, view it on GitHub https://github.com/dart-lang/pub/issues/4387#issuecomment-2376281626, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE6N6UIN2XL7ZNFUNBVSSDZYPAFPAVCNFSM6AAAAABODJG5J2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZWGI4DCNRSGY . You are receiving this because you authored the thread.Message ID: @.***>

sigurdm commented 1 month ago

which could also be handled by setting the override accordingly.

Not sure I get how this would be done. Say foo is overridden in pubspec.yaml. How would you create a pubspec_overrides.yaml that removes the override?

I vaguely remember us discussing this, and deciding this was the most useful and predictable behavior. It seems to me simpler that a field in pubspec_overrides replaces the same field in pubspec.yaml, not merging with it.

I can fully see how there are cases where you desire the merging behavior.

However I doubt that we are going to break this.