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

pubspec.yaml should have a "latest" keyword for easy authoring #2895

Closed
eseidel opened this issue Feb 27, 2021 · 8 comments
Closed

pubspec.yaml should have a "latest" keyword for easy authoring #2895

eseidel opened this issue Feb 27, 2021 · 8 comments

Comments

@eseidel
Copy link

eseidel commented Feb 27, 2021

I never remember what the right syntax is depending on the latest package.

I know "any" is discouraged, but I use it anyway, because it's convenient.

What if instead, there was a latest keyword (or similar) which just replaced with the correct syntax the first time it fetched?

That makes pub get no longer idempotent (not quite the right word, but I can't think of the right one?) with regards to pubspec.yaml, so maybe this instead belongs in the Editor plugins or some higher level user affordance?

Curious for your thoughts @devoncarew. Feel free to close. Just jotting down thoughts as I do some weekend hacking with Dart.

@eseidel
Copy link
Author

eseidel commented Feb 27, 2021

Would also allow docs like this to be copy/pastable:
https://flutter.dev/docs/development/data-and-backend/json#code-generation

dependencies:
  # Your other regular dependencies here
  json_annotation: <latest_version>

dev_dependencies:
  # Your other dev_dependencies here
  build_runner: <latest_version>
  json_serializable: <latest_version>

@sigurdm
Copy link
Contributor

sigurdm commented Mar 1, 2021

Interesting idea!

We have dart pub add

> dart create m
> cd m
> dart pub add json_annotation
Resolving dependencies... 
+ json_annotation 4.0.0
Changed 1 dependency!
> dart pub add --dev build_runner
Resolving dependencies... 
[...]
Changed 50 dependencies!
> dart pub add --dev json_serializable
[...]
Changed 2 dependencies!
> cat pubspec.yaml
name: m
description: A simple command-line application.
# version: 1.0.0
# homepage: https://www.example.com

environment:
  sdk: '>=2.10.0 <3.0.0'

#dependencies:
#  path: ^1.7.0

dev_dependencies:
  build_runner: ^1.11.5
  json_serializable: ^4.0.2
  pedantic: ^1.9.0
dependencies: 
  json_annotation: ^4.0.0

Does this work for your use cases?

@eseidel
Copy link
Author

eseidel commented Mar 1, 2021

dart pub add will work great, yes thanks.

I guess there still remains a question of what to do for our docs (should they be recommending dart pub add?) and also what to do for IDE users (should they also be just dropping to the command line? Presumably there are enough other reasons to do so.)

But i'm also fine to see this closed. Thanks for the reply!

@sigurdm
Copy link
Contributor

sigurdm commented Mar 2, 2021

I see the IDE-friendliness of the "latest" keyword that transforms into the latest good version compared to using the CLI.

I would hope for IDEs to incorporate dart pub add somehow. I know work is being done on tab-completion for package-names.

@jonasfj WDYT?

@jonasfj
Copy link
Member

jonasfj commented Mar 16, 2021

@DanTup has been working on package name completion in pubspec.yaml recent API for listing package-names (excluding: Dart 1.x, discontinued and unlisted packages).

I've even seen a future iteration of @DanTup's work where there is completion for version constraints.

This will certainly improve the story for people editing pubspec.yaml.


But yes, incorporating dart pub add <package> in IDEs would be nice, especially in combination with package name completion.. I suspect that it might be easy to make a ctrl+p command to "add a dependency" which then let's you auto-complete on package names.

Similarly, we should probably make analyzer hints to add a dependency using dart pub add <package>, if an imported package is missing.

@DanTup
Copy link

DanTup commented Mar 16, 2021

The package-name work has landed in the analyzer, though versions isn't complete yet (the way it currently works only supports LSP/VS Code, but I have ideas to fix this).

Nov-25-2020 17-06-43

It suggests the latest version number, so there might not be much value in including an entry for "latest" directly - although if we ever show more than just the latest version, it could make sense to annotate them (eg. with "latest pre-release", "latest stable" or maybe even ones that may not be compatible with your current SDK constraints or similar).

@DanTup
Copy link

DanTup commented Mar 16, 2021

just replaced with the correct syntax the first time it fetched

I think I misunderstood this as "when completed from code completion", but reading the copy/paste example above, I realise that wasn't the case. If this was implemented (to update the pubspec on the first pub get) then maybe there is more value in including the string "latest" in the completion too - eg. if you're authoring a template project.

@jonasfj
Copy link
Member

jonasfj commented Mar 16, 2021

It suggests the latest version number, so there might not be much value in including an entry for "latest" directly

This is already super awesome, which is why I think we shouldn't support a <latest> syntax in pubspec.yaml, which would have the downside of making dart pub get mutate pubspec.yaml.

nit: we probably shouldn't suggest the latest version, but only suggest caret ranges like ^1.7.0 (pinning versions will make dart pub upgrade less useful).

eg. if you're authoring a template project.

But templates are regularly updated, and if a new major version is published, you really should check if it works with the template code, before upgrading.

Templates should already be using ^a.b.c syntax, so it's only relevant for major versions.

I don't think making pub get mutate the pubspec is a good idea, unless we get a lot of value from it :)


I'm going to close this issue, because I think we should:

  • Advocate the use of dart pub add <package> in tutorials,
  • Continue to improve IDE integration, like possibly adding:
    • Auto completion for package names,
    • ctrl+p commands for adding dependencies,
    • Analyzer quick fixes for missing dependencies,

I know "any" is discouraged, but I use it anyway, because it's convenient.

If you are publishing packages it's strongly discouraged, I think even forbidden.

If you're developing an application it's discouraged. It has major downsides if you're maintaining a big complicated application with many developers.

For quick hacks using any can be fine, the downside is that you more easily make major version upgrades without noticing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants