slang-i18n / slang

Type-safe i18n for Dart and Flutter
https://pub.dev/packages/slang
MIT License
421 stars 36 forks source link

build_runner only works the first time for each output_file_name #90

Open stefan-schweiger opened 1 year ago

stefan-schweiger commented 1 year ago

Describe the bug When I run flutter pub run build_runner build --delete-conflicting-outputs with the following build.yaml the first time it generates the correct translations.g.dart file. But when I run the command a second time it generates nothing (if you delete the file you won't get a new one). If I change the output_file to something else it works again for one time and breaks again afterwards.

targets:
  $default:
    builders:
      slang_build_runner:
        options:
          base_locale: en
          output_file_name: translations.g.dart

For the same reason flutter pub run build_runner watch --delete-conflicting-outputs also doesn't work for me.

Expected behavior The file should be regenerated each time the command is run.

Additional context

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter  
  intl: ^0.17.0
  slang: ^2.6.1
  slang_flutter: ^2.6.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  build_runner: ^2.2.0
  slang_build_runner: ^2.6.0

Additional question Why is the --delete-conflicting-outputs needed in the first place? Libs like auto_route and json_serializable don't seem to need the flag to work.

stefan-schweiger commented 1 year ago

I just tried it without output_file_name and noticed I have the same issue there as well.

Tienisto commented 1 year ago

Hi, currently, this library generates the dart file only if input changes. That's why your issue should be minor. I will investigate if there is a way to force a rebuild. Other libraries have a 1:1 relationship between source and output. build_runner will notice right away when you delete one of the output files. slang however, does not tell build_runner what and where to build beforehand. That's why build_runner only watches the i18n files and the config to determine if slang should be run.

Actually, --delete-conflicting-outputs may not be needed anymore. I added this option a time ago when it was kind of buggy.

My recommendation is: Run flutter pub run slang on your dev machine. This command is build.yaml compatible. On your CI (if you have one), you can run flutter pub run build_runner build. If you start from a clean environment everytime (which should be the case in CI), then everything should be okay.

AdamHavlicek commented 3 months ago

@Tienisto this behavior should be mentioned in the docs or in FAQ at least, because the newcomers might wonder why build_runner does not output anything or why build_runner fails to generate files