Skip to content

Upgrade to the latest source_gen #260

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

Merged
merged 6 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
which allows `TypeHelper` instances to add additional members when handling
a field. This is useful for generating shared helpers, for instance.

* **BREAKING** The `header` option is no longer supported and must be removed
from `build.yaml`.

* If a manual build script is used the `json_serializable` builder must be
switched to `hideOutput: true`, and the `combiningBuilder` from `source_gen`
must be included following this builder. When using a generated build script
with `pub run build_runner` or `webdev` this is handled automatically.

## 0.5.8+1

* Support the Dart 2.0 stable release.
Expand Down
11 changes: 0 additions & 11 deletions json_serializable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ targets:
builders:
json_serializable:
options:
# Specifies a string to add to the top of every generated file.
#
# If not specified, the default is the value of `defaultFileHeader`
# defined in `package:source_gen/source_gen.dart`.
#
# Note: use `|` to define a multi-line block.
header: |
// Copyright (c) 2018, the Dart project authors.

// GENERATED CODE - DO NOT MODIFY BY HAND

# Options configure how source code is generated for every
# `@JsonSerializable`-annotated class in the package.
#
Expand Down
5 changes: 3 additions & 2 deletions json_serializable/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ builders:
json_serializable:
import: "package:json_serializable/builder.dart"
builder_factories: ["jsonSerializable"]
build_extensions: {".dart": [".g.dart"]}
build_extensions: {".dart": ["json_serializable.g.part"]}
auto_apply: dependents
build_to: source
build_to: cache
applies_builders: ["source_gen|combining_builder"]
4 changes: 0 additions & 4 deletions json_serializable/example/example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion json_serializable/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Builder jsonSerializable(BuilderOptions options) {
var optionsMap = new Map<String, dynamic>.from(options.config);

var builder = jsonPartBuilder(
header: optionsMap.remove('header') as String,
useWrappers: optionsMap.remove('use_wrappers') as bool,
checked: optionsMap.remove('checked') as bool,
anyMap: optionsMap.remove('any_map') as bool,
Expand Down
9 changes: 2 additions & 7 deletions json_serializable/lib/src/json_part_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,20 @@ import 'json_serializable_generator.dart';
/// Returns a [Builder] for use within a `package:build_runner`
/// `BuildAction`.
///
/// [header] is used to specify the content at the top of each generated file.
/// If `null`, the content of [defaultFileHeader] is used.
/// If [header] is an empty `String` no header is added.
///
/// [formatOutput] is called to format the generated code. If not provided,
/// the default Dart code formatter is used.
///
/// For details on [useWrappers], [anyMap], and [checked] see
/// [JsonSerializableGenerator].
Builder jsonPartBuilder({
String header,
String formatOutput(String code),
bool useWrappers = false,
bool anyMap = false,
bool checked = false,
bool explicitToJson = false,
bool generateToJsonFunction = true,
}) {
return new PartBuilder([
return new SharedPartBuilder([
new JsonSerializableGenerator(
useWrappers: useWrappers,
anyMap: anyMap,
Expand All @@ -38,5 +33,5 @@ Builder jsonPartBuilder({
generateToJsonFunction: generateToJsonFunction,
),
const JsonLiteralGenerator()
], header: header, formatOutput: formatOutput);
], 'json_serializable', formatOutput: formatOutput);
}
2 changes: 1 addition & 1 deletion json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
json_annotation: '>=0.3.0 <0.3.1'
meta: ^1.1.0
path: ^1.3.2
source_gen: ^0.8.3
source_gen: ^0.9.0

dev_dependencies:
build_runner: ^0.9.0
Expand Down
13 changes: 4 additions & 9 deletions json_serializable/test/config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'dart:io';
import 'package:build/build.dart';
import 'package:json_serializable/builder.dart';
import 'package:logging/logging.dart';
import 'package:source_gen/source_gen.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';

Expand All @@ -31,14 +30,13 @@ void main() {
setUp(records.clear);

test('empty', () async {
var builder = jsonSerializable(BuilderOptions.empty) as PartBuilder;
var builder = jsonSerializable(BuilderOptions.empty);
expect(builder, isNotNull);
expect(records, isEmpty);
});

test('valid config', () async {
var builder =
jsonSerializable(const BuilderOptions(_validConfig)) as PartBuilder;
var builder = jsonSerializable(const BuilderOptions(_validConfig));
expect(builder, isNotNull);

expect(records, isEmpty);
Expand Down Expand Up @@ -68,15 +66,14 @@ void main() {

expect(config.keys, unorderedEquals(_validConfig.keys));

var builder = jsonSerializable(new BuilderOptions(config)) as PartBuilder;
var builder = jsonSerializable(new BuilderOptions(config));
expect(builder, isNotNull);
expect(records, isEmpty);
});

test('unsupported configuration', () async {
var builder =
jsonSerializable(const BuilderOptions(const {'unsupported': 'config'}))
as PartBuilder;
jsonSerializable(const BuilderOptions(const {'unsupported': 'config'}));
expect(builder, isNotNull);

expect(records.single.message,
Expand All @@ -97,7 +94,6 @@ void main() {
}

const _validConfig = const {
'header': 'header',
'use_wrappers': true,
'any_map': true,
'checked': true,
Expand All @@ -106,7 +102,6 @@ const _validConfig = const {
};

const _invalidConfig = const {
'header': true,
'use_wrappers': 42,
'any_map': 42,
'checked': 42,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions json_serializable/test/default_value/default_value.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions json_serializable/test/generic_files/generic_class.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions json_serializable/test/integration/json_test_example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions json_serializable/test/kitchen_sink/kitchen_sink.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions json_serializable/test/kitchen_sink/simple_object.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions json_serializable/test/kitchen_sink/strict_keys_object.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions json_serializable/test/literal/json_literal.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions json_serializable/test/yaml/build_config.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 20 additions & 10 deletions json_serializable/tool/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:build_config/build_config.dart';
import 'package:build_runner/build_runner.dart';
import 'package:build_test/builder.dart';
import 'package:json_serializable/src/json_part_builder.dart' as jpb;
import 'package:source_gen/builder.dart';

import 'builder.dart';

Expand All @@ -28,7 +29,6 @@ Builder _jsonPartBuilder({
}

return jpb.jsonPartBuilder(
header: copyrightHeader,
formatOutput: formatOutput,
useWrappers: useWrappers,
anyMap: anyMap,
Expand Down Expand Up @@ -63,14 +63,16 @@ final List<BuilderApplication> builders = [
'test/integration/json_test_example.dart',
'test/integration/json_test_example.non_nullable.dart'
],
)),
),
hideOutput: true),
applyToRoot(_jsonPartBuilder(),
generateFor: const InputSet(
include: const [
'test/generic_files/generic_class.dart',
'test/default_value/default_value.dart',
],
)),
),
hideOutput: true),
applyToRoot(_jsonPartBuilder(anyMap: true, generateToJsonFunction: false),
generateFor: const InputSet(
include: const [
Expand All @@ -79,47 +81,55 @@ final List<BuilderApplication> builders = [
'test/kitchen_sink/simple_object.dart',
'test/kitchen_sink/strict_keys_object.dart'
],
)),
),
hideOutput: true),
applyToRoot(
_jsonPartBuilder(
checked: true, anyMap: true, generateToJsonFunction: false),
generateFor: const InputSet(
include: const [
'test/kitchen_sink/kitchen_sink.non_nullable.checked.dart',
],
)),
),
hideOutput: true),
applyToRoot(_jsonPartBuilder(checked: true, anyMap: true),
generateFor: const InputSet(
include: const [
'test/yaml/build_config.dart',
],
)),
),
hideOutput: true),
applyToRoot(_jsonPartBuilder(checked: true, anyMap: true),
generateFor: const InputSet(
include: const [
'test/default_value/default_value.checked.dart',
],
)),
),
hideOutput: true),
applyToRoot(_jsonPartBuilder(useWrappers: true),
generateFor: const InputSet(
include: const [
'test/integration/json_test_example*wrapped.dart',
],
)),
),
hideOutput: true),
applyToRoot(_jsonPartBuilder(useWrappers: true),
generateFor: const InputSet(
include: const [
'test/generic_files/generic_class*wrapped.dart',
],
)),
),
hideOutput: true),
applyToRoot(
_jsonPartBuilder(
useWrappers: true, anyMap: true, generateToJsonFunction: false),
generateFor: const InputSet(
include: const [
'test/kitchen_sink/kitchen_sink*wrapped.dart',
],
)),
),
hideOutput: true),
applyToRoot(combiningBuilder()),
applyToRoot(testBootstrapBuilder(null),
generateFor: const InputSet(include: const ['test/**']),
hideOutput: true),
Expand Down