[dart-announce] Migrating your packages to Dart 2

235 views
Skip to first unread message

'Michael Thomsen' via Dart Announcements

unread,
Jul 20, 2018, 6:31:44 PM7/20/18
to Dart Announcements

We expect the Dart 2 release to graduate to stable in the immediate future. Thus, it’s critical that you migrate your code — especially any packages you have published — to be Dart 2 compatible now!


There are three main aspects to this:

  • Make sure your code passes Dart 2 analysis (details). We recommend you also pay attention to hints — for example, to prepare for deprecations.

  • Run tests to make sure your code passes Dart 2 runtime checks (details).

  • Update the upper bound of the SDK constraint of your packages to <3.0.0 (details).


We strongly encourage all package authors to do this work as soon as possible. To support this work, we’ve made some enhancements to the Pub site to better show potential issues. See our Medium post for full details.

--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Announcements" group.
Visit this group at https://groups.google.com/a/dartlang.org/group/announce/.

Anatoly Pulyaevskiy

unread,
Jul 23, 2018, 2:20:15 AM7/23/18
to Dart Misc, anno...@dartlang.org
I have a question.

How do I fix following warnings which only appear in output of  `pub publish`?


Fix lib/src/document/node.dart.
Analysis of lib/src/document/node.dart failed with 2 errors:
line 6 col 8: Target of URI doesn't exist: 'package:meta/meta.dart'.
line 70 col 3: Undefined name 'protected' used as an annotation.


This happens when I import `meta` package and only use annotations from it, e.g. @protected, like in this case.
Running dartanalyzer results on "no issues found".


Another issue is that analysis tab says I should add `strong-mode: true` to my analysis_options.yaml, but dartanalyzer says it's deprecated.

Thanks,
Anatoly

Istvan Soos

unread,
Jul 23, 2018, 3:13:43 AM7/23/18
to General Dart Discussion, anatoly.p...@gmail.com
On Mon, Jul 23, 2018 at 8:20 AM, Anatoly Pulyaevskiy
<anatoly.p...@gmail.com> wrote:
> How do I fix following warnings which only appear in output of `pub
> publish`?

You can abort the publish at that point and fix the warnings from the
console. If you are looking to fix pub site's warnings, there is a
tool called pana, which you can run locally, and should give you most
of the output that you find on pub site (in a json format):
https://pub.dartlang.org/packages/pana

> Fix lib/src/document/node.dart.
> Analysis of lib/src/document/node.dart failed with 2 errors:
> line 6 col 8: Target of URI doesn't exist: 'package:meta/meta.dart'.
> line 70 col 3: Undefined name 'protected' used as an annotation.

Your code depends on package:meta, but it does not specify it as a
dependency (only through transitive dev_dependencies). During pub
site's analysis we remove the dev_dependencies and work only with your
dependencies block, and pub is not able to resolve the package. As
your library code depends on it, you shall specify it as a dependency
(although pub site's analysis is a bit forgiving there, it will work
if it is pulled in as a transitive dependency too).

> Another issue is that analysis tab says I should add `strong-mode: true` to
> my analysis_options.yaml, but dartanalyzer says it's deprecated.

Fix is in progress for that.

Thanks,
Istvan

Anatoly Pulyaevskiy

unread,
Jul 23, 2018, 12:47:40 PM7/23/18
to Dart Misc, anatoly.p...@gmail.com
Thanks Istvan,

Looks like all this time I've been reading it wrong, user error. When Pub prints out following message:

Suggestions:
* line 6, column 1 of lib/src/document/node.dart: This package doesn't depend on meta.
  import 'package:meta/meta.dart';
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For some reason I always thought that it thinks my lib/src/document/node.dart imports meta but is not using it, kind of like similar analyzer warning about "unused import".
With your explanation it's now clear what I've been doing wrong.

This is probably only me but I think wording in this suggestion could be improved to something like "This package imports meta but does not have it listed in dependencies section."

Also this sounds more like a "warning" than "suggestion" to me. I'm surprised Pub allows me to publish my packages in such state.

Rob Becker

unread,
Jul 23, 2018, 2:38:30 PM7/23/18
to Dart Misc, anatoly.p...@gmail.com
To check your dependencies, you can use https://pub.dartlang.org/packages/dependency_validator

'Kevin Moore' via Dart Announcements

unread,
Jul 25, 2018, 4:50:34 PM7/25/18
to Dart Announcements
If you'd like to verify that your package and all of your dependencies are ready for Dart 2, you can set an environment variable to force the pub client to run as if the current SDK is the stable release.

On Linux and Mac:

$> _PUB_TEST_SDK_VERSION=2.0.0 pub upgrade

On Windows, you can use the setx command then run pub upgrade.

If the command succeeds, you can be confident SDK Constraints won't cause problems when Dart 2 stable is released.

If the command fails, look at the output to determine which packages need to be fixed.

$> _PUB_TEST_SDK_VERSION=2.0.0 pub upgrade
Resolving dependencies... (5.2s)
The current Dart SDK version is 2.0.0.

Because repo_manager depends on gviz >=0.1.0 which requires SDK version >=1.20.1 <2.0.0, version solving failed.

In this case, we should file an issue (or, better yet, a pull request) on the gviz package to be updated.

You can also use _PUB_TEST_SDK_VERSION to control the behavior of the pub client after Dart 2 is released if you some of your dependencies have not yet been updated.

Note: _PUB_TEST_SDK_VERSION was implemented to support testing the pub client. It may change or be removed at any point. Avoid using it in production environments.
Reply all
Reply to author
Forward
0 new messages