Skip to content

latest pkg:source_gen, and a lot of deprecation cleanup #120

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 5 commits into from
Mar 30, 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
21 changes: 16 additions & 5 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
## 0.4.1
## 0.5.0

* **BREAKING** Removed deprecated support for `require_library_directive` /
`requireLibraryDirective` in `build_runner` configuration.

* **BREAKING** Removed the deprecated `generators.dart` library.

* **BREAKING** Removed `jsonPartBuilder` function from public API.

* Support the latest `package:source_gen`.

* Private and ignored fields are now excluded when generating serialization and
deserialization code by using `@JsonKey(ignore: true)`.

* Throw an exception if a private field or an ignored field is referenced by a
required constructor argument.

### `package:json_serializable/type_helper.dart`

* **Potentially Breaking** The `metadata` property on `SerializeContext` and
`DeserializeContext` is now readonly. This would potentially break code that
extends these classes – which is not expected.

* Private and ignored fields are now excluded when generating serialization and deserialization code.

* Throw an exception if a private field, or an ignored field is referenced by a required constructor argument.

## 0.4.0

* **Potentially Breaking** Inherited fields are now processed and used
Expand Down
40 changes: 33 additions & 7 deletions json_serializable/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,39 @@
// 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.

/// Configuration for using `package:build`-compatible build systems.
///
/// See:
/// * [build_runner](https://pub.dartlang.org/packages/build_runner)
///
/// This library is **not** intended to be imported by typical end-users unless
/// you are creating a custom compilation pipeline. See documentation for
/// details, and `build.yaml` for how these builders are configured by default.
library json_serializable.builder;

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

import 'src/json_part_builder.dart';

// TODO: until we can use `log` here - github.com/dart-lang/build/issues/1223
final _logger = new Logger('json_serializable');

import 'json_serializable.dart';
/// Supports `package:build_runner` creation and configuration of `build_cli`.
///
/// Not meant to be invoked by hand-authored code.
Builder jsonSerializable(BuilderOptions options) {
// Paranoid copy of options.config - don't assume it's mutable or needed
// elsewhere.
var optionsMap = new Map<String, dynamic>.from(options.config);

Builder jsonSerializable(BuilderOptions options) => jsonPartBuilder(
header: options.config['header'] as String,
useWrappers: options.config['use_wrappers'] as bool ?? false,
// ignore: deprecated_member_use
requireLibraryDirective:
options.config['require_library_directive'] as bool ?? false);
try {
return jsonPartBuilder(
header: optionsMap.remove('header') as String,
useWrappers: optionsMap.remove('use_wrappers') as bool);
} finally {
if (optionsMap.isNotEmpty) {
_logger.warning('These options were ignored: `$optionsMap`.');
}
}
}
12 changes: 0 additions & 12 deletions json_serializable/lib/generators.dart

This file was deleted.

1 change: 0 additions & 1 deletion json_serializable/lib/json_serializable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
// 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';
44 changes: 2 additions & 42 deletions json_serializable/lib/src/json_part_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
// 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.

// https://github.com/dart-lang/sdk/issues/31761
// ignore_for_file: comment_references

// Until `requireLibraryDirective` is removed
// ignore_for_file: deprecated_member_use

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

Expand All @@ -25,44 +19,10 @@ import 'json_serializable_generator.dart';
/// [Map] and [List] instances created during serialization. This will
/// increase the code size, but it may improve runtime performance, especially
/// for large object graphs.
///
/// May set [requireLibraryDirective] to `true` in order to opt-out of the
/// Dart `2.0.0-dev` feature of `part of` being usable without an explicit
/// `library` directive. Developers should restrict the SDK constraint in
/// `pubspec.yaml` accordingly:
///
/// ```yaml
/// sdk: '>=2.0.0-dev <2.0.0'
/// ```
///
/// 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,
@Deprecated(
'Library directives are no longer required for part generation. '
'This option will be removed in v0.4.0.')
bool requireLibraryDirective: false}) {
Builder jsonPartBuilder({String header, bool useWrappers: false}) {
useWrappers ??= false;
requireLibraryDirective ??= false;
return new PartBuilder([
new JsonSerializableGenerator(useWrappers: useWrappers),
const JsonLiteralGenerator()
],
header: header,
// ignore: deprecated_member_use
requireLibraryDirective: requireLibraryDirective);
], header: header);
}
6 changes: 0 additions & 6 deletions json_serializable/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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 'dart:io';
import 'package:analyzer/dart/element/element.dart';

// Copied from pkg/source_gen - lib/src/utils.
Expand Down Expand Up @@ -39,10 +38,5 @@ String friendlyNameForElement(Element element) {
return names.join(' ');
}

/// Logs to STDERR with wrapper stars to make things readable during build.
void log(object) {
stderr.writeln(['***', object, '***'].join('\n'));
}

final toJsonMapVarName = 'val';
final toJsonMapHelperName = 'writeNotNull';
4 changes: 2 additions & 2 deletions json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_serializable
version: 0.4.1-dev
version: 0.5.0-dev
author: Dart Team <misc@dartlang.org>
description: Generates utilities to aid in serializing to/from JSON.
homepage: https://github.com/dart-lang/json_serializable
Expand All @@ -15,7 +15,7 @@ dependencies:
# `json_annotation`. Properly constrains all features it provides.
json_annotation: '>=0.2.3 <0.2.4'
path: ^1.3.2
source_gen: ^0.7.5
source_gen: '>=0.7.5 <0.9.0'
dev_dependencies:
build_runner: ^0.8.0
build_test: ">=0.9.0 <0.11.0"
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/tool/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:async';
import 'package:build/build.dart';
import 'package:build_config/build_config.dart';
import 'package:build_runner/build_runner.dart';
import 'package:json_serializable/json_serializable.dart';
import 'package:json_serializable/src/json_part_builder.dart';
import 'package:path/path.dart' as p;
import 'package:source_gen/source_gen.dart';

Expand Down