diff --git a/CHANGELOG.md b/CHANGELOG.md index ecb0f930..12598193 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.1 + +* Fixed: Empty flavors map been added to the project config by @leoafarias + ## 3.1.0 * Initial release of [JSON API](https://fvm.app/documentation/advanced/json-api), allows for better integration of third-party tools and CI/CD workflows. diff --git a/lib/src/services/project_service.dart b/lib/src/services/project_service.dart index 898ead36..f680a70b 100644 --- a/lib/src/services/project_service.dart +++ b/lib/src/services/project_service.dart @@ -86,15 +86,17 @@ class ProjectService extends ContextService { /// or updates the project's config file. The updated project is returned. Project update( Project project, { - Map flavors = const {}, + Map? flavors, String? flutterSdkVersion, bool? updateVscodeSettings, }) { final currentConfig = project.config ?? ProjectConfig.empty(); + final mergedFlavors = {...?currentConfig.flavors, ...?flavors}; + final newConfig = ProjectConfig( flutter: flutterSdkVersion, - flavors: {...?currentConfig.flavors, ...flavors}, + flavors: mergedFlavors.isNotEmpty ? mergedFlavors : null, updateVscodeSettings: updateVscodeSettings, ); diff --git a/lib/src/utils/context.dart b/lib/src/utils/context.dart index c8393263..c6b38aa2 100644 --- a/lib/src/utils/context.dart +++ b/lib/src/utils/context.dart @@ -59,7 +59,19 @@ class FVMContext with FVMContextMappable { /// Generated values final Map _dependencies = {}; - factory FVMContext.create({ + /// Constructor + /// If nothing is provided set default + FVMContext.raw({ + required this.id, + required this.workingDirectory, + required this.config, + required this.environment, + required this.args, + required this.generators, + this.isTest = false, + }); + + static FVMContext create({ String? id, List? args, AppConfig? configOverrides, @@ -77,7 +89,7 @@ class FVMContext with FVMContextMappable { final environment = {...Platform.environment, ...?environmentOverrides}; - return FVMContext._( + return FVMContext.raw( id: id ?? 'MAIN', workingDirectory: workingDirectory, config: config, @@ -99,18 +111,6 @@ class FVMContext with FVMContextMappable { ); } - /// Constructor - /// If nothing is provided set default - FVMContext._({ - required this.id, - required this.workingDirectory, - required this.config, - required this.environment, - required this.args, - required this.generators, - this.isTest = false, - }); - /// Directory where FVM is stored @MappableField() String get fvmDir => config.cachePath ?? kAppDirHome; diff --git a/lib/src/utils/context.mapper.dart b/lib/src/utils/context.mapper.dart index 6be0ff1d..8f627a64 100644 --- a/lib/src/utils/context.mapper.dart +++ b/lib/src/utils/context.mapper.dart @@ -22,33 +22,26 @@ class FVMContextMapper extends ClassMapperBase { final String id = 'FVMContext'; static String _$id(FVMContext v) => v.id; - static const Field _f$id = Field('id', _$id, opt: true); - static List _$args(FVMContext v) => v.args; - static const Field> _f$args = - Field('args', _$args, opt: true); - static const Field _f$configOverrides = - Field('configOverrides', null, mode: FieldMode.param, opt: true); + static const Field _f$id = Field('id', _$id); static String _$workingDirectory(FVMContext v) => v.workingDirectory; static const Field _f$workingDirectory = - Field('workingDirectory', _$workingDirectory, opt: true); - static const Field> _f$generatorOverrides = - Field('generatorOverrides', null, mode: FieldMode.param, opt: true); - static const Field> _f$environmentOverrides = - Field('environmentOverrides', null, mode: FieldMode.param, opt: true); - static bool _$isTest(FVMContext v) => v.isTest; - static const Field _f$isTest = - Field('isTest', _$isTest, opt: true, def: false); - static Map _$generators( - FVMContext v) => - v.generators; - static const Field> - _f$generators = Field('generators', _$generators, mode: FieldMode.member); + Field('workingDirectory', _$workingDirectory); static AppConfig _$config(FVMContext v) => v.config; static const Field _f$config = - Field('config', _$config, mode: FieldMode.member); + Field('config', _$config); static Map _$environment(FVMContext v) => v.environment; static const Field> _f$environment = - Field('environment', _$environment, mode: FieldMode.member); + Field('environment', _$environment); + static List _$args(FVMContext v) => v.args; + static const Field> _f$args = Field('args', _$args); + static Map _$generators( + FVMContext v) => + v.generators; + static const Field> + _f$generators = Field('generators', _$generators); + static bool _$isTest(FVMContext v) => v.isTest; + static const Field _f$isTest = + Field('isTest', _$isTest, opt: true, def: false); static String _$fvmDir(FVMContext v) => v.fvmDir; static const Field _f$fvmDir = Field('fvmDir', _$fvmDir); static bool _$gitCache(FVMContext v) => v.gitCache; @@ -93,15 +86,12 @@ class FVMContextMapper extends ClassMapperBase { @override final MappableFields fields = const { #id: _f$id, - #args: _f$args, - #configOverrides: _f$configOverrides, #workingDirectory: _f$workingDirectory, - #generatorOverrides: _f$generatorOverrides, - #environmentOverrides: _f$environmentOverrides, - #isTest: _f$isTest, - #generators: _f$generators, #config: _f$config, #environment: _f$environment, + #args: _f$args, + #generators: _f$generators, + #isTest: _f$isTest, #fvmDir: _f$fvmDir, #gitCache: _f$gitCache, #runPubGetOnSdkChanges: _f$runPubGetOnSdkChanges, @@ -119,13 +109,13 @@ class FVMContextMapper extends ClassMapperBase { }; static FVMContext _instantiate(DecodingData data) { - return FVMContext.create( + return FVMContext.raw( id: data.dec(_f$id), - args: data.dec(_f$args), - configOverrides: data.dec(_f$configOverrides), workingDirectory: data.dec(_f$workingDirectory), - generatorOverrides: data.dec(_f$generatorOverrides), - environmentOverrides: data.dec(_f$environmentOverrides), + config: data.dec(_f$config), + environment: data.dec(_f$environment), + args: data.dec(_f$args), + generators: data.dec(_f$generators), isTest: data.dec(_f$isTest)); } @@ -182,14 +172,23 @@ extension FVMContextValueCopy<$R, $Out> abstract class FVMContextCopyWith<$R, $In extends FVMContext, $Out> implements ClassCopyWith<$R, $In, $Out> { + AppConfigCopyWith<$R, AppConfig, AppConfig> get config; + MapCopyWith<$R, String, String, ObjectCopyWith<$R, String, String>> + get environment; ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get args; + MapCopyWith< + $R, + Type, + ContextService Function(FVMContext), + ObjectCopyWith<$R, ContextService Function(FVMContext), + ContextService Function(FVMContext)>> get generators; $R call( {String? id, - List? args, - AppConfig? configOverrides, String? workingDirectory, - Map? generatorOverrides, - Map? environmentOverrides, + AppConfig? config, + Map? environment, + List? args, + Map? generators, bool? isTest}); FVMContextCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); } @@ -203,36 +202,55 @@ class _FVMContextCopyWithImpl<$R, $Out> late final ClassMapperBase $mapper = FVMContextMapper.ensureInitialized(); @override + AppConfigCopyWith<$R, AppConfig, AppConfig> get config => + $value.config.copyWith.$chain((v) => call(config: v)); + @override + MapCopyWith<$R, String, String, ObjectCopyWith<$R, String, String>> + get environment => MapCopyWith( + $value.environment, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(environment: v)); + @override ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get args => ListCopyWith($value.args, (v, t) => ObjectCopyWith(v, $identity, t), (v) => call(args: v)); @override + MapCopyWith< + $R, + Type, + ContextService Function(FVMContext), + ObjectCopyWith<$R, ContextService Function(FVMContext), + ContextService Function(FVMContext)>> get generators => MapCopyWith( + $value.generators, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(generators: v)); + @override $R call( - {Object? id = $none, - Object? args = $none, - AppConfig? configOverrides, - Object? workingDirectory = $none, - Map? generatorOverrides, - Map? environmentOverrides, + {String? id, + String? workingDirectory, + AppConfig? config, + Map? environment, + List? args, + Map? generators, bool? isTest}) => $apply(FieldCopyWithData({ - if (id != $none) #id: id, - if (args != $none) #args: args, - #configOverrides: configOverrides, - if (workingDirectory != $none) #workingDirectory: workingDirectory, - #generatorOverrides: generatorOverrides, - #environmentOverrides: environmentOverrides, + if (id != null) #id: id, + if (workingDirectory != null) #workingDirectory: workingDirectory, + if (config != null) #config: config, + if (environment != null) #environment: environment, + if (args != null) #args: args, + if (generators != null) #generators: generators, if (isTest != null) #isTest: isTest })); @override - FVMContext $make(CopyWithData data) => FVMContext.create( + FVMContext $make(CopyWithData data) => FVMContext.raw( id: data.get(#id, or: $value.id), - args: data.get(#args, or: $value.args), - configOverrides: data.get(#configOverrides), workingDirectory: data.get(#workingDirectory, or: $value.workingDirectory), - generatorOverrides: data.get(#generatorOverrides), - environmentOverrides: data.get(#environmentOverrides), + config: data.get(#config, or: $value.config), + environment: data.get(#environment, or: $value.environment), + args: data.get(#args, or: $value.args), + generators: data.get(#generators, or: $value.generators), isTest: data.get(#isTest, or: $value.isTest)); @override diff --git a/lib/src/version.dart b/lib/src/version.dart index d006dce1..3c880f01 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '3.1.0'; +const packageVersion = '3.1.1'; diff --git a/pubspec.yaml b/pubspec.yaml index 4d8bef25..afd7c3e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: fvm description: A simple cli to manage Flutter SDK versions per project. Support channels, releases, and local cache for fast switching between versions. -version: 3.1.0 +version: 3.1.1 homepage: https://github.com/leoafarias/fvm environment: