Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@
## 6.12.0-wip

- Allow `run_only_if_triggered` to be specified in `build.yaml` to turn on the
`build_runner` triggers heuristic.

## 6.11.1

- Allow `build: '>=3.0.0 <5.0.0'`.
Expand Down
7 changes: 6 additions & 1 deletion json_serializable/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import 'src/json_part_builder.dart';
/// Not meant to be invoked by hand-authored code.
Builder jsonSerializable(BuilderOptions options) {
try {
final config = JsonSerializable.fromJson(options.config);
var configJson = options.config;
// Ignore `run_only_if_triggered` if present, it's used by `build_runner`.
if (configJson.containsKey('run_only_if_triggered')) {
configJson = Map.of(configJson)..remove('run_only_if_triggered');
}
final config = JsonSerializable.fromJson(configJson);
return jsonPartBuilder(config: config);
} on CheckedFromJsonException catch (e) {
final lines = <String>[
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_serializable
version: 6.11.1
version: 6.12.0-wip
description: >-
Automatically generate code for converting to and from JSON by annotating
Dart classes.
Expand Down
5 changes: 5 additions & 0 deletions json_serializable/test/config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ void main() {
expect(builder, isNotNull);
});

test('triggers config is ignored', () async {
// This key is used by build_runner so it's meaningful for any builder.
jsonSerializable(const BuilderOptions({'run_only_if_triggered': true}));
});

test('valid, non-default config', () {
expect(
generatorConfigNonDefaultJson.keys,
Expand Down