Skip to content

Commit

Permalink
Support latest packages, bump min SDK to 3.6 (#1465)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Dec 17, 2024
1 parent d3cee99 commit 52c25cc
Show file tree
Hide file tree
Showing 33 changed files with 112 additions and 80 deletions.
60 changes: 30 additions & 30 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ jobs:
- name: mono_repo self validate
run: dart pub global run mono_repo generate --validate
job_002:
name: "analyzer_and_format; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`"
name: "analyzer_and_format; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dart analyze`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:analyze_1"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: "3.5.0"
sdk: "3.6.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand Down Expand Up @@ -192,23 +192,23 @@ jobs:
if: "always() && steps.json_serializable_pub_upgrade.conclusion == 'success'"
working-directory: json_serializable
job_004:
name: "unit_test; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`"
name: "unit_test; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `dart test`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example-json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example-json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: "3.5.0"
sdk: "3.6.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand Down Expand Up @@ -253,23 +253,23 @@ jobs:
- job_002
- job_003
job_005:
name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`"
name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/annotation_version_test.dart`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_3"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_3"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: "3.5.0"
sdk: "3.6.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand All @@ -287,23 +287,23 @@ jobs:
- job_002
- job_003
job_006:
name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`"
name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_1"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_1"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: "3.5.0"
sdk: "3.6.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand All @@ -321,23 +321,23 @@ jobs:
- job_002
- job_003
job_007:
name: "unit_test; Dart 3.5.0; PKG: json_serializable; `dart test -p chrome`"
name: "unit_test; Dart 3.6.0; PKG: json_serializable; `dart test -p chrome`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable;commands:test_2"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable;commands:test_2"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:json_serializable
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: "3.5.0"
sdk: "3.6.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand Down Expand Up @@ -518,23 +518,23 @@ jobs:
- job_002
- job_003
job_012:
name: "ensure_build; Dart 3.5.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`"
name: "ensure_build; Dart 3.6.0; PKGS: _test_yaml, checked_yaml, example; `dart test --run-skipped -t presubmit-only test/ensure_build_test.dart`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example;commands:test_1"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example;commands:test_1"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:_test_yaml-checked_yaml-example
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:_test_yaml-checked_yaml-example
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: "3.5.0"
sdk: "3.6.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand Down
2 changes: 1 addition & 1 deletion _test_yaml/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: _test_yaml
publish_to: none

environment:
sdk: ^3.5.0
sdk: ^3.6.0

resolution: workspace

Expand Down
2 changes: 1 addition & 1 deletion checked_yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 2.0.4-wip

- Require Dart 3.5
- Require Dart 3.6

## 2.0.3

Expand Down
2 changes: 1 addition & 1 deletion checked_yaml/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ topics:
- codegen

environment:
sdk: ^3.5.0
sdk: ^3.6.0

resolution: workspace

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: example
publish_to: none

environment:
sdk: ^3.5.0
sdk: ^3.6.0

resolution: workspace

Expand Down
2 changes: 1 addition & 1 deletion json_annotation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 4.9.1-wip

- Require Dart 3.5
- Require Dart 3.6

## 4.9.0

Expand Down
2 changes: 1 addition & 1 deletion json_annotation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ topics:
- codegen

environment:
sdk: ^3.5.0
sdk: ^3.6.0

resolution: workspace

Expand Down
5 changes: 5 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 6.9.1

- Support the latest `package:analyzer` and `package:source_gen`.
- Require Dart 3.6

## 6.9.0

- Use conditional map syntax to clean up `null` handling in `toJson` functions.
Expand Down
7 changes: 1 addition & 6 deletions json_serializable/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ Builder jsonSerializable(BuilderOptions options) {
lines.add(e.innerError.toString());
}

throw StateError(
lines
.join('\n')
// TODO(kevmoo) remove when dart-lang/sdk#50756 is fixed!
.replaceAll(" of ' in type cast'", ' in type cast'),
);
throw StateError(lines.join('\n'));
}
}
16 changes: 6 additions & 10 deletions json_serializable/lib/src/field_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +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.

// TODO: Waiting until Dart 3.6 so we can pin a stable Dart SDK compatible w/ latest
// analyzer
// ignore_for_file: deprecated_member_use

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/dart/element/inheritance_manager3.dart' // ignore: implementation_imports
show
Expand Down Expand Up @@ -41,21 +37,21 @@ class _FieldSet implements Comparable<_FieldSet> {

static int _sortByLocation(FieldElement a, FieldElement b) {
final checkerA = TypeChecker.fromStatic(
(a.enclosingElement as InterfaceElement).thisType,
(a.enclosingElement3 as InterfaceElement).thisType,
);

if (!checkerA.isExactly(b.enclosingElement)) {
if (!checkerA.isExactly(b.enclosingElement3)) {
// in this case, you want to prioritize the enclosingElement that is more
// "super".

if (checkerA.isAssignableFrom(b.enclosingElement)) {
if (checkerA.isAssignableFrom(b.enclosingElement3)) {
return -1;
}

final checkerB = TypeChecker.fromStatic(
(b.enclosingElement as InterfaceElement).thisType);
(b.enclosingElement3 as InterfaceElement).thisType);

if (checkerB.isAssignableFrom(a.enclosingElement)) {
if (checkerB.isAssignableFrom(a.enclosingElement3)) {
return 1;
}
}
Expand Down Expand Up @@ -87,7 +83,7 @@ List<FieldElement> createSortedFieldSet(ClassElement element) {

for (final v in manager.getInheritedConcreteMap2(element).values) {
assert(v is! FieldElement);
if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) {
if (_dartCoreObjectChecker.isExactly(v.enclosingElement3)) {
continue;
}

Expand Down
9 changes: 7 additions & 2 deletions json_serializable/lib/src/json_part_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:build/build.dart';
import 'package:dart_style/dart_style.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:source_gen/source_gen.dart';

import 'check_dependencies.dart';
Expand All @@ -18,7 +20,7 @@ import 'settings.dart';
/// [formatOutput] is called to format the generated code. If not provided,
/// the default Dart code formatter is used.
Builder jsonPartBuilder({
String Function(String code)? formatOutput,
String Function(String code, Version languageVersion)? formatOutput,
JsonSerializable? config,
}) {
final settings = Settings(config: config);
Expand All @@ -32,7 +34,7 @@ Builder jsonPartBuilder({
const JsonLiteralGenerator(),
],
'json_serializable',
formatOutput: formatOutput,
formatOutput: formatOutput ?? defaultFormatOutput,
);
}

Expand Down Expand Up @@ -99,3 +101,6 @@ Iterable<String> _normalizeGeneratorOutput(Object? value) {
ArgumentError _argError(Object value) => ArgumentError(
'Must be a String or be an Iterable containing String values. '
'Found `${Error.safeToString(value)}` (${value.runtimeType}).');

String defaultFormatOutput(String code, Version languageVersion) =>
DartFormatter(languageVersion: languageVersion).format(code);
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ _JsonConvertData? _typeConverterFrom(
final annotationElement = match.elementAnnotation?.element;
if (annotationElement is PropertyAccessorElement) {
// ignore: deprecated_member_use
final enclosing = annotationElement.enclosingElement;
final enclosing = annotationElement.enclosingElement3;

var accessString = annotationElement.name;

Expand Down
10 changes: 3 additions & 7 deletions json_serializable/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +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.

// TODO: Waiting until Dart 3.6 so we can pin a stable Dart SDK compatible w/ latest
// analyzer
// ignore_for_file: deprecated_member_use

import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
Expand Down Expand Up @@ -267,15 +263,15 @@ extension ExecutableElementExtension on ExecutableElement {
}

if (this is MethodElement) {
return '${enclosingElement.name}.$name';
return '${enclosingElement3.name}.$name';
}

if (this is ConstructorElement) {
// Ignore the default constructor.
if (name.isEmpty) {
return '${enclosingElement.name}';
return '${enclosingElement3.name}';
}
return '${enclosingElement.name}.$name';
return '${enclosingElement3.name}.$name';
}

throw UnsupportedError(
Expand Down
Loading

0 comments on commit 52c25cc

Please sign in to comment.