Skip to content

Commit

Permalink
fix: Make the builder name compatible with both flutter_gen and flutt…
Browse files Browse the repository at this point in the history
…er_gen_runner (#592)

## What does this change?

Fixes #589 🎯

## Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] This change requires a documentation update
  • Loading branch information
b2nkuu authored Oct 20, 2024
1 parent a5f0e4e commit 1f4f6cc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ You can also configure generate options in the `build.yaml`, it will be read bef
targets:
$default:
builders:
flutter_gen:
flutter_gen_runner: # or flutter_gen
options:
output: lib/build_gen/ # Optional (default: lib/gen/)
line_length: 120 # Optional (default: 80)
Expand Down
4 changes: 2 additions & 2 deletions packages/command/test/flutter_gen_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {
);
expect(
await process.stdout.next,
equals('$flutterGenVersion Loading ... command${separator}pubspec.yaml'),
equals('$flutterGenVersion Loading ...'),
);
await process.shouldExit(0);
});
Expand All @@ -26,7 +26,7 @@ void main() {
);
expect(
await process.stdout.next,
equals('$flutterGenVersion Loading ... command${separator}pubspec.yaml'),
equals('$flutterGenVersion Loading ...'),
);
await process.shouldExit(0);
});
Expand Down
8 changes: 4 additions & 4 deletions packages/core/lib/settings/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) {
if (buildFile != null && buildFile.existsSync()) {
final buildContent = buildFile.readAsStringSync();
final rawMap = loadYaml(buildContent) as Map?;
final optionBuildMap = rawMap?['targets']?[r'$default']?['builders']
?['flutter_gen']?['options'];

if (optionBuildMap != null) {
final builders = rawMap?['targets']?[r'$default']?['builders'];
final optionBuildMap = (builders?['flutter_gen_runner'] ??
builders?['flutter_gen'])?['options'];
if (optionBuildMap is YamlMap) {
final buildMap = {'flutter_gen': optionBuildMap};
mergedMap = mergeMap([mergedMap, buildMap]);
final buildLocaleHint = normalize(
Expand Down
12 changes: 12 additions & 0 deletions packages/core/test/assets_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ void main() {
await expectedAssetsGen(pubspec, generated, fact, build: build);
},
);

test(
'Assets on pubspec_assets.yaml and override with build_runner_assets.yaml ',
() async {
const pubspec = 'test_resources/pubspec_assets.yaml';
const build = 'test_resources/build_runnfer_assets.yaml';
const fact = 'test_resources/actual_data/build_assets.gen.dart';
const generated = 'test_resources/lib/build_gen/assets.gen.dart';

await expectedAssetsGen(pubspec, generated, fact, build: build);
},
);
});

group('Test generatePackageNameForConfig', () {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/test_resources/build_runner_assets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: test

targets:
$default:
builders:
flutter_gen_runner:
options:
output: lib/build_gen/
line_length: 120

0 comments on commit 1f4f6cc

Please sign in to comment.