mirror of https://github.com/AMT-Cheif/drift.git
Properly read options (#1992)
This commit is contained in:
parent
a21576e02c
commit
27ea49137d
|
@ -1,3 +1,7 @@
|
|||
## 2.0.1
|
||||
|
||||
- Recognize options for applied `not_shared` builder when exporting schemas.
|
||||
|
||||
## 2.0.0
|
||||
|
||||
- Removes the following build options, which are always turned on now:
|
||||
|
|
|
@ -93,7 +93,7 @@ class DriftOptions {
|
|||
this.overrideHashAndEqualsInResultSets = false,
|
||||
this.skipVerificationCode = false,
|
||||
this.useDataClassNameForCompanions = false,
|
||||
this.useColumnNameAsJsonKeyWhenDefinedInMoorFile = false,
|
||||
this.useColumnNameAsJsonKeyWhenDefinedInMoorFile = true,
|
||||
this.generateConnectConstructor = false,
|
||||
this.dataClassToCompanions = true,
|
||||
this.generateMutableClasses = false,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:build_config/build_config.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:drift_dev/src/analyzer/options.dart';
|
||||
|
||||
Future<DriftOptions> fromRootDir(String path) async {
|
||||
|
@ -7,14 +8,13 @@ Future<DriftOptions> fromRootDir(String path) async {
|
|||
}
|
||||
|
||||
DriftOptions readOptionsFromConfig(BuildConfig config) {
|
||||
final options = config.buildTargets.values
|
||||
.map((t) {
|
||||
return t.builders['moor_generator:moor_generator']?.options ??
|
||||
t.builders['drift_dev:drift_dev']?.options;
|
||||
})
|
||||
.whereType<Map>()
|
||||
.map((json) => DriftOptions.fromJson(json));
|
||||
|
||||
final iterator = options.iterator;
|
||||
return iterator.moveNext() ? iterator.current : const DriftOptions.defaults();
|
||||
return config.buildTargets.values
|
||||
.map((t) {
|
||||
return t.builders['drift_dev:drift_dev']?.options ??
|
||||
t.builders['drift_dev:not_shared']?.options;
|
||||
})
|
||||
.whereType<Map>()
|
||||
.map((json) => DriftOptions.fromJson(json))
|
||||
.firstOrNull ??
|
||||
DriftOptions.defaults();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
import 'package:build_config/build_config.dart';
|
||||
import 'package:drift_dev/src/utils/options_reader.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('reads options from build.yaml file', () {
|
||||
final config = BuildConfig.parse('a', ['drift_dev'], r'''
|
||||
targets:
|
||||
$default:
|
||||
auto_apply_builders: false
|
||||
builders:
|
||||
drift_dev:preparing_builder:
|
||||
enabled: true
|
||||
drift_dev:drift_dev:
|
||||
enabled: true
|
||||
options:
|
||||
scoped_dart_components: false
|
||||
json_serializable:
|
||||
enabled: true
|
||||
sources:
|
||||
- lib/**
|
||||
- test/generated/**
|
||||
''');
|
||||
|
||||
final options = readOptionsFromConfig(config);
|
||||
expect(options.scopedDartComponents, isFalse);
|
||||
});
|
||||
|
||||
test('supports reading from non-default target', () {
|
||||
final config = BuildConfig.parse('a', ['drift_dev'], r'''
|
||||
targets:
|
||||
$default:
|
||||
dependencies: [:source_gen]
|
||||
source_gen:
|
||||
auto_apply_builders: false
|
||||
builders:
|
||||
drift_dev:preparing_builder:
|
||||
enabled: true
|
||||
drift_dev:drift_dev:
|
||||
enabled: true
|
||||
options:
|
||||
scoped_dart_components: false
|
||||
json_serializable:
|
||||
enabled: true
|
||||
sources:
|
||||
- lib/**
|
||||
- test/generated/**
|
||||
''');
|
||||
|
||||
final options = readOptionsFromConfig(config);
|
||||
expect(options.scopedDartComponents, isFalse);
|
||||
});
|
||||
|
||||
test('supports reading for not_shared builder', () {
|
||||
final config = BuildConfig.parse('a', ['drift_dev'], r'''
|
||||
targets:
|
||||
$default:
|
||||
dependencies: [:source_gen]
|
||||
source_gen:
|
||||
auto_apply_builders: false
|
||||
builders:
|
||||
drift_dev:preparing_builder:
|
||||
enabled: true
|
||||
drift_dev:not_shared:
|
||||
enabled: true
|
||||
options:
|
||||
scoped_dart_components: false
|
||||
json_serializable:
|
||||
enabled: true
|
||||
sources:
|
||||
- lib/**
|
||||
- test/generated/**
|
||||
''');
|
||||
|
||||
final options = readOptionsFromConfig(config);
|
||||
expect(options.scopedDartComponents, isFalse);
|
||||
});
|
||||
|
||||
test('still works with | syntax', () {
|
||||
final config = BuildConfig.parse('a', ['drift_dev'], r'''
|
||||
targets:
|
||||
$default:
|
||||
dependencies: [:source_gen]
|
||||
source_gen:
|
||||
auto_apply_builders: false
|
||||
builders:
|
||||
drift_dev|preparing_builder:
|
||||
enabled: true
|
||||
drift_dev|not_shared:
|
||||
enabled: true
|
||||
options:
|
||||
scoped_dart_components: false
|
||||
json_serializable:
|
||||
enabled: true
|
||||
sources:
|
||||
- lib/**
|
||||
- test/generated/**
|
||||
''');
|
||||
|
||||
final options = readOptionsFromConfig(config);
|
||||
expect(options.scopedDartComponents, isFalse);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue