Skip to content

Commit f01e5ce

Browse files
authored
Change require library directive default (#102)
1 parent 5c4fa3e commit f01e5ce

23 files changed

+31
-39
lines changed

json_serializable/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.2
2+
3+
* The `require_library_directive` option now defaults to `false`.
4+
The option will be removed entirely in `0.4.0`.
5+
16
## 0.3.1+2
27

38
* Support the latest version of the `analyzer` package.

json_serializable/lib/builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ import 'json_serializable.dart';
99
Builder jsonSerializable(BuilderOptions options) => jsonPartBuilder(
1010
header: options.config['header'] as String,
1111
useWrappers: options.config['use_wrappers'] as bool ?? false,
12+
// ignore: deprecated_member_use
1213
requireLibraryDirective:
13-
options.config['require_library_directive'] as bool ?? true);
14+
options.config['require_library_directive'] as bool ?? false);

json_serializable/lib/src/json_part_builder.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
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+
811
import 'package:build/build.dart';
912
import 'package:source_gen/source_gen.dart';
1013

@@ -23,9 +26,11 @@ import 'json_serializable_generator.dart';
2326
/// increase the code size, but it may improve runtime performance, especially
2427
/// for large object graphs.
2528
///
26-
/// May set [requireLibraryDirective] to `false` in order to opt-in to
27-
/// supporting a Dart v2 feature of `part of` being usable without an explicit
28-
/// `library` directive. Developers should restrict their `pubspec` accordingly:
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+
///
2934
/// ```yaml
3035
/// sdk: '>=2.0.0-dev <2.0.0'
3136
/// ```
@@ -47,9 +52,12 @@ import 'json_serializable_generator.dart';
4752
Builder jsonPartBuilder(
4853
{String header,
4954
bool useWrappers: false,
50-
bool requireLibraryDirective: true}) {
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}) {
5159
useWrappers ??= false;
52-
requireLibraryDirective ??= true;
60+
requireLibraryDirective ??= false;
5361
return new PartBuilder([
5462
new JsonSerializableGenerator(useWrappers: useWrappers),
5563
const JsonLiteralGenerator()

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.3.1+2
2+
version: 0.3.2
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.2 <0.2.3'
1717
path: ^1.3.2
18-
source_gen: ^0.7.1
18+
source_gen: ^0.7.5
1919
dev_dependencies:
2020
build_runner: ^0.7.0
2121
build_test: ">=0.9.0 <0.11.0"

json_serializable/test/test_files/json_literal.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +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-
library json_serializable.example;
6-
75
import 'package:json_annotation/json_annotation.dart';
86
part 'json_literal.g.dart';
97

json_serializable/test/test_files/json_literal.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.example;
7+
part of 'json_literal.dart';
88

99
// **************************************************************************
1010
// Generator: JsonLiteralGenerator

json_serializable/test/test_files/json_test_example.dart

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

55
// ignore_for_file: annotate_overrides, hash_and_equals
6-
library json_serializable.test.json_test_example;
7-
86
import 'dart:collection';
97

108
import 'package:collection/collection.dart';

json_serializable/test/test_files/json_test_example.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.test.json_test_example;
7+
part of 'json_test_example.dart';
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

json_serializable/test/test_files/json_test_example.non_nullable.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// **************************************************************************
1010

1111
// ignore_for_file: annotate_overrides, hash_and_equals
12-
library json_serializable.test.json_test_example.non_nullable;
13-
1412
import 'dart:collection';
1513

1614
import 'package:collection/collection.dart';

json_serializable/test/test_files/json_test_example.non_nullable.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.test.json_test_example.non_nullable;
7+
part of 'json_test_example.non_nullable.dart';
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

json_serializable/test/test_files/json_test_example.non_nullable.wrapped.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
// **************************************************************************
1616

1717
// ignore_for_file: annotate_overrides, hash_and_equals
18-
library json_serializable.test.json_test_example.non_nullable_wrapped;
19-
2018
import 'dart:collection';
2119

2220
import 'package:collection/collection.dart';

json_serializable/test/test_files/json_test_example.non_nullable.wrapped.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.test.json_test_example.non_nullable_wrapped;
7+
part of 'json_test_example.non_nullable.wrapped.dart';
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

json_serializable/test/test_files/json_test_example.wrapped.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// **************************************************************************
1010

1111
// ignore_for_file: annotate_overrides, hash_and_equals
12-
library json_serializable.test.json_test_example_wrapped;
13-
1412
import 'dart:collection';
1513

1614
import 'package:collection/collection.dart';

json_serializable/test/test_files/json_test_example.wrapped.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.test.json_test_example_wrapped;
7+
part of 'json_test_example.wrapped.dart';
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

json_serializable/test/test_files/kitchen_sink.dart

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

55
// ignore_for_file: annotate_overrides, hash_and_equals
6-
library json_serializable.test.kitchen_sink;
7-
86
import 'package:json_annotation/json_annotation.dart';
97

108
import 'kitchen_sink_interface.dart' as k;

json_serializable/test/test_files/kitchen_sink.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.test.kitchen_sink;
7+
part of 'kitchen_sink.dart';
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

json_serializable/test/test_files/kitchen_sink.non_nullable.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// **************************************************************************
1010

1111
// ignore_for_file: annotate_overrides, hash_and_equals
12-
library json_serializable.test.kitchen_sink.non_nullable;
13-
1412
import 'package:json_annotation/json_annotation.dart';
1513

1614
import 'kitchen_sink_interface.dart' as k;

json_serializable/test/test_files/kitchen_sink.non_nullable.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.test.kitchen_sink.non_nullable;
7+
part of 'kitchen_sink.non_nullable.dart';
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

json_serializable/test/test_files/kitchen_sink.non_nullable.wrapped.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
// **************************************************************************
1616

1717
// ignore_for_file: annotate_overrides, hash_and_equals
18-
library json_serializable.test.kitchen_sink.non_nullable_wrapped;
19-
2018
import 'package:json_annotation/json_annotation.dart';
2119

2220
import 'kitchen_sink_interface.dart' as k;

json_serializable/test/test_files/kitchen_sink.non_nullable.wrapped.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.test.kitchen_sink.non_nullable_wrapped;
7+
part of 'kitchen_sink.non_nullable.wrapped.dart';
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

json_serializable/test/test_files/kitchen_sink.wrapped.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// **************************************************************************
1010

1111
// ignore_for_file: annotate_overrides, hash_and_equals
12-
library json_serializable.test.kitchen_sink_wrapped;
13-
1412
import 'package:json_annotation/json_annotation.dart';
1513

1614
import 'kitchen_sink_interface.dart' as k;

json_serializable/test/test_files/kitchen_sink.wrapped.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.test.kitchen_sink_wrapped;
7+
part of 'kitchen_sink.wrapped.dart';
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

json_serializable/tool/build.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class _NonNullableGenerator extends Generator {
6565
final content = await buildStep.readAsString(buildStep.inputId);
6666
var replacements = <_Replacement>[
6767
new _Replacement(_copyrightContent, ''),
68-
new _Replacement('library ${buildStep.inputId.package}.test.$baseName',
69-
'library ${buildStep.inputId.package}.test.${baseName}.non_nullable'),
7068
new _Replacement(
7169
"part '${baseName}.g.dart",
7270
"part '${baseName}.non_nullable.g.dart",
@@ -99,8 +97,6 @@ class _WrappedGenerator extends Generator {
9997
final content = await buildStep.readAsString(buildStep.inputId);
10098
var replacements = <_Replacement>[
10199
new _Replacement(_copyrightContent, ''),
102-
new _Replacement('library ${buildStep.inputId.package}.test.$baseName',
103-
'library ${buildStep.inputId.package}.test.${baseName}_wrapped'),
104100
new _Replacement(
105101
"part '${baseName}.g.dart",
106102
"part '${baseName}.wrapped.g.dart",

0 commit comments

Comments
 (0)