Skip to content

Change require library directive default #102

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 3 commits into from
Feb 12, 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
5 changes: 5 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.2

* The `require_library_directive` option now defaults to `false`.
The option will be removed entirely in `0.4.0`.

## 0.3.1+2

* Support the latest version of the `analyzer` package.
Expand Down
3 changes: 2 additions & 1 deletion json_serializable/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ import 'json_serializable.dart';
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 ?? true);
options.config['require_library_directive'] as bool ?? false);
18 changes: 13 additions & 5 deletions json_serializable/lib/src/json_part_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// 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 @@ -23,9 +26,11 @@ import 'json_serializable_generator.dart';
/// increase the code size, but it may improve runtime performance, especially
/// for large object graphs.
///
/// May set [requireLibraryDirective] to `false` in order to opt-in to
/// supporting a Dart v2 feature of `part of` being usable without an explicit
/// `library` directive. Developers should restrict their `pubspec` accordingly:
/// 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'
/// ```
Expand All @@ -47,9 +52,12 @@ import 'json_serializable_generator.dart';
Builder jsonPartBuilder(
{String header,
bool useWrappers: false,
bool requireLibraryDirective: true}) {
@Deprecated(
'Library directives are no longer required for part generation. '
'This option will be removed in v0.4.0.')
bool requireLibraryDirective: false}) {
useWrappers ??= false;
requireLibraryDirective ??= true;
requireLibraryDirective ??= false;
return new PartBuilder([
new JsonSerializableGenerator(useWrappers: useWrappers),
const JsonLiteralGenerator()
Expand Down
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.3.1+2
version: 0.3.2
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.2 <0.2.3'
path: ^1.3.2
source_gen: ^0.7.1
source_gen: ^0.7.5
dev_dependencies:
build_runner: ^0.7.0
build_test: ">=0.9.0 <0.11.0"
Expand Down
2 changes: 0 additions & 2 deletions json_serializable/test/test_files/json_literal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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.

library json_serializable.example;

import 'package:json_annotation/json_annotation.dart';
part 'json_literal.g.dart';

Expand Down
2 changes: 1 addition & 1 deletion json_serializable/test/test_files/json_literal.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.example;
part of 'json_literal.dart';

// **************************************************************************
// Generator: JsonLiteralGenerator
Expand Down
2 changes: 0 additions & 2 deletions json_serializable/test/test_files/json_test_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: annotate_overrides, hash_and_equals
library json_serializable.test.json_test_example;

import 'dart:collection';

import 'package:collection/collection.dart';
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/test/test_files/json_test_example.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.test.json_test_example;
part of 'json_test_example.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// **************************************************************************

// ignore_for_file: annotate_overrides, hash_and_equals
library json_serializable.test.json_test_example.non_nullable;

import 'dart:collection';

import 'package:collection/collection.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.test.json_test_example.non_nullable;
part of 'json_test_example.non_nullable.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// **************************************************************************

// ignore_for_file: annotate_overrides, hash_and_equals
library json_serializable.test.json_test_example.non_nullable_wrapped;

import 'dart:collection';

import 'package:collection/collection.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.test.json_test_example.non_nullable_wrapped;
part of 'json_test_example.non_nullable.wrapped.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// **************************************************************************

// ignore_for_file: annotate_overrides, hash_and_equals
library json_serializable.test.json_test_example_wrapped;

import 'dart:collection';

import 'package:collection/collection.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.test.json_test_example_wrapped;
part of 'json_test_example.wrapped.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
Expand Down
2 changes: 0 additions & 2 deletions json_serializable/test/test_files/kitchen_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: annotate_overrides, hash_and_equals
library json_serializable.test.kitchen_sink;

import 'package:json_annotation/json_annotation.dart';

import 'kitchen_sink_interface.dart' as k;
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/test/test_files/kitchen_sink.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.test.kitchen_sink;
part of 'kitchen_sink.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// **************************************************************************

// ignore_for_file: annotate_overrides, hash_and_equals
library json_serializable.test.kitchen_sink.non_nullable;

import 'package:json_annotation/json_annotation.dart';

import 'kitchen_sink_interface.dart' as k;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.test.kitchen_sink.non_nullable;
part of 'kitchen_sink.non_nullable.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// **************************************************************************

// ignore_for_file: annotate_overrides, hash_and_equals
library json_serializable.test.kitchen_sink.non_nullable_wrapped;

import 'package:json_annotation/json_annotation.dart';

import 'kitchen_sink_interface.dart' as k;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.test.kitchen_sink.non_nullable_wrapped;
part of 'kitchen_sink.non_nullable.wrapped.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
Expand Down
2 changes: 0 additions & 2 deletions json_serializable/test/test_files/kitchen_sink.wrapped.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// **************************************************************************

// ignore_for_file: annotate_overrides, hash_and_equals
library json_serializable.test.kitchen_sink_wrapped;

import 'package:json_annotation/json_annotation.dart';

import 'kitchen_sink_interface.dart' as k;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// GENERATED CODE - DO NOT MODIFY BY HAND

part of json_serializable.test.kitchen_sink_wrapped;
part of 'kitchen_sink.wrapped.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
Expand Down
4 changes: 0 additions & 4 deletions json_serializable/tool/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class _NonNullableGenerator extends Generator {
final content = await buildStep.readAsString(buildStep.inputId);
var replacements = <_Replacement>[
new _Replacement(_copyrightContent, ''),
new _Replacement('library ${buildStep.inputId.package}.test.$baseName',
'library ${buildStep.inputId.package}.test.${baseName}.non_nullable'),
new _Replacement(
"part '${baseName}.g.dart",
"part '${baseName}.non_nullable.g.dart",
Expand Down Expand Up @@ -99,8 +97,6 @@ class _WrappedGenerator extends Generator {
final content = await buildStep.readAsString(buildStep.inputId);
var replacements = <_Replacement>[
new _Replacement(_copyrightContent, ''),
new _Replacement('library ${buildStep.inputId.package}.test.$baseName',
'library ${buildStep.inputId.package}.test.${baseName}_wrapped'),
new _Replacement(
"part '${baseName}.g.dart",
"part '${baseName}.wrapped.g.dart",
Expand Down