Skip to content

Commit 0084d31

Browse files
committed
Removed deprecated support for require_library_directive
...and support the latest `package:source_gen`.
1 parent 805a9c6 commit 0084d31

File tree

5 files changed

+32
-39
lines changed

5 files changed

+32
-39
lines changed

json_serializable/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## 0.4.1
1+
## 0.5.0
2+
3+
* **BREAKING** Removed deprecated support for `require_library_directive` /
4+
`requireLibraryDirective` in `build_runner` configuration.
5+
6+
* Support the latest `package:source_gen`.
27

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

json_serializable/lib/builder.dart

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,28 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:build/build.dart';
6+
import 'package:logging/logging.dart';
67

78
import 'json_serializable.dart';
89

9-
Builder jsonSerializable(BuilderOptions options) => jsonPartBuilder(
10-
header: options.config['header'] as String,
11-
useWrappers: options.config['use_wrappers'] as bool ?? false,
12-
// ignore: deprecated_member_use
13-
requireLibraryDirective:
14-
options.config['require_library_directive'] as bool ?? false);
10+
// TODO: until we can use `log` here - github.com/dart-lang/build/issues/1223
11+
final _logger = new Logger('json_serializable');
12+
13+
/// Supports `package:build_runner` creation and configuration of `build_cli`.
14+
///
15+
/// Not meant to be invoked by hand-authored code.
16+
Builder jsonSerializable(BuilderOptions options) {
17+
// Paranoid copy of options.config - don't assume it's mutable or needed
18+
// elsewhere.
19+
var optionsMap = new Map<String, dynamic>.from(options.config);
20+
21+
try {
22+
return jsonPartBuilder(
23+
header: optionsMap.remove('header') as String,
24+
useWrappers: optionsMap.remove('use_wrappers') as bool);
25+
} finally {
26+
if (optionsMap.isNotEmpty) {
27+
_logger.warning('These options were ignored: `$optionsMap`.');
28+
}
29+
}
30+
}

json_serializable/lib/src/json_part_builder.dart

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
// https://github.com/dart-lang/sdk/issues/31761
66
// ignore_for_file: comment_references
77

8-
// Until `requireLibraryDirective` is removed
9-
// ignore_for_file: deprecated_member_use
10-
118
import 'package:build/build.dart';
129
import 'package:source_gen/source_gen.dart';
1310

@@ -26,15 +23,6 @@ import 'json_serializable_generator.dart';
2623
/// increase the code size, but it may improve runtime performance, especially
2724
/// for large object graphs.
2825
///
29-
/// May set [requireLibraryDirective] to `true` in order to opt-out of the
30-
/// Dart `2.0.0-dev` feature of `part of` being usable without an explicit
31-
/// `library` directive. Developers should restrict the SDK constraint in
32-
/// `pubspec.yaml` accordingly:
33-
///
34-
/// ```yaml
35-
/// sdk: '>=2.0.0-dev <2.0.0'
36-
/// ```
37-
///
3826
/// Usage:
3927
///
4028
/// ```dart
@@ -49,20 +37,10 @@ import 'json_serializable_generator.dart';
4937
/// `json_serializable`.
5038
///
5139
/// [example]: https://github.com/dart-lang/json_serializable/tree/master/example
52-
Builder jsonPartBuilder(
53-
{String header,
54-
bool useWrappers: false,
55-
@Deprecated(
56-
'Library directives are no longer required for part generation. '
57-
'This option will be removed in v0.4.0.')
58-
bool requireLibraryDirective: false}) {
40+
Builder jsonPartBuilder({String header, bool useWrappers: false}) {
5941
useWrappers ??= false;
60-
requireLibraryDirective ??= false;
6142
return new PartBuilder([
6243
new JsonSerializableGenerator(useWrappers: useWrappers),
6344
const JsonLiteralGenerator()
64-
],
65-
header: header,
66-
// ignore: deprecated_member_use
67-
requireLibraryDirective: requireLibraryDirective);
45+
], header: header);
6846
}

json_serializable/lib/src/utils.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:io';
65
import 'package:analyzer/dart/element/element.dart';
76

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

42-
/// Logs to STDERR with wrapper stars to make things readable during build.
43-
void log(object) {
44-
stderr.writeln(['***', object, '***'].join('\n'));
45-
}
46-
4741
final toJsonMapVarName = 'val';
4842
final toJsonMapHelperName = 'writeNotNull';

json_serializable/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_serializable
2-
version: 0.4.1-dev
2+
version: 0.5.0-dev
33
author: Dart Team <misc@dartlang.org>
44
description: Generates utilities to aid in serializing to/from JSON.
55
homepage: https://github.com/dart-lang/json_serializable
@@ -15,7 +15,7 @@ dependencies:
1515
# `json_annotation`. Properly constrains all features it provides.
1616
json_annotation: '>=0.2.3 <0.2.4'
1717
path: ^1.3.2
18-
source_gen: ^0.7.5
18+
source_gen: '>=0.7.5 <0.9.0'
1919
dev_dependencies:
2020
build_runner: ^0.8.0
2121
build_test: ">=0.9.0 <0.11.0"

0 commit comments

Comments
 (0)