Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change: pubspec.yaml must contain a Dart SDK constraint #44072

Closed
mit-mit opened this issue Nov 5, 2020 · 10 comments
Closed

Breaking change: pubspec.yaml must contain a Dart SDK constraint #44072

mit-mit opened this issue Nov 5, 2020 · 10 comments
Assignees
Labels
area-sdk Use area-sdk for general purpose SDK issues (packaging, distribution, …). breaking-change-request This tracks requests for feedback on breaking changes

Comments

@mit-mit
Copy link
Member

mit-mit commented Nov 5, 2020

Background

Dart apps and packages often use a pubspec.yaml file to declare various metadata such as dependencies. It can also contain a Dart SDK constraint such as:

environment:
  sdk: '>=2.10.0 <3.0.0'

This expresses that the app/package requires a Dart SDK that is at least 2.10.0, and strictly less than 3.0.0. This is commonly used to express that the code uses a feature only available in more recent Dart releases, for example Dart 2.7 if using extension methods. The SDK constraint is documented here: https://dart.dev/tools/pub/pubspec#sdk-constraints

Currently it is allowed to omit this SDK constraint. In that case Dart interprets this as having a lower constraint that is the same as the version of the Dart SDK being used.

What is the change

We're making it an error for apps to have a pubspec.yaml that doesn't have this SDK constraint specified. Concretely, for a pubspec not containing the Dart SDK constraint, the pub/dart pub/flutter pub command will abort dependency resolution for apps and fail with an error like:

pubspec.yaml has no lower-bound SDK constraint.
You should edit pubspec.yaml to contain an SDK constraint:

environment:
  sdk: '>=2.10.0 <3.0.0'

Why are we making this change

For the Dart null safety feature we're relying on the SDK constraint to tell if a Dart app/package us using null safety semantics or not. Because of the current defaulting to current SDK version when the SDK constraint is omitted, this results in such projects being opted-in to null safety implicitly. This in turn results in lots of null safety errors.

Making the SDK constraint required ensures that all apps and packages are forced to make a choice about what Dart version they need.

Effect of the change

All existing pubspec.yaml files that don't contain an SDK constraint will start to see resolution errors. They will need to add an SDK constraint like this to their pubspec. After adding this they will continue to run as before.

environment:
  sdk: '>=2.10.0 <3.0.0'

Timeline

This change is blocking the progress on null safety, so the change will be made immediately in the Dart master channel (where the Dart 2.12 version is underway).

@mit-mit mit-mit added the breaking-change-request This tracks requests for feedback on breaking changes label Nov 5, 2020
@mit-mit
Copy link
Member Author

mit-mit commented Nov 5, 2020

@mit-mit
Copy link
Member Author

mit-mit commented Nov 5, 2020

@franklinyow
Copy link
Contributor

cc @Hixie @matanlurey

@Hixie
Copy link
Contributor

Hixie commented Nov 5, 2020

Rather than merely fail with an error that tells the user what to do, can we provide a command that will do it for them? Adding something to a YAML file is something eminently automatable. Maybe we should even do it automatically, like we do pub get automatically?

@jonasfj
Copy link
Member

jonasfj commented Nov 6, 2020

@Hixie I fear that having pub get modify your pubspec.yaml without prompts or a flag would be surprising behavior.

We could do a pub fix command, but it just seems a bit arbitrary. Also what else could/should it fix..

As for modifying YAML, it's not trivial, but we had a GSoC project create package:yaml_edit to make this easy. I think the hard part is designing a CLI interface for exposing this logic.

@bwilkerson
Copy link
Member

We might want to look into adding a quick fix in the analysis server for this case.

@franklinyow
Copy link
Contributor

marking this as Approved

@subzero911
Copy link

How about adding a key to pubspec: uses-null-safety: true instead of relying on constraints? As a user, I don't want to remember since which version you added a null safety.

@jonasfj
Copy link
Member

jonasfj commented Feb 26, 2021

As a user, I don't want to remember since which version you added a null safety.

I think the upside is that once migrated, you'll probably stop thinking about this. A boolean would instead continue to be a thing going forward.

babich-a added a commit to babich-a/DevExtreme that referenced this issue Mar 5, 2021
babich-a added a commit to babich-a/DevExtreme that referenced this issue Mar 5, 2021
babich-a added a commit to DevExpress/DevExtreme that referenced this issue Mar 5, 2021
babich-a added a commit to DevExpress/DevExtreme that referenced this issue Mar 5, 2021
haberda added a commit to haberda/leaf2mqtt that referenced this issue Mar 30, 2021
Fix pubspec.yaml to conform with latest spec: dart-lang/sdk#44072
@franklinyow
Copy link
Contributor

Closing this as this is already in Dart 2.12

X25MB added a commit to X25MB/chewie that referenced this issue Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-sdk Use area-sdk for general purpose SDK issues (packaging, distribution, …). breaking-change-request This tracks requests for feedback on breaking changes
Projects
None yet
Development

No branches or pull requests

7 participants