Skip to content

No source gen dep #85

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 2 commits into from
Dec 15, 2017
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
9 changes: 0 additions & 9 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,3 @@ dev_dependencies:

# A great Dart testing package, but not required to use `json_serializable`.
test: ^0.12.29

# Don't copy `dependency_overrides` into your `pubspec.yaml`
# Here to ensure compatibility with the packages in this repository during
# development.
dependency_overrides:
json_annotation:
path: ../json_annotation
json_serializable:
path: ../json_serializable
8 changes: 8 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## 0.3.0

* **NEW** top-level library `json_serializable.dart`.

* Replaces now deprecated `generators.dart` to access
`JsonSerializableGenerator` and `JsonLiteralGenerator`.

* Adds the `jsonPartBuilder` function to make it easy to create a
`PartBuilder`, without creating an explicit dependency on `source_gen`.

* **BREAKING** `UnsupportedTypeError` added a new required constructor argument:
`reason`.

Expand Down
6 changes: 5 additions & 1 deletion json_serializable/lib/generators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// Generator classes.
/// **DEPRECATED** import `package:json_serializable/json_serializable.dart`
/// instead.
@Deprecated(
'import `package:json_serializable/json_serializable.dart` instead.')
library json_serializable.generators;

export 'src/json_literal_generator.dart';
export 'src/json_serializable_generator.dart';
7 changes: 7 additions & 0 deletions json_serializable/lib/json_serializable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'src/json_literal_generator.dart';
export 'src/json_part_builder.dart';
export 'src/json_serializable_generator.dart';
43 changes: 43 additions & 0 deletions json_serializable/lib/src/json_part_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:build/build.dart';
import 'package:source_gen/source_gen.dart';

import 'json_literal_generator.dart';
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.
///
/// If [useWrappers] is `true`, wrappers are used to minimize the number of
/// [Map] and [List] instances created during serialization. This will
/// increase the code size, but it may improve runtime performance, especially
/// for large object graphs.
///
/// Usage:
///
/// ```dart
/// new BuildAction(
/// jsonPartBuilder(),
/// 'my_package',
/// inputs: const ['lib/*.dart']
/// )
/// ```
///
/// See the [example] to understand how to configure your project for
/// `json_serializable`.
///
/// [example]: https://github.com/dart-lang/json_serializable/tree/master/example
Builder jsonPartBuilder({String header, bool useWrappers: false}) {
useWrappers ??= false;
return new PartBuilder([
new JsonSerializableGenerator(useWrappers: useWrappers),
const JsonLiteralGenerator()
], header: header);
}
5 changes: 5 additions & 0 deletions json_serializable/lib/src/json_serializable_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class JsonSerializableGenerator
///
/// If [typeHelpers] is not provided, two built-in helpers are used:
/// [JsonHelper] and [DateTimeHelper].
///
/// If [useWrappers] is `true`, wrappers are used to minimize the number of
/// [Map] and [List] instances created during serialization. This will
/// increase the code size, but it may improve runtime performance, especially
/// for large object graphs.
const JsonSerializableGenerator(
{List<TypeHelper> typeHelpers, bool useWrappers: false})
: this.useWrappers = useWrappers ?? false,
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/test/json_serializable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'dart:async';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/src/string_source.dart';
import 'package:dart_style/dart_style.dart' as dart_style;
import 'package:json_serializable/generators.dart';
import 'package:json_serializable/json_serializable.dart';
import 'package:json_serializable/src/utils.dart';
import 'package:path/path.dart' as p;
import 'package:source_gen/source_gen.dart';
Expand Down
9 changes: 3 additions & 6 deletions json_serializable/tool/build_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:async';
import 'package:build/build.dart';

import 'package:build_runner/build_runner.dart';
import 'package:json_serializable/generators.dart';
import 'package:json_serializable/json_serializable.dart';
import 'package:path/path.dart' as p;
import 'package:source_gen/source_gen.dart';

Expand All @@ -31,9 +31,7 @@ final List<BuildAction> buildActions = [
'test/test_files/json_test_example.non_nullable.dart',
]),
new BuildAction(
new PartBuilder(
const [const JsonSerializableGenerator(), const JsonLiteralGenerator()],
header: _copyrightHeader),
jsonPartBuilder(header: _copyrightHeader),
'json_serializable',
inputs: const [
'test/test_files/json_literal.dart',
Expand All @@ -44,8 +42,7 @@ final List<BuildAction> buildActions = [
],
),
new BuildAction(
new PartBuilder(const [const JsonSerializableGenerator(useWrappers: true)],
header: _copyrightHeader),
jsonPartBuilder(useWrappers: true, header: _copyrightHeader),
'json_serializable',
inputs: const [
'test/test_files/kitchen_sink*wrapped.dart',
Expand Down