-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Can the @Since
annotation be made usable for packages?
#52627
Comments
We can make the The latter requires an extra dependency to use. The former exposes an annotation that has no language effect, and it's only used by the analyzer. But that goes for all other public annotations in The |
Note that it appears to be quite common for package authors to forget to bump their minimum constraints. Since I've started running This forces me to fix versions of transitive dependencies on my own in my packages, by listing them as There's an example in one of the repositories I'm working on: https://github.com/invertase/dart_globe/blob/main/packages/globe_cli/pubspec.yaml#L30 |
Changing to be an analyzer issue, because the question is whether the analyzer is interested in checking The behavior would be similar to the SDK:
It's not perfect for indirect dependencies, because it still depends on the current version solution. Optimally, it should depend on the result of |
About the package exporting another package issue: Like: // package:foo/foo.dart
export 'package:bar/bar.dart'
show
@Since('1.0.0')
Bar,
@Since('1.1.0')
barUtil; This should enable packages to "override" the |
Ideally, we would also have a CI tool which, by relying on either pub or git, checks for missing Like maybe a custom |
I'd actually want that syntax for saying when the export was added, in the current package's versioning. That still leaves us without a way to say which version of the exported library we're promising. @Since("1.2") // The version of my own package where this export was added.
@Since(package: "foo", "3.3"), // The expected library version of the exported package.
export "package:foo/foo.dart"; (Very loose thought, not sure whether it'd work.) |
I think show-based Because a more legitimate use case may be one package having multiple public libraries, both exporting the same private library, but with different shows/hides. Like: // my_package/lib/a.dart
export 'src/file.dart'
show
// This library exports Foo since 1.0.0
@Since('1.0.0')
Foo;
// my_package/lib/b.dart
export 'src/file.dart'
show
Bar,
// "Foo" is exported by this library only since v1.2.3
@Since('1.2.3')
Foo; In this case, although the class |
cc @bwilkerson |
If we can fully define the semantics of the annotation when used outside the SDK (there are some interesting ideas above, we just need to know which are actually being supported) I wouldn't have any problem having the analyzer check for it. The analyzer already produces warnings related to the other annotations exposed from the core libraries.
The language grammar allows annotations on directives, but doesn't allow annotations on the names in a show clause. In order to change the parser to recognize these annotations we'd probably need a minor adjustment to the language. I doubt that it would create any issues, but it can't really be an analyzer-only enhancement; I think it really does need to be added to the spec for all tools. |
The grammar not allowing annotations inside the declaration was the main reason I suggested having multiple exports if you need multiple versions mentioned. To actually work, each such annotated exported declaration should probably only be exported by one export. |
cc @jonasfj who has been thinking about this. |
I can see why we'd want to make the We could score packages with Instead, I've been leaning towards the idea what this should be solved through static analysis. It would most definitely end up being a gross under-approximation, that can only highlight some issues, not all issues. In the extreme scenario, we could simply grep the lower-bound version of the dependency you're using to see if the identifier you're using exists inside the package.
@Since warnings without annotations |
I think it's a case of "Why not both?" Some package authors would be willing to use |
The SDK uses a custom annotation for warnings:
@Since('version')
.This warning is helpful to help folks with changing their version constraints to match what they use in their application.
This is especially useful in Dart as it is installed globally instead of on a per-project basis. But there are other use-cases.
I think opening this annotation to Flutter and package authors would be helpful too.
In general, it is very difficult to know what is the actual minimum version possible of a dependency based on what a package uses.
A package may specify
dependency: ^1.0.0
, yet use a feature only available since v1.2.0 – because when the package was first developed, 1.2.0 was available.As such, the package author may think their package is compatible with
dependency: 1.1.0
, when it actually isn't. So if an application depends on our package but also uses an olderdependency
version, it will get a funky compilation error (in the best-case scenario) instead of pub failing to resolve thepub get
.By opening up this annotation to package authors, folks could start annotating new APIs with
@Since
when they are introduced. This would help the community as a whole deal with minimum version constraints.The text was updated successfully, but these errors were encountered: