Upgrading source_gen 0.6 to 0.7
Breaking0.6.1+1 → 0.7.6Breaking7Platform1Deprecated2New11Changed9Fixed5
BreakingUpgrade verdict
7 breaking changes and a platform requirement change.
In plain terms
- JSON serialization support is no longer in this package; use package:json_serializable instead.
- The separate builder import path is gone; import the main library instead.
- The OutputFormatter type alias no longer exists.
- Code generators can now return either a string or a future of a string.
Must act Top 5 of 10 that need code or config changes
source_gen publishes an official migration guide for version 0.7. It covers more than the release notes do.
The wiki ↗Dart SDK requirement changed in 0.7.5: >=1.22.1 <2.0.0 → >=2.0.0-dev.19.0 <2.0.0.
What you must change
Breaking7
Removes JsonSerializable and related classes, which move to package:json_serializable.
JsonSerializableRemoves lib/builder.dart; import through source_gen.dart instead.
lib/builder.dartsource_gen.dartRemoves the OutputFormatter typedef.
OutputFormatterThe return type of
generate{ForAnnotatedElement} is now FutureOr<String>.generate{ForAnnotatedElement}FutureOr<String>Generator.generate now operates on a LibraryReader instead of being called for every Element within a library.
Generator.generateLibraryReaderLibraryReader.allElementsGeneratorForAnnotationgenerateForAnnotatedElementGeneratorForAnnotation passes a ConstantReader for the annotation instance instead of re-creating it using mirrors.
GeneratorForAnnotationConstantReaderGeneratorBuilder is replaced with PartBuilder and LibraryBuilder depending on whether output goes in a part file.
GeneratorBuilderPartBuilderLibraryBuilderPlatform1
Requires at least Dart
2.0.0-dev.19.0.Deprecations to plan for
Deprecated2
Adds
isAny for consistency but marks it deprecated.ConstantReader.isAnyConstantReader.isLiteralAdds
literalValue as an alias for the now deprecated anyValue.ConstantReader.literalValueConstantReader.anyValue