Skip to content

Commit 54ca5a6

Browse files
committed
Allow an option called run_only_if_triggered.
1 parent b7fd5fc commit 54ca5a6

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
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+
## 6.12.0-wip
2+
3+
- Allow `run_only_if_triggered` to be specified in `build.yaml` to turn on the
4+
`build_runner` triggers heuristic.
5+
16
## 6.11.1
27

38
- Allow `build: '>=3.0.0 <5.0.0'`.

json_serializable/lib/builder.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import 'src/json_part_builder.dart';
2323
/// Not meant to be invoked by hand-authored code.
2424
Builder jsonSerializable(BuilderOptions options) {
2525
try {
26-
final config = JsonSerializable.fromJson(options.config);
26+
var configJson = options.config;
27+
// Ignore `run_only_if_triggered` if present, it's used by `build_runner`.
28+
if (configJson.containsKey('run_only_if_triggered')) {
29+
configJson = Map.of(configJson)..remove('run_only_if_triggered');
30+
}
31+
final config = JsonSerializable.fromJson(configJson);
2732
return jsonPartBuilder(config: config);
2833
} on CheckedFromJsonException catch (e) {
2934
final lines = <String>[

json_serializable/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_serializable
2-
version: 6.11.1
2+
version: 6.12.0-wip
33
description: >-
44
Automatically generate code for converting to and from JSON by annotating
55
Dart classes.

json_serializable/test/config_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ void main() {
3636
expect(builder, isNotNull);
3737
});
3838

39+
test('triggers config is ignored', () async {
40+
// This key is used by build_runner so it's meaningful for any builder.
41+
jsonSerializable(const BuilderOptions({'run_only_if_triggered': true}));
42+
});
43+
3944
test('valid, non-default config', () {
4045
expect(
4146
generatorConfigNonDefaultJson.keys,

0 commit comments

Comments
 (0)