Skip to content

Commit d01ba0b

Browse files
authored
Support latest dependencies, prepare release (#177)
Fixes #176
1 parent 58e2fc3 commit d01ba0b

26 files changed

+523
-659
lines changed

.github/workflows/dart.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Created with package:mono_repo v6.6.2
1+
# Created with package:mono_repo v6.6.3
22
name: Dart CI
33
on:
44
push:
@@ -36,27 +36,27 @@ jobs:
3636
name: Checkout repository
3737
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
3838
- name: mono_repo self validate
39-
run: dart pub global activate mono_repo 6.6.2
39+
run: dart pub global activate mono_repo 6.6.3
4040
- name: mono_repo self validate
4141
run: dart pub global run mono_repo generate --validate
4242
job_002:
43-
name: "analyzer_and_format; Dart 3.6.0; PKGS: build_cli, build_cli_annotations; `dart analyze --fatal-infos .`"
43+
name: "analyzer_and_format; Dart 3.8.0; PKGS: build_cli, build_cli_annotations; `dart analyze --fatal-infos .`"
4444
runs-on: ubuntu-latest
4545
steps:
4646
- name: Cache Pub hosted dependencies
4747
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
4848
with:
4949
path: "~/.pub-cache/hosted"
50-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:build_cli-build_cli_annotations;commands:analyze"
50+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:build_cli-build_cli_annotations;commands:analyze"
5151
restore-keys: |
52-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:build_cli-build_cli_annotations
53-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
52+
os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:build_cli-build_cli_annotations
53+
os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0
5454
os:ubuntu-latest;pub-cache-hosted
5555
os:ubuntu-latest
5656
- name: Setup Dart SDK
5757
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
5858
with:
59-
sdk: "3.6.0"
59+
sdk: "3.8.0"
6060
- id: checkout
6161
name: Checkout repository
6262
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
@@ -81,23 +81,23 @@ jobs:
8181
needs:
8282
- job_001
8383
job_003:
84-
name: "analyzer_and_format; Dart 3.6.0; PKGS: build_cli, build_cli_annotations; `dart format --output=none --set-exit-if-changed .`"
84+
name: "analyzer_and_format; Dart 3.8.0; PKGS: build_cli, build_cli_annotations; `dart format --output=none --set-exit-if-changed .`"
8585
runs-on: ubuntu-latest
8686
steps:
8787
- name: Cache Pub hosted dependencies
8888
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
8989
with:
9090
path: "~/.pub-cache/hosted"
91-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:build_cli-build_cli_annotations;commands:format"
91+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:build_cli-build_cli_annotations;commands:format"
9292
restore-keys: |
93-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:build_cli-build_cli_annotations
94-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
93+
os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:build_cli-build_cli_annotations
94+
os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0
9595
os:ubuntu-latest;pub-cache-hosted
9696
os:ubuntu-latest
9797
- name: Setup Dart SDK
9898
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
9999
with:
100-
sdk: "3.6.0"
100+
sdk: "3.8.0"
101101
- id: checkout
102102
name: Checkout repository
103103
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
@@ -204,23 +204,23 @@ jobs:
204204
needs:
205205
- job_001
206206
job_006:
207-
name: "unit_test; Dart 3.6.0; PKG: build_cli; `dart test --run-skipped --reporter expanded`"
207+
name: "unit_test; Dart 3.8.0; PKG: build_cli; `dart test --run-skipped --reporter expanded`"
208208
runs-on: ubuntu-latest
209209
steps:
210210
- name: Cache Pub hosted dependencies
211211
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
212212
with:
213213
path: "~/.pub-cache/hosted"
214-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:build_cli;commands:test"
214+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:build_cli;commands:test"
215215
restore-keys: |
216-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:build_cli
217-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
216+
os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0;packages:build_cli
217+
os:ubuntu-latest;pub-cache-hosted;sdk:3.8.0
218218
os:ubuntu-latest;pub-cache-hosted
219219
os:ubuntu-latest
220220
- name: Setup Dart SDK
221221
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
222222
with:
223-
sdk: "3.6.0"
223+
sdk: "3.8.0"
224224
- id: checkout
225225
name: Checkout repository
226226
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

build_cli/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 2.2.8
2+
3+
- Required `sdk: ^3.8.0`
4+
- Required `analyzer: ^8.1.1`
5+
- Required `build: ^4.0.0`
6+
- Required `build_config: ^1.2.0`
7+
- Required `source_gen: ^4.0.1`
8+
- Required `source_helper: ^1.3.8`
9+
110
## 2.2.7
211

312
- Fix issue with latest version of `package:source_gen`.

build_cli/example/example.g.dart

Lines changed: 15 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_cli/lib/builder.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,5 @@ Builder buildCli(BuilderOptions options) {
1919
);
2020
}
2121

22-
return SharedPartBuilder(
23-
const [
24-
CliGenerator(),
25-
],
26-
'build_cli',
27-
);
22+
return SharedPartBuilder(const [CliGenerator()], 'build_cli');
2823
}

build_cli/lib/src/arg_info.dart

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
import 'package:analyzer/dart/constant/value.dart';
44
import 'package:analyzer/dart/element/element.dart';
5+
import 'package:analyzer/dart/element/element2.dart';
56
import 'package:analyzer/dart/element/type.dart';
67
import 'package:build_cli_annotations/build_cli_annotations.dart';
78
import 'package:source_gen/source_gen.dart';
89
import 'package:source_helper/source_helper.dart';
910

1011
import 'to_share.dart';
1112

12-
const boolChecker = TypeChecker.fromRuntime(bool);
13-
const listChecker = TypeChecker.fromRuntime(List);
14-
const numChecker = TypeChecker.fromRuntime(num);
15-
const stringChecker = TypeChecker.fromRuntime(String);
16-
const objectChecker = TypeChecker.fromRuntime(Object);
17-
const _argResultsChecker = TypeChecker.fromRuntime(ArgResults);
18-
const _cliOptionChecker = TypeChecker.fromRuntime(CliOption);
19-
const _iterableChecker = TypeChecker.fromRuntime(Iterable);
13+
const boolChecker = TypeChecker.fromUrl('dart:core#bool');
14+
const listChecker = TypeChecker.fromUrl('dart:core#List');
15+
const numChecker = TypeChecker.fromUrl('dart:core#num');
16+
const stringChecker = TypeChecker.fromUrl('dart:core#String');
17+
const _argResultsChecker = TypeChecker.typeNamed(ArgResults);
18+
const _cliOptionChecker = TypeChecker.typeNamed(CliOption);
19+
const _iterableChecker = TypeChecker.fromUrl('dart:core#Iterable');
2020

2121
class ConverterData {
2222
final String name;
@@ -37,34 +37,34 @@ final _argInfoCache = Expando<ArgInfo>();
3737

3838
enum ArgType { option, flag, multiOption, rest, wasParsed, command }
3939

40-
const specialTypes = <ArgType, bool Function(FieldElement)>{
40+
const specialTypes = <ArgType, bool Function(FieldElement2)>{
4141
ArgType.rest: _couldBeRestArg,
4242
ArgType.wasParsed: _couldBeWasParsedArg,
4343
ArgType.command: _couldBeCommand,
4444
};
4545

4646
const wasParsedSuffix = 'WasParsed';
4747

48-
bool _couldBeRestArg(FieldElement element) => element.name == 'rest';
48+
bool _couldBeRestArg(FieldElement2 element) => element.name3 == 'rest';
4949

50-
bool _couldBeWasParsedArg(FieldElement element) =>
51-
element.name.endsWith(wasParsedSuffix) &&
52-
element.name.length > wasParsedSuffix.length &&
50+
bool _couldBeWasParsedArg(FieldElement2 element) =>
51+
element.name3!.endsWith(wasParsedSuffix) &&
52+
element.name3!.length > wasParsedSuffix.length &&
5353
boolChecker.isAssignableFromType(element.type);
5454

55-
bool _couldBeCommand(FieldElement element) =>
56-
element.name == 'command' &&
55+
bool _couldBeCommand(FieldElement2 element) =>
56+
element.name3 == 'command' &&
5757
_argResultsChecker.isAssignableFromType(element.type);
5858

5959
class ArgInfo {
6060
final CliOption? optionData;
6161
final ArgType argType;
6262
final DartType dartType;
6363

64-
ArgInfo(this.argType, this.optionData, FieldElement element)
65-
: dartType = element.type;
64+
ArgInfo(this.argType, this.optionData, FieldElement2 element)
65+
: dartType = element.type;
6666

67-
static ArgInfo fromField(FieldElement element) {
67+
static ArgInfo fromField(FieldElement2 element) {
6868
final info = _argInfoCache[element];
6969
if (info != null) {
7070
return info;
@@ -120,7 +120,7 @@ class ArgInfo {
120120
}
121121
}
122122

123-
ArgType _getArgType(FieldElement element, CliOption option) {
123+
ArgType _getArgType(FieldElement2 element, CliOption option) {
124124
final targetType = element.type;
125125

126126
if (converterDataFromOptions(option) != null) {
@@ -148,9 +148,10 @@ ArgType _getArgType(FieldElement element, CliOption option) {
148148
);
149149
}
150150

151-
CliOption? _getOptions(FieldElement element) {
152-
final obj = _cliOptionChecker.firstAnnotationOfExact(element) ??
153-
_cliOptionChecker.firstAnnotationOfExact(element.getter!);
151+
CliOption? _getOptions(FieldElement2 element) {
152+
final obj =
153+
_cliOptionChecker.firstAnnotationOfExact(element) ??
154+
_cliOptionChecker.firstAnnotationOfExact(element.getter2!);
154155

155156
List<Object>? allowedValues;
156157
Object? defaultsTo;
@@ -161,13 +162,14 @@ CliOption? _getOptions(FieldElement element) {
161162
return null;
162163
}
163164

164-
final defaultsToReader =
165-
annotation.isNull ? null : annotation.read('defaultsTo');
165+
final defaultsToReader = annotation.isNull
166+
? null
167+
: annotation.read('defaultsTo');
166168

167169
if (element.type.isEnum) {
168170
final interfaceType = element.type as InterfaceType;
169171

170-
final enumNames = interfaceType.accessors
172+
final enumNames = interfaceType.getters
171173
.where(
172174
(p) =>
173175
// An enum's values are non-nullable. For example, If the enum
@@ -177,7 +179,7 @@ CliOption? _getOptions(FieldElement element) {
177179
p.returnType.toStringNonNullable() ==
178180
element.type.toStringNonNullable(),
179181
)
180-
.map((p) => p.name)
182+
.map((p) => p.name3!)
181183
.toList();
182184

183185
if (defaultsToReader != null && !defaultsToReader.isNull) {
@@ -191,8 +193,11 @@ CliOption? _getOptions(FieldElement element) {
191193
);
192194
}
193195

194-
defaultsTo =
195-
_enumValueForDartObject<String>(objectValue, enumNames, (v) => v);
196+
defaultsTo = _enumValueForDartObject<String>(
197+
objectValue,
198+
enumNames,
199+
(v) => v,
200+
);
196201
defaultsTo = (defaultsTo as String).kebab;
197202
}
198203

@@ -280,7 +285,7 @@ CliOption? _getOptions(FieldElement element) {
280285
negatable: annotation.read('negatable').literalValue as bool?,
281286
provideDefaultToOverride:
282287
annotation.read('provideDefaultToOverride').literalValue as bool? ??
283-
false,
288+
false,
284289
valueHelp: annotation.read('valueHelp').literalValue as String?,
285290
);
286291

@@ -297,11 +302,14 @@ CliOption? _getOptions(FieldElement element) {
297302
);
298303
}
299304

300-
if (functionElement.parameters.isEmpty ||
301-
functionElement.parameters.first.isNamed ||
302-
functionElement.parameters.where((pe) => !pe.isOptional).length > 1 ||
303-
!element.library.typeProvider.stringType
304-
.isAssignableTo(functionElement.parameters.first.type)) {
305+
final formalParams = functionElement.formalParameters;
306+
307+
if (formalParams.isEmpty ||
308+
formalParams.first.isNamed ||
309+
formalParams.where((pe) => !pe.isOptional).length > 1 ||
310+
!element.library2.typeProvider.stringType.isAssignableTo(
311+
formalParams.first.type,
312+
)) {
305313
throwUnsupported(
306314
element,
307315
'The convert function `${functionElement.name}` must have one '
@@ -319,8 +327,8 @@ CliOption? _getOptions(FieldElement element) {
319327
);
320328
}
321329
_convertName[option] = ConverterData(
322-
functionElement.name,
323-
functionElement.parameters.first.type.isNullableType,
330+
functionElement.name3!,
331+
formalParams.first.type.isNullableType,
324332
);
325333
}
326334

@@ -331,5 +339,4 @@ T _enumValueForDartObject<T>(
331339
DartObject source,
332340
List<T> items,
333341
String Function(T) name,
334-
) =>
335-
items[source.getField('index')!.toIntValue()!];
342+
) => items[source.getField('index')!.toIntValue()!];

0 commit comments

Comments
 (0)