-
Notifications
You must be signed in to change notification settings - Fork 266
Add lean_builder support infrastructure to retrofit_generator #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
99fb686
Initial plan
Copilot bb982e4
Add lean_builder support infrastructure to retrofit_generator
Copilot cf2956a
Fix analyzer issues in lean_builder support
Copilot c55f008
Remove duplicate documentation in lean_builder.dart
Copilot 3607706
Make lean_builder an optional dependency instead of required
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Lean Builder Support (Experimental) | ||
|
|
||
| This document provides information about using lean_builder with retrofit_generator. | ||
|
|
||
| ## Status | ||
|
|
||
| ⚠️ **Experimental** - Lean Builder support is currently under development and not yet recommended for production use. | ||
|
|
||
| ## What is Lean Builder? | ||
|
|
||
| [Lean Builder](https://pub.dev/packages/lean_builder) is a streamlined Dart build system that offers: | ||
| - Fast incremental builds (often under 1 second) | ||
| - Parallel processing for maximum efficiency | ||
| - Watch mode with hot reload support | ||
| - Simple, declarative builder configuration | ||
|
|
||
| ## Current Implementation | ||
|
|
||
| The infrastructure for lean_builder support has been added to retrofit_generator, but the full implementation is pending until: | ||
| 1. Lean Builder reaches a stable release (currently at v0.1.2) | ||
| 2. The retrofit_generator codebase is fully adapted to lean_builder's API | ||
|
|
||
| ## Using build_runner (Recommended) | ||
|
|
||
| For now, please continue using build_runner for code generation: | ||
|
|
||
| ```bash | ||
| # One-time build | ||
| dart pub run build_runner build | ||
|
|
||
| # Watch mode (recommended during development) | ||
| dart pub run build_runner watch --delete-conflicting-outputs | ||
| ``` | ||
|
|
||
| ## Future Usage (When Available) | ||
|
|
||
| Once lean_builder support is fully implemented, you'll be able to use: | ||
|
|
||
| ```bash | ||
| # One-time build | ||
| dart run lean_builder build | ||
|
|
||
| # Watch mode with hot reload | ||
| dart run lean_builder watch --dev | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### pubspec.yaml | ||
|
|
||
| When lean_builder support is ready, your `pubspec.yaml` will include: | ||
|
|
||
| ```yaml | ||
| dependencies: | ||
| retrofit: ^4.6.0 | ||
| dio: ^5.0.0 | ||
| json_annotation: ^4.9.0 | ||
|
|
||
| dev_dependencies: | ||
| retrofit_generator: ^10.0.0 | ||
| lean_builder: ^0.1.2 # or latest version | ||
| json_serializable: ^6.10.0 | ||
| ``` | ||
|
|
||
| ### build.yaml (Optional) | ||
|
|
||
| You can keep your existing `build.yaml` configuration. Lean Builder will respect these settings when support is fully implemented: | ||
|
|
||
| ```yaml | ||
| targets: | ||
| $default: | ||
| builders: | ||
| retrofit_generator: | ||
| options: | ||
| auto_cast_response: true | ||
| ``` | ||
|
|
||
| ## Migration Path | ||
|
|
||
| When lean_builder support becomes stable: | ||
|
|
||
| 1. **No code changes required** - Your @RestApi annotations and API definitions remain the same | ||
| 2. **Update dependencies** - Add lean_builder to dev_dependencies | ||
| 3. **Switch build command** - Use `dart run lean_builder build` instead of `build_runner` | ||
| 4. **Enjoy faster builds** - Experience significantly faster incremental builds | ||
|
|
||
| ## Contributing | ||
|
|
||
| If you're interested in helping complete the lean_builder integration, please: | ||
| 1. Check the [retrofit.dart GitHub repository](https://github.com/trevorwang/retrofit.dart) | ||
| 2. Review the [lean_builder documentation](https://pub.dev/packages/lean_builder) | ||
| 3. Submit a pull request or open an issue with your ideas | ||
|
|
||
| ## Support | ||
|
|
||
| For questions or issues: | ||
| - **retrofit.dart**: https://github.com/trevorwang/retrofit.dart/issues | ||
| - **lean_builder**: https://github.com/Milad-Akarie/lean_builder/issues | ||
|
|
||
| ## Timeline | ||
|
|
||
| Follow the retrofit.dart repository for updates on when lean_builder support will be fully available. The maintainers are monitoring lean_builder's development and will complete the integration when appropriate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /// Lean Builder entry point for Retrofit code generator. | ||
| /// | ||
| /// **⚠️ Experimental Feature ⚠️** | ||
| /// | ||
| /// This file provides experimental lean_builder support for retrofit_generator. | ||
| /// Lean Builder support is currently under development and not yet recommended | ||
| /// for production use. | ||
| /// | ||
| /// ## Current Status | ||
| /// | ||
| /// While the infrastructure for lean_builder support has been added, the | ||
| /// retrofit_generator package is currently optimized for build_runner. Full | ||
| /// lean_builder integration is planned for future releases once lean_builder | ||
| /// reaches a stable version. | ||
| /// | ||
| /// ## Usage (Experimental) | ||
| /// | ||
| /// For those who want to try the experimental support: | ||
| /// | ||
| /// 1. Add lean_builder to your dev_dependencies: | ||
| /// ```yaml | ||
| /// dev_dependencies: | ||
| /// lean_builder: ^0.1.2 | ||
| /// retrofit_generator: <version> | ||
| /// ``` | ||
| /// | ||
| /// 2. For now, please continue using build_runner: | ||
| /// ```bash | ||
| /// dart pub run build_runner build | ||
| /// # or for watch mode: | ||
| /// dart pub run build_runner watch | ||
| /// ``` | ||
| /// | ||
| /// ## Future Plans | ||
| /// | ||
| /// Once lean_builder reaches stability and this integration is complete, you'll | ||
| /// be able to use: | ||
| /// ```bash | ||
| /// dart run lean_builder build | ||
| /// # or for watch mode with hot reload: | ||
| /// dart run lean_builder watch --dev | ||
| /// ``` | ||
| /// | ||
| /// For updates on lean_builder support, visit: | ||
| /// https://github.com/trevorwang/retrofit.dart | ||
| library; | ||
|
|
||
| export 'package:retrofit_generator/src/lean_generator.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:lean_builder/builder.dart'; | ||
| import 'package:lean_builder/element.dart'; | ||
| import 'package:retrofit/retrofit.dart' as retrofit; | ||
|
|
||
| /// Lean Builder generator for Retrofit. | ||
| /// | ||
| /// This generator provides lean_builder support for retrofit_generator, | ||
| /// allowing faster incremental builds with lean_builder. | ||
| /// | ||
| /// Note: This is an experimental feature. For production use, we recommend | ||
| /// using the traditional build_runner approach until lean_builder support | ||
| /// is fully stable. | ||
| /// | ||
| /// This generator is automatically discovered by lean_builder through the | ||
| /// @LeanGenerator.shared() annotation, which marks it as a shared part builder | ||
| /// (similar to build_runner's shared part builders). | ||
| @LeanGenerator.shared() | ||
| class RetrofitLeanGenerator extends GeneratorForAnnotatedClass<retrofit.RestApi> { | ||
| RetrofitLeanGenerator(); | ||
|
|
||
| @override | ||
| FutureOr<String?> generateForClass( | ||
| BuildStep buildStep, | ||
| ClassElement classElement, | ||
| ElementAnnotation annotation, | ||
| ) async { | ||
| // The retrofit generator is currently optimized for build_runner/source_gen. | ||
| // Full lean_builder support requires adapting the codebase to use lean_builder's | ||
| // analyzer abstractions instead of source_gen's API. | ||
| // | ||
| // For now, this serves as a placeholder for future lean_builder support. | ||
| // Users should continue using build_runner for code generation: | ||
| // dart pub run build_runner build | ||
|
|
||
| throw UnsupportedError( | ||
| 'Lean Builder support for retrofit_generator is not yet fully implemented.\n' | ||
| 'The retrofit_generator package currently works with build_runner.\n\n' | ||
| 'To generate code, please use:\n' | ||
| ' dart pub run build_runner build\n\n' | ||
| 'For more information, see: https://github.com/trevorwang/retrofit.dart\n\n' | ||
| 'Lean Builder support is planned for a future release once lean_builder reaches stable.', | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
It made all users must be add lean_builder as the deps, any way to use it in a separated method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! lean_builder is now completely optional and removed from dependencies.
Users who want to use lean_builder support will add it to their own project dependencies. The lean_builder support files (
lib/lean_builder.dartandlib/src/lean_generator.dart) are excluded from analysis since they're only used when lean_builder is explicitly added.Changes in commit:
git show --statwill show the removal from pubspec.yaml + documentation updates.