Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,24 @@ then run the generator
```sh
# dart
dart pub run build_runner build

# for watch mode (recommended during development)
dart pub run build_runner watch
```

#### Lean Builder Support (Experimental)

Retrofit now has experimental support for [lean_builder](https://pub.dev/packages/lean_builder), a faster build system for Dart. While lean_builder support is still under development, the infrastructure has been added for future use.

To prepare for lean_builder support, add it to your `dev_dependencies`:

```yaml
dev_dependencies:
lean_builder: ^0.1.2
```

**Note:** For now, please continue using `build_runner` as shown above. Full lean_builder integration will be available in a future release once lean_builder reaches stability.

### Use it

```dart
Expand Down
102 changes: 102 additions & 0 deletions example/LEAN_BUILDER.md
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.
8 changes: 8 additions & 0 deletions generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 10.0.8 (Unreleased)

- Add experimental lean_builder support infrastructure
- Add `lean_builder` as a dependency for future integration
- Add `lib/lean_builder.dart` entry point for lean_builder users
- Add comprehensive documentation for lean_builder support
- Note: Full lean_builder implementation is pending until lean_builder reaches stability

## 10.0.6

- Update `protobuf` to 5.0.0
Expand Down
48 changes: 48 additions & 0 deletions generator/lib/lean_builder.dart
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';
46 changes: 46 additions & 0 deletions generator/lib/src/lean_generator.dart
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.',
);
}
}
1 change: 1 addition & 0 deletions generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies:
code_builder: ^4.10.1
dart_style: ^3.1.1
dio: ^5.8.0
lean_builder: ^0.1.2
Copy link
Owner

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

Copy link
Contributor Author

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.dart and lib/src/lean_generator.dart) are excluded from analysis since they're only used when lean_builder is explicitly added.

Changes in commit: git show --stat will show the removal from pubspec.yaml + documentation updates.

protobuf: ^5.0.0
retrofit: ^4.7.3
source_gen: '>=3.1.0 <5.0.0'
Expand Down
Loading