diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2ce5f3c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "pubspec_manager", + "request": "launch", + "type": "dart", + "program": "bin/manage.dart", + "args": [ + "manage", + "-f", + "test", + "-b", + "no-pub-get" + ] + }, + { + "name": "example", + "cwd": "example", + "request": "launch", + "type": "dart" + } + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ed7623..b51e040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +### 0.3.0+1 (2024-01-25) +#### Added +- Added support to mange overridden dependencies in pubspec_overrides.yaml file. +- Added support to avoid running pub get after managing the dependencies, can be called by `pubm -f -b no-pub-get` or `dart run pub:manage -f -b no-pub-get`, -b is abbreviation for `--build-args` +- Added support to both `flutter pub get` and `dart pub get` commands (If the pubspec.yaml file contains flutter sdk dependency then it will run flutter pub get else dart pub get). + +#### Fixed +- Fixed the issue of of removing and managing dependencies when clubbed together. + ### 0.2.0 (2023-11-04) #### Added - Added support to remove values from pubspec.yaml file. diff --git a/README.md b/README.md index 1c138b5..a5503b1 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,21 @@ pubm -f -v # else dart run pubm:manage -f -v ``` + +Once the pubspec is managed, this run the pub get command, if the pubspec.yaml file contains flutter sdk dependency then it will run flutter pub get else dart pub get. +To stop calling pub get after managing the pubspec.yaml file, use the -b flag with no-pub-get value. +-b (--build-args) +```console +# if activated from https://pub.dev +pubm -f -b no-pub-get -v + +# else +dart run pubm:manage -f -b no-pub-get -v +``` + +Pubm also supports managing the overridden dependencies in `pubspec_overrides.yaml` file. + + ### 📋 Example: pubspec_dev.yaml Here's an example of a flavor-specific pubspec.yaml file for a 'dev' flavor: ```yaml diff --git a/backup_pubspec.yaml b/backup_pubspec.yaml index 892cf27..2f2dcb7 100644 --- a/backup_pubspec.yaml +++ b/backup_pubspec.yaml @@ -1,15 +1,8 @@ name: pubm description: A Dart command line tool to help with managing pubspec dependencies. -version: 0.1.0 +version: 0.0.1-beta +homepage: https://github.com/kushalmahapatro/pubspec_manager repository: https://github.com/kushalmahapatro/pubspec_manager -homepage: https://github.com/kushalmahapatro/pubspec_manager -topics: - - pubspec - - pubspec-manager - - pubspec-splitter - - pubspec-updater - - pubspec-dependency-manager - environment: sdk: ^3.0.0 @@ -17,13 +10,13 @@ environment: dependencies: # normal dependencies args: ^2.4.2 - cli_util: ^0.4.0 - collection: ^1.17.1 + cli_util: ^0.4.1 + collection: ^1.18.0 cupertino_icons: ^1.0.2 equatable: ^2.0.5 - get_it: ^7.2.0 + get_it: ^7.6.7 json2yaml: ^3.0.1 - path: ^1.8.0 + path: ^1.9.0 yaml: ^3.1.2 dev_dependencies: @@ -31,10 +24,13 @@ dev_dependencies: lints: ^2.1.1 test: ^1.24.3 - flutter: - uses-material-design: true - generate: true +topics: + - pubspec + - pubspec-manager + - pubspec-splitter + - pubspec-updater + - pubspec-dependency-manager executables: pubm: manage diff --git a/backup_pubspec_overrides.yaml b/backup_pubspec_overrides.yaml new file mode 100644 index 0000000..0092fd1 --- /dev/null +++ b/backup_pubspec_overrides.yaml @@ -0,0 +1,4 @@ + +dependency_overrides: + # normal dependencies + args: ^2.4.1 diff --git a/example/_pubspec.yaml b/example/_pubspec.yaml deleted file mode 100644 index 3d3123c..0000000 --- a/example/_pubspec.yaml +++ /dev/null @@ -1,49 +0,0 @@ -name: pubm -description: Actual description -version: 0.0.1 -homepage: https://test.homepage - -environment: - sdk: ^3.0.0 - -dependencies: - cupertino_icons: ^1.0.2 - unwanted_dependency: ^0.0.1 - -dev_dependencies: - flutter_lints: ^2.0.0 - unwanted_dependency: ^0.0.1-dev - -dependency_overrides: - flutter_lints: ^1.0.0 - unwanted_dependency: ^0.0.1-override - -flutter: - uses-material-design: true - generate: true - - assets: - - assets/dev/ - - assets/prod/ - - fonts: - - family: font1 - fonts: - - asset: actual/font1/700.ttf - weight: 700 - - asset: actual/font1/600.ttf - weight: 600 - - asset: actual/font1/500.ttf - weight: 500 - - asset: actual/font1/400.ttf - weight: 400 - - family: font - fonts: - - asset: actual/font2/700.ttf - weight: 700 - - asset: actual/font2/600.ttf - weight: 600 - - asset: actual/font2/500.ttf - weight: 500 - - asset: actual/font2/400.ttf - weight: 400 \ No newline at end of file diff --git a/example/backup_pubspec.yaml b/example/backup_pubspec.yaml new file mode 100644 index 0000000..0f08879 --- /dev/null +++ b/example/backup_pubspec.yaml @@ -0,0 +1,28 @@ +name: pubm +description: prod version of pubspec.yaml +version: 0.0.1-dev + +environment: + sdk: ^3.0.0 + +dependencies: + # path related dependencies + example_dependency: + path: example/dependency + # normal dependencies + cupertino_icons: ^1.0.2 + +flutter: + uses-material-design: true + generate: true + fonts: + - family: font + fonts: + - asset: dev/font2/700.ttf + weight: 700 + - asset: dev/font2/600.ttf + weight: 600 + - asset: dev/font2/500.ttf + weight: 500 + - asset: dev/font2/400.ttf + weight: 400 diff --git a/example/backup_pubspec_overrides.yaml b/example/backup_pubspec_overrides.yaml new file mode 100644 index 0000000..d946bc8 --- /dev/null +++ b/example/backup_pubspec_overrides.yaml @@ -0,0 +1,5 @@ + +dependency_overrides: + # normal dependencies + flutter_lints: ^9.0.0 + unwanted_dependency: ^0.0.1-override diff --git a/example/pubspec.yaml b/example/pubspec.yaml new file mode 100644 index 0000000..0f08879 --- /dev/null +++ b/example/pubspec.yaml @@ -0,0 +1,28 @@ +name: pubm +description: prod version of pubspec.yaml +version: 0.0.1-dev + +environment: + sdk: ^3.0.0 + +dependencies: + # path related dependencies + example_dependency: + path: example/dependency + # normal dependencies + cupertino_icons: ^1.0.2 + +flutter: + uses-material-design: true + generate: true + fonts: + - family: font + fonts: + - asset: dev/font2/700.ttf + weight: 700 + - asset: dev/font2/600.ttf + weight: 600 + - asset: dev/font2/500.ttf + weight: 500 + - asset: dev/font2/400.ttf + weight: 400 diff --git a/example/pubspec_dev.yaml b/example/pubspec_dev.yaml index 49d8d8c..42f160c 100644 --- a/example/pubspec_dev.yaml +++ b/example/pubspec_dev.yaml @@ -1,10 +1,14 @@ description: prod version of pubspec.yaml -version: 0.0.1-prod +version: 0.0.1-dev dependencies: example_dependency: path: example/dependency +dependency_overrides: + flutter_lints: ^9.0.0 + unwanted_override: ^1.0.1-override + dev_dependencies: lints: ^2.1.1 @@ -20,19 +24,19 @@ flutter: weight: 500 - asset: dev/font2/400.ttf weight: 400 - remove: homepage: https://test.homepage - dependencies: unwanted_dependency: dev_dependencies: - dependency_overrides: + + dependency_overrides: + unwanted_override: flutter: assets: - assets/dev/ fonts: - - family: font1 \ No newline at end of file + - family: font1 diff --git a/example/pubspec_overrides.yaml b/example/pubspec_overrides.yaml new file mode 100644 index 0000000..d946bc8 --- /dev/null +++ b/example/pubspec_overrides.yaml @@ -0,0 +1,5 @@ + +dependency_overrides: + # normal dependencies + flutter_lints: ^9.0.0 + unwanted_dependency: ^0.0.1-override diff --git a/example/pubspec_prod.yaml b/example/pubspec_prod.yaml index cabbfac..aabb511 100644 --- a/example/pubspec_prod.yaml +++ b/example/pubspec_prod.yaml @@ -34,7 +34,7 @@ remove: flutter: assets: - - assets/dev/ + - assets/prod/ fonts: - - family: font1 \ No newline at end of file + - family: font1 diff --git a/lib/constants.dart b/lib/constants.dart index da5fb05..ff7e265 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -1,5 +1,6 @@ const String comment = "Pubspec Manager Comment"; const String pubspecYamlPath = "pubspec.yaml"; +const String pubspecOverridesYamlPath = "pubspec_overrides.yaml"; /// Pubspec keys const String name = 'name'; diff --git a/lib/models/pubspec.dart b/lib/models/pubspec.dart index 4f31a66..9bb73da 100644 --- a/lib/models/pubspec.dart +++ b/lib/models/pubspec.dart @@ -68,36 +68,36 @@ class Pubspec extends Equatable { Pubspec pubspec = Pubspec(); Map others = {}; map.forEach((key, value) { - if (key == 'name') { + if (key == 'name' && value != null) { pubspec = pubspec.copyWith(name: value); - } else if (key == 'description') { + } else if (key == 'description' && value != null) { pubspec = pubspec.copyWith(description: value); - } else if (key == 'version') { + } else if (key == 'version' && value != null) { pubspec = pubspec.copyWith(version: value); - } else if (key == 'homepage') { + } else if (key == 'homepage' && value != null) { pubspec = pubspec.copyWith(homepage: value); - } else if (key == 'repository') { + } else if (key == 'repository' && value != null) { pubspec = pubspec.copyWith(repository: value); - } else if (key == 'issue_tracker') { + } else if (key == 'issue_tracker' && value != null) { pubspec = pubspec.copyWith(issueTracker: value); - } else if (key == 'documentation') { + } else if (key == 'documentation' && value != null) { pubspec = pubspec.copyWith(documentation: value); - } else if (key == 'publish_to') { + } else if (key == 'publish_to' && value != null) { pubspec = pubspec.copyWith(publishTo: value); - } else if (key == 'environment') { + } else if (key == 'environment' && value != null) { pubspec = pubspec.copyWith( environment: Environment.fromMap(value.cast())); - } else if (key == 'dependencies') { + } else if (key == 'dependencies' && value != null) { pubspec = pubspec.copyWith( dependencies: getDependencies(value.cast())); - } else if (key == 'dev_dependencies') { + } else if (key == 'dev_dependencies' && value != null) { pubspec = pubspec.copyWith( devDependencies: getDependencies(value.cast())); - } else if (key == 'dependency_overrides') { + } else if (key == 'dependency_overrides' && value != null) { pubspec = pubspec.copyWith( dependenciesOverride: getDependencies(value.cast())); - } else if (key == 'flutter') { + } else if (key == 'flutter' && value != null) { pubspec = pubspec.copyWith( flutter: FlutterData.fromMap(value.cast())); } else { diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index 40b77fa..5d80cbb 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -10,20 +10,24 @@ import 'package:yaml/yaml.dart'; /// Handles loading and validating the configuration values class Configuration { - final List _arguments; Configuration(this._arguments); - + final List _arguments; final Logger _logger = GetIt.I(); - late ArgResults _args; - List? buildArgs; - String flavor = ''; + File backupPubspecFile = File('backup_$pubspecYamlPath'); + File backupPubspecOverridesFile = File('backup_$pubspecOverridesYamlPath'); File pubspecFile = File(pubspecYamlPath); + File pubspecOverridesFile = File(pubspecOverridesYamlPath); + + String flavor = ''; File pubspecFlavorFile = File(''); + List? buildArgs; + ArgResults _args = ArgParser().parse([]); + bool pubGetAfterDone = true; /// Gets the configuration values from from [_arguments] or pubspec.yaml file Future getConfigValues() async { - _parseCliArguments(_arguments); + _args = _parseCliArguments(_arguments); dynamic pubspec = await _getPubspec(); dynamic yaml = pubspec['pubm_config'] ?? YamlMap(); @@ -32,6 +36,9 @@ class Configuration { if (buildArgsConfig != null && buildArgsConfig.isNotEmpty) { CommandLineConverter commandLineConverter = CommandLineConverter(); buildArgs = commandLineConverter.convert(buildArgsConfig); + if (buildArgs?.contains('no-pub-get') ?? false) { + pubGetAfterDone = false; + } } } @@ -42,7 +49,9 @@ class Configuration { if (_args['help']) { _logger.stdout('Usage: pubm -f '); _logger.stdout( - 'Usage: pubm -f -v (verbose) to enable verbose mode'); + 'Usage: pubm --flavor/-f --verbose/-v (verbose) to enable verbose mode'); + _logger.stdout( + 'Usage: pubm --flavor/-f --build-args/-b --verbose/-v to build without running pub get and enable verbose mode'); _logger.stdout( 'Usage: pubm -h to get the list of available commands and how to use'); @@ -68,16 +77,16 @@ class Configuration { } /// Declare and parse the cli arguments - void _parseCliArguments(List args) { + ArgResults _parseCliArguments(List args) { _logger.trace('parsing cli arguments'); ArgParser parser = ArgParser() ..addOption('flavor', abbr: 'f', help: 'flavor of YAML file (pubspec_/flavor/.yaml)') - ..addOption('build-args') + ..addOption('build-args', abbr: 'b', help: 'build arguments') ..addFlag('help', negatable: false, abbr: 'h'); // exclude -v (verbose) from the arguments - _args = parser.parse(args.where((arg) => arg != '-v')); + return parser.parse(args.where((arg) => arg != '-v')); } } diff --git a/lib/src/flutter_build.dart b/lib/src/flutter_build.dart index 03465a8..2517b71 100644 --- a/lib/src/flutter_build.dart +++ b/lib/src/flutter_build.dart @@ -34,14 +34,18 @@ class FlutterBuild { loggerProgress.finish(showTiming: true); } - Future pubGet() async { + Future pubGet({required bool isFlutterProject}) async { var flutterPath = await _getFlutterPath(); + var dartPath = await _getDartPath(); - final Progress loggerProgress = - _logger.progress('running "flutter pub get"'); + final Progress loggerProgress = _logger + .progress('running "${isFlutterProject ? 'flutter' : 'dart'} pub get"'); - final ProcessResult pubGetProgress = - await Process.run(flutterPath, ['pub', 'get'], runInShell: true); + final ProcessResult pubGetProgress = await Process.run( + isFlutterProject ? flutterPath : dartPath, + ['pub', 'get'], + runInShell: true, + ); pubGetProgress.exitOnError(); @@ -71,3 +75,13 @@ Future _getFlutterPath() async { return flutterPath; } + +Future _getDartPath() async { + // e.g. C:\Users\MyUser\fvm\versions\3.10.5\bin\cache\dart-sdk\bin\dart + final dartPath = p.split(Platform.executable); + + // e.g. C:\Users\MyUser\fvm\versions\3.10.5\bin\flutter + final dartRelativePath = p.joinAll(dartPath); + + return dartRelativePath; +} diff --git a/lib/src/manage/manage_dependency_overrides.dart b/lib/src/manage/manage_dependency_overrides.dart index a852f5d..d6f2a64 100644 --- a/lib/src/manage/manage_dependency_overrides.dart +++ b/lib/src/manage/manage_dependency_overrides.dart @@ -9,8 +9,9 @@ void checkAndUpdateDependencyOverrides( Pubspec flavorPubspec, Map finalMap, Map map, - Logger logger, -) { + Logger logger, { + bool isPubspecOverrides = false, +}) { var dependencyOverrideCheck = PubspecChecker.checkDependencyOverride( actualPubspec, flavorPubspec, @@ -20,13 +21,17 @@ void checkAndUpdateDependencyOverrides( if (!dependencyOverrideCheck.hasMatch) { if (dependencyOverrideCheck.update.isNotEmpty) { for (var element in dependencyOverrideCheck.update) { - logger.trace('Updating dependency_override $element'); + logger.trace( + 'Updating dependency_override $element ${isPubspecOverrides ? 'in pubspec_overrides.yaml' : 'in pubspec.yaml'}', + ); } } if (dependencyOverrideCheck.addition.isNotEmpty) { for (var element in dependencyOverrideCheck.addition) { - logger.trace('Adding dependency_override $element'); + logger.trace( + 'Adding dependency_override $element ${isPubspecOverrides ? 'in pubspec_overrides.yaml' : 'in pubspec.yaml'}', + ); } } diff --git a/lib/src/manage/pubspec_manage.dart b/lib/src/manage/pubspec_manage.dart index 0d01456..1dc564e 100644 --- a/lib/src/manage/pubspec_manage.dart +++ b/lib/src/manage/pubspec_manage.dart @@ -1,8 +1,11 @@ import 'package:cli_util/cli_logging.dart'; +import 'package:collection/collection.dart'; import 'package:pubm/constants.dart'; +import 'package:pubm/models/dependencies.dart'; import 'package:pubm/models/pubspec.dart'; import 'package:pubm/src/configuration.dart'; import 'package:pubm/src/extensions.dart'; +import 'package:pubm/src/flutter_build.dart'; import 'package:pubm/src/helpers/pubspec_checker.dart'; import 'package:pubm/src/manage/manage_dependencies.dart'; import 'package:pubm/src/manage/manage_dependency_overrides.dart'; @@ -10,7 +13,7 @@ import 'package:pubm/src/manage/manage_dev_dependencies.dart'; import 'package:pubm/src/manage/manage_other_values.dart'; import 'package:pubm/src/manage/remove_values.dart'; import 'package:pubm/src/manage/sort_all_dependencies.dart'; -import 'package:pubm/src/manage/update_actuap_pubspec.dart'; +import 'package:pubm/src/manage/update_actual_pubspec.dart'; import 'package:yaml/yaml.dart'; import 'manage_flutter_values.dart'; @@ -34,34 +37,61 @@ mixin PubspecManager { final dynamic yamlMap = loadYaml(contents); final dynamic actualYamlMap = loadYaml(config.pubspecFile.readAsStringSync()); + final dynamic pubspecOverridesYamlMap = + config.pubspecOverridesFile.existsSync() + ? loadYaml(config.pubspecOverridesFile.readAsStringSync()) + : null; - if (checkIfItsOnlyRemove(yamlMap)) { - final Map? finalMap = await removeValuesFromPubspec( + if (checkIfItsOnlyRemove(Pubspec.fromMap(yamlMap).toMap())) { + final RemovedPubspecsMap mapsAfterRemoving = + await removeValuesFromPubspec( logger: logger, config: config, ); - if (finalMap != null) { - /// Sort all the dependencies (dependencies, dev_dependencies, dependency_overrides) - sortAllDependencies( - finalMap, - logger, - ); - /// Update the actual pubspec.yaml file - await updateActualPubspec( - finalMap, - nameChanged, - Pubspec.fromMap(actualYamlMap), - Pubspec.fromMap(yamlMap), - config, - logger, + /// Sort all the dependencies (dependencies, dev_dependencies, dependency_overrides) + sortAllDependencies( + mapsAfterRemoving.pubspecMap ?? {}, + logger, + ); + + sortAllDependencies( + mapsAfterRemoving.pubspecOverridesMap ?? {}, + logger, + ); + + /// Update the actual pubspec.yaml file + await updateActualPubspecFiles( + finalPubspecMap: mapsAfterRemoving.pubspecMap ?? {}, + actualPubspec: Pubspec.fromMap(actualYamlMap), + flavorPubspec: Pubspec.fromMap(yamlMap), + nameChanged: nameChanged, + config: config, + logger: logger, + ); + + /// Update the actual pubspec.yaml file + if (pubspecOverridesYamlMap != null) { + await updateActualPubspecFiles( + finalPubspecMap: mapsAfterRemoving.pubspecOverridesMap ?? {}, + actualPubspec: Pubspec.fromMap(pubspecOverridesYamlMap), + flavorPubspec: Pubspec.fromMap(yamlMap), + config: config, + logger: logger, + isForPubspecOverrides: true, ); - return; } + + await _performPubGet(); + + return; } // Create a Pubspec object final Pubspec actualPubspec = Pubspec.fromMap(actualYamlMap); + final Pubspec? pubspecOverrides = pubspecOverridesYamlMap == null + ? null + : Pubspec.fromMap(pubspecOverridesYamlMap); final Pubspec flavorPubspec = Pubspec.fromMap(yamlMap); final bool alreadyMerged = PubspecChecker.checkIfPubspecAlreadyMerged( @@ -76,7 +106,8 @@ mixin PubspecManager { // Update the Pubspec object Map finalMap = actualPubspec.toMap(); - final Map map = flavorPubspec.toMap(); + Map? finalMapPubspecOverrides = pubspecOverrides?.toMap(); + final Map flavorMap = flavorPubspec.toMap(); if (!PubspecChecker.checkName(actualPubspec, flavorPubspec)) { logger.trace('Updating $name from ${actualPubspec.name} to ' @@ -143,7 +174,7 @@ mixin PubspecManager { actualPubspec, flavorPubspec, finalMap, - map, + flavorMap, logger, ); @@ -152,18 +183,32 @@ mixin PubspecManager { actualPubspec, flavorPubspec, finalMap, - map, + flavorMap, logger, ); /// Check and update the dependency_overrides - checkAndUpdateDependencyOverrides( - actualPubspec, - flavorPubspec, - finalMap, - map, - logger, - ); + if (actualPubspec.dependenciesOverride != null) { + checkAndUpdateDependencyOverrides( + actualPubspec, + flavorPubspec, + finalMap, + flavorMap, + logger, + ); + } + + /// Check and update the dependency_overrides in pubspec_overrides.yaml + if (finalMapPubspecOverrides != null && pubspecOverrides != null) { + checkAndUpdateDependencyOverrides( + pubspecOverrides, + flavorPubspec, + finalMapPubspecOverrides, + flavorMap, + logger, + isPubspecOverrides: true, + ); + } /// Other values which are not checked and might be from other plugins checkAndUpdateOtherValues( @@ -182,14 +227,21 @@ mixin PubspecManager { ); /// Get the final map after removing the values mentioned in the pubspec_flavor.yaml - final Map? finalMapAfterRemoving = - await removeValuesFromPubspec( - logger: logger, - config: config, - ); + if (checkIfItsContainsRemove(flavorMap)) { + final RemovedPubspecsMap finalMapAfterRemoving = + await removeValuesFromPubspec( + logger: logger, + config: config, + ); + + if (finalMapAfterRemoving.pubspecMap != null) { + finalMap = finalMapAfterRemoving.pubspecMap ?? {}; + } - if (finalMapAfterRemoving != null) { - finalMap = finalMapAfterRemoving; + if (finalMapAfterRemoving.pubspecOverridesMap != null) { + finalMapPubspecOverrides = + finalMapAfterRemoving.pubspecOverridesMap ?? {}; + } } /// Sort all the dependencies (dependencies, dev_dependencies, dependency_overrides) @@ -198,14 +250,47 @@ mixin PubspecManager { logger, ); - /// Update the actual pubspec.yaml file - await updateActualPubspec( - finalMap, - nameChanged, - actualPubspec, - flavorPubspec, - config, + /// Sort all the dependency_overrides in pubspec_overrides.yaml + sortAllDependencies( + finalMapPubspecOverrides ?? {}, logger, + isPubspecOverrides: true, + ); + + /// Update the actual pubspec.yaml file + await updateActualPubspecFiles( + finalPubspecMap: finalMap, + actualPubspec: actualPubspec, + flavorPubspec: flavorPubspec, + nameChanged: nameChanged, + config: config, + logger: logger, ); + + if (finalMapPubspecOverrides != null && pubspecOverrides != null) { + await updateActualPubspecFiles( + finalPubspecMap: finalMapPubspecOverrides, + actualPubspec: pubspecOverrides, + flavorPubspec: flavorPubspec, + config: config, + logger: logger, + isForPubspecOverrides: true, + ); + } + + await _performPubGet(); + } + + Future _performPubGet() async { + if (config.pubGetAfterDone) { + final Pubspec actualPubspec = + Pubspec.fromMap(loadYaml(config.pubspecFile.readAsStringSync())); + final SdkDependency? hasFlutterSdkDependency = + (actualPubspec.dependencies?.sdkDependencies ?? []) + .firstWhereOrNull((element) => element.name == 'flutter'); + + await FlutterBuild() + .pubGet(isFlutterProject: hasFlutterSdkDependency != null); + } } } diff --git a/lib/src/manage/remove_values.dart b/lib/src/manage/remove_values.dart index dfe7265..bf8fe33 100644 --- a/lib/src/manage/remove_values.dart +++ b/lib/src/manage/remove_values.dart @@ -6,23 +6,29 @@ import 'package:pubm/src/configuration.dart'; import 'package:pubm/src/extensions.dart'; import 'package:yaml/yaml.dart'; +typedef RemovedPubspecsMap = ({ + Map? pubspecMap, + Map? pubspecOverridesMap +}); + /// Check if the pubspec_flavor.yaml file contains remove key -bool checkIfItsOnlyRemove(dynamic data) { - return data is Map && data.containsKey("remove") && data.keys.length == 1; +bool checkIfItsOnlyRemove(Map data) { + return data.containsKey("remove") && data.keys.length == 1; } -bool checkIfItsContainsRemove(dynamic data) { - return data is Map && data.containsKey("remove"); +bool checkIfItsContainsRemove(Map data) { + return data.containsKey("remove"); } /// Remove the values mentioned in the remove section of the pubspec_flavor.yaml -Future?> removeValuesFromPubspec({ +Future removeValuesFromPubspec({ required Logger logger, required Configuration config, }) async { if (!config.pubspecFlavorFile.existsSync()) { logger.stderr('File does not exist: ${config.flavor}'.red); - return null; + + return (pubspecMap: null, pubspecOverridesMap: null); } // Read the YAML file @@ -31,23 +37,34 @@ Future?> removeValuesFromPubspec({ // Parse the YAML contents final dynamic yamlMap = loadYaml(contents); - /// Check if the pubspec_flavor.yaml file contains remove key - if (!checkIfItsContainsRemove(yamlMap)) { - logger.stdout( - 'No remove key found in pubspec_${config.flavor}.yaml'.emphasized, - ); - return null; - } - final dynamic actualYamlMap = loadYaml(config.pubspecFile.readAsStringSync()); + final dynamic pubspecOverridesYamlMap = + config.pubspecOverridesFile.existsSync() + ? loadYaml(config.pubspecOverridesFile.readAsStringSync()) + : null; // Create a Pubspec object final Pubspec actualPubspec = Pubspec.fromMap(actualYamlMap); final Pubspec flavorPubspec = Pubspec.fromMap(yamlMap[remove]); + final Pubspec? pubspecOverridesPubspec = pubspecOverridesYamlMap != null + ? Pubspec.fromMap(pubspecOverridesYamlMap) + : null; // Update the Pubspec object final Map finalMap = actualPubspec.toMap(); final Map map = flavorPubspec.toMap(); + final Map? pubspecOverridesMap = + pubspecOverridesPubspec?.toMap(); + + /// Check if the pubspec_flavor.yaml file contains remove key + if (yamlMap is! Map || + !checkIfItsContainsRemove(yamlMap.cast())) { + logger.stdout( + 'No remove key found in pubspec_${config.flavor}.yaml'.emphasized, + ); + + return (pubspecMap: finalMap, pubspecOverridesMap: pubspecOverridesMap); + } //Remove name if name exists in flavor if (map.containsKey(name)) { @@ -59,62 +76,63 @@ Future?> removeValuesFromPubspec({ ///Remove description if description exists in flavor if (map.containsKey(description)) { - logger.trace('Removing $description'); + logger.trace('Removing:0-7654` $description'); finalMap.remove(description); } ///Remove version if version exists in flavor if (map.containsKey(version)) { - logger.trace('Removing $version'); + logger.trace('Removing: $version'); finalMap.remove(version); } ///Remove homepage if homepage exists in flavor if (map.containsKey(homepage)) { - logger.trace('Removing $homepage'); + logger.trace('Removing: $homepage'); finalMap.remove(homepage); } ///Remove repository if repository exists in flavor if (map.containsKey(repository)) { - logger.trace('Removing $repository'); + logger.trace('Removing: $repository'); finalMap.remove(repository); } ///Remove issueTracker if issueTracker exists in flavor if (map.containsKey(issueTracker)) { - logger.trace('Removing $issueTracker'); + logger.trace('Removing: $issueTracker'); finalMap.remove(issueTracker); } ///Remove documentation if documentation exists in flavor if (map.containsKey(documentation)) { - logger.trace('Removing $documentation'); + logger.trace('Removing: $documentation'); finalMap.remove(documentation); } ///Remove publish_to if publish_to exists in flavor if (map.containsKey(publishTo)) { - logger.trace('Removing $publishTo'); + logger.trace('Removing: $publishTo'); finalMap.remove(publishTo); } ///Remove environment if environment exists in flavor if (map.containsKey(environment)) { - logger.trace('Removing $environment'); + logger.trace('Removing: $environment'); finalMap.remove(environment); } ///Check if dependencies key exists if so then ///Loop through all the dependencies and remove it. if (map.containsKey(dependencies)) { - map[dependencies].forEach((key, value) { - if (finalMap[dependencies].containsKey(key)) { - logger.trace('Removing dependency $key'); + map[dependencies]?.forEach((key, value) { + if (finalMap[dependencies]?.containsKey(key) ?? false) { + logger.trace('Removing dependency: $key'); finalMap[dependencies].remove(key); } }); - if ((finalMap[dependencies] as Map).isEmpty) { + if (finalMap[dependencies] != null && + (finalMap[dependencies] as Map).isEmpty) { finalMap.remove(dependencies); } } @@ -122,13 +140,14 @@ Future?> removeValuesFromPubspec({ ///Check if dev_dependencies key exists if so then ///Loop through all the dev_dependencies and remove it. if (map.containsKey(devDependencies)) { - map[devDependencies].forEach((key, value) { - if (finalMap[devDependencies].containsKey(key)) { - logger.trace('Deleting dev_dependency $key'); + map[devDependencies]?.forEach((key, value) { + if (finalMap[devDependencies]?.containsKey(key) ?? false) { + logger.trace('Deleting dev_dependency: $key'); finalMap[devDependencies].remove(key); } }); - if ((finalMap[devDependencies] as Map).isEmpty) { + if (finalMap[devDependencies] != null && + (finalMap[devDependencies] as Map).isEmpty) { finalMap.remove(devDependencies); } } @@ -136,15 +155,37 @@ Future?> removeValuesFromPubspec({ ///Check if dependency_overrides key exists if so then ///Loop through all the dependency_overrides and remove it. if (map.containsKey(dependencyOverrides)) { - map[dependencyOverrides].forEach((key, value) { - if (finalMap[dependencyOverrides].containsKey(key)) { - logger.trace('Deleting dependency_override $key'); + map[dependencyOverrides]?.forEach((key, value) { + if (finalMap[dependencyOverrides]?.containsKey(key) ?? false) { + logger.trace('Deleting dependency_override: $key'); finalMap[dependencyOverrides].remove(key); } }); - if ((finalMap[dependencyOverrides] as Map).isEmpty) { + + if (finalMap[dependencyOverrides] != null && + (finalMap[dependencyOverrides] as Map).isEmpty) { finalMap.remove(dependencyOverrides); } + + /// Removing the keys from pubspec_overrides.yaml + if (pubspecOverridesMap != null && + pubspecOverridesMap[dependencyOverrides] != null) { + map[dependencyOverrides]?.forEach( + (key, value) { + if (pubspecOverridesMap[dependencyOverrides]?.containsKey(key) ?? + false) { + logger.trace( + 'Deleting dependency_override from pubspec_overrides.yaml: $key'); + pubspecOverridesMap[dependencyOverrides].remove(key); + } + }, + ); + + if (pubspecOverridesMap[dependencyOverrides] != null && + (pubspecOverridesMap[dependencyOverrides] as Map).isEmpty) { + pubspecOverridesMap.remove(dependencyOverrides); + } + } } /// Other values which are not checked and might be from other plugins @@ -216,5 +257,5 @@ Future?> removeValuesFromPubspec({ } } - return finalMap; + return (pubspecMap: finalMap, pubspecOverridesMap: pubspecOverridesMap); } diff --git a/lib/src/manage/sort_all_dependencies.dart b/lib/src/manage/sort_all_dependencies.dart index d55bc15..ad88623 100644 --- a/lib/src/manage/sort_all_dependencies.dart +++ b/lib/src/manage/sort_all_dependencies.dart @@ -6,10 +6,14 @@ import 'package:pubm/constants.dart'; /// Sort all the dependencies (dependencies, dev_dependencies, dependency_overrides) void sortAllDependencies( Map finalMap, - Logger logger, -) { + Logger logger, { + bool isPubspecOverrides = false, +}) { if (finalMap.containsKey(dependencies)) { - logger.trace('Sorting $dependencies'); + logger.trace( + 'Sorting $dependencies ${isPubspecOverrides ? 'in pubspec_overrides' : 'in pubspec.yaml'}', + ); + var sortedKeys = finalMap[dependencies].keys.toList(growable: false) ..sort((k1, k2) => k1.toString().compareTo(k2.toString())); LinkedHashMap sortedMap = LinkedHashMap.fromIterable(sortedKeys, diff --git a/lib/src/manage/update_actuap_pubspec.dart b/lib/src/manage/update_actual_pubspec.dart similarity index 54% rename from lib/src/manage/update_actuap_pubspec.dart rename to lib/src/manage/update_actual_pubspec.dart index 9dc9d00..9e6aced 100644 --- a/lib/src/manage/update_actuap_pubspec.dart +++ b/lib/src/manage/update_actual_pubspec.dart @@ -4,17 +4,17 @@ import 'package:pubm/constants.dart'; import 'package:pubm/models/pubspec.dart'; import 'package:pubm/src/configuration.dart'; import 'package:pubm/src/extensions.dart'; -import 'package:pubm/src/flutter_build.dart'; - -Future updateActualPubspec( - Map finalMap, - bool nameChanged, - Pubspec actualPubspec, - Pubspec flavorPubspec, - Configuration config, - Logger logger, -) async { - final finalPubspec = Pubspec.fromMap(finalMap); + +Future updateActualPubspecFiles({ + required Map finalPubspecMap, + required Pubspec actualPubspec, + required Pubspec flavorPubspec, + required Configuration config, + required Logger logger, + bool nameChanged = false, + bool isForPubspecOverrides = false, +}) async { + final finalPubspec = Pubspec.fromMap(finalPubspecMap); /// Convert the `finalMap` to String with pubspec.yaml format final String string = json2yaml( @@ -36,13 +36,28 @@ Future updateActualPubspec( return '# ${m.group(1)}'; }); - /// Save the updated YAML to the file - logger.trace('Creating a backup of pubspec.yaml to backup_pubspec.yaml'); - config.backupPubspecFile - .writeAsStringSync(config.pubspecFile.readAsStringSync()); - config.pubspecFile.writeAsStringSync(replacedText); + if (isForPubspecOverrides) { + /// Save the updated YAML to the file + logger.trace( + 'Creating a backup of pubspec_overrides.yaml to backup_pubspec_overrides.yaml' + .emphasized); + config.backupPubspecOverridesFile + .writeAsStringSync(config.pubspecOverridesFile.readAsStringSync()); + + /// Write the string format of pubspec_overrides.yaml to file (pubspec_overrides.yaml) + config.pubspecOverridesFile.writeAsStringSync(replacedText); + logger.stdout( + 'Merging of pubspec_overrides.yaml files completed successfully'.green); + } else { + /// Save the updated YAML to the file + logger.trace('Creating a backup of pubspec.yaml to backup_pubspec.yaml'); + config.backupPubspecFile + .writeAsStringSync(config.pubspecFile.readAsStringSync()); - logger.stdout('Merging of pubspec.yaml files completed successfully'.green); + /// Write the string format of pubspec.yaml to file (pubspec.yaml) + config.pubspecFile.writeAsStringSync(replacedText); + logger.stdout('Merging of pubspec.yaml files completed successfully'.green); + } /// Error message when name is changed in the main pubspec.yaml from the flavor pubspec.yaml if (nameChanged) { @@ -54,6 +69,4 @@ Future updateActualPubspec( logger.stderr( "Refactor: import 'package:${actualPubspec.name}/ to import 'package:${flavorPubspec.name}/ "); } - - await FlutterBuild().pubGet(); } diff --git a/pubspec.lock b/pubspec.lock index 4e79a67..fe0b09e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -45,18 +45,18 @@ packages: dependency: "direct main" description: name: cli_util - sha256: b8db3080e59b2503ca9e7922c3df2072cf13992354d5e944074ffa836fba43b7 + sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19 url: "https://pub.dev" source: hosted - version: "0.4.0" + version: "0.4.1" collection: dependency: "direct main" description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" convert: dependency: transitive description: @@ -85,18 +85,18 @@ packages: dependency: "direct main" description: name: cupertino_icons - sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be + sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d url: "https://pub.dev" source: hosted - version: "1.0.5" + version: "1.0.6" dart_internal: dependency: transitive description: name: dart_internal - sha256: dae3976f383beddcfcd07ad5291a422df2c8c0a8a03c52cda63ac7b4f26e0f4e + sha256: "689dccc3d5f62affd339534cca548dce12b3a6b32f0f10861569d3025efc0567" url: "https://pub.dev" source: hosted - version: "0.2.8" + version: "0.2.9" equatable: dependency: "direct main" description: @@ -125,10 +125,10 @@ packages: dependency: "direct main" description: name: get_it - sha256: "529de303c739fca98cd7ece5fca500d8ff89649f1bb4b4e94fb20954abcd7468" + sha256: e6017ce7fdeaf218dc51a100344d8cb70134b80e28b760f8bb23c242437bafd7 url: "https://pub.dev" source: hosted - version: "7.6.0" + version: "7.6.7" glob: dependency: transitive description: @@ -181,10 +181,10 @@ packages: dependency: "direct dev" description: name: lints - sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "3.0.0" logging: dependency: transitive description: @@ -197,10 +197,10 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" meta: dependency: transitive description: @@ -237,10 +237,10 @@ packages: dependency: "direct main" description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" pool: dependency: transitive description: @@ -349,26 +349,26 @@ packages: dependency: "direct dev" description: name: test - sha256: "67ec5684c7a19b2aba91d2831f3d305a6fd8e1504629c5818f8d64478abf4f38" + sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073" url: "https://pub.dev" source: hosted - version: "1.24.4" + version: "1.25.2" test_api: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" test_core: dependency: transitive description: name: test_core - sha256: "6b753899253c38ca0523bb0eccff3934ec83d011705dae717c61ecf209e333c9" + sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4" url: "https://pub.dev" source: hosted - version: "0.5.4" + version: "0.6.0" typed_data: dependency: transitive description: @@ -418,4 +418,4 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.0.0 <3.2.0" + dart: ">=3.0.0 <3.3.0" diff --git a/pubspec.yaml b/pubspec.yaml index 01090c2..5ae0f68 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,15 +1,8 @@ name: pubm description: A Dart command line tool to help with managing pubspec dependencies. -version: 0.2.0 +version: 0.3.0+1 repository: https://github.com/kushalmahapatro/pubspec_manager -homepage: https://github.com/kushalmahapatro/pubspec_manager -topics: - - pubspec - - pubspec-manager - - pubspec-splitter - - pubspec-updater - - pubspec-dependency-manager - +homepage: https://github.com/kushalmahapatro/pubspec_manager environment: sdk: ^3.0.0 @@ -17,24 +10,26 @@ environment: dependencies: # normal dependencies args: ^2.4.2 - cli_util: ^0.4.0 - collection: ^1.17.1 + cli_util: ^0.4.1 + collection: ^1.18.0 cupertino_icons: ^1.0.2 equatable: ^2.0.5 - get_it: ^7.2.0 + get_it: ^7.6.7 json2yaml: ^3.0.1 - path: ^1.8.0 + path: ^1.9.0 yaml: ^3.1.2 dev_dependencies: # normal dependencies - lints: ^2.1.1 - test: ^1.24.3 + lints: ^3.0.0 + test: ^1.25.2 - -flutter: - uses-material-design: true - generate: true +topics: + - pubspec + - pubspec-manager + - pubspec-splitter + - pubspec-updater + - pubspec-dependency-manager executables: pubm: manage diff --git a/pubspec_overrides.yaml b/pubspec_overrides.yaml new file mode 100644 index 0000000..0092fd1 --- /dev/null +++ b/pubspec_overrides.yaml @@ -0,0 +1,4 @@ + +dependency_overrides: + # normal dependencies + args: ^2.4.1 diff --git a/pubspec_test.yaml b/pubspec_test.yaml index b6a674a..5afe766 100644 --- a/pubspec_test.yaml +++ b/pubspec_test.yaml @@ -12,6 +12,9 @@ dev_dependencies: lints: ^2.1.1 test: ^1.24.3 +dependency_overrides: + args: ^2.4.1 + flutter: uses-material-design: true - generate: true \ No newline at end of file + generate: true diff --git a/test/configuration_temp/backup_pubspec.yaml b/test/configuration_temp/backup_pubspec.yaml new file mode 100644 index 0000000..612d66c --- /dev/null +++ b/test/configuration_temp/backup_pubspec.yaml @@ -0,0 +1,89 @@ +name: pubm +description: A command-line application to manage pubspec dependencies. +version: 1.0.0 +environment: + sdk: '>=3.0.0 <4.0.0' + flutter: '3.10.0' + +dependencies: + flutter: + sdk: flutter + flutter_localizations: + sdk: flutter + path_test: + path: abc/xyz + path_test2: + path: abc/xyz/2 + git_test: + git: + url: https://github.com/aa/aa.git + ref: 1232131231231dependency + path: path + git_test2: + git: + url: https://github.com/aa/aa2.git + ref: 00000000000000dependency + path: path2 + args: ^2.4.2 + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_driver: + sdk: flutter + git_test_dev: + git: + url: https://github.com/aa/dev.git + ref: 00000000000000dev + path: path_dev + test: any + lints: ^2.1.1 + +dependency_overrides: + git_test_override: + git: + url: https://github.com/aa/override.git + ref: 00000000000000override + path: path_override + +flutter: + uses-material-design: true + generate: true + assets: + - assets/my_icon.png + - assets/background.png + - directory/ + - directory/subdirectory/ + + fonts: + - family: test + fonts: + - asset: a/a/700.ttf + weight: 700 + - asset: a/a/600.ttf + weight: 600 + - asset: a/a/500.ttf + weight: 500 + - asset: a/a/400.ttf + weight: 400 + - family: test2 + fonts: + - asset: a/b/700.ttf + weight: 700 + - asset: a/b/600.ttf + weight: 600 + - asset: a/b/500.ttf + weight: 500 + - asset: a/b/400.ttf + weight: 400 + +msix_config: + display_name: Flutter App + publisher_display_name: Company Name + identity_name: company.suite.flutterapp + msix_version: 1.0.0.0 + logo_path: C:\path\to\logo.png + capabilities: internetClient, location, microphone, webcam + + \ No newline at end of file diff --git a/test/configuration_temp/pubspec.yaml b/test/configuration_temp/pubspec.yaml new file mode 100644 index 0000000..3023b1f --- /dev/null +++ b/test/configuration_temp/pubspec.yaml @@ -0,0 +1,84 @@ +name: pubm +description: A command-line application to manage pubspec dependencies. +version: 1.0.0 + +environment: + sdk: '>=3.0.0 <4.0.0' + flutter: 3.10.0 + +dependencies: + # git related dependencies + git_test: + git: + url: https://github.com/aa/aa.git + ref: 1232131231231dependency + path: path + git_test2: + git: + url: https://github.com/aa/aa2.git + ref: 00000000000000dependency + path: path2 + # path related dependencies + path_test: + path: abc/xyz + path_test2: + path: abc/xyz/2 + # normal dependencies + args: ^2.4.2 + cupertino_icons: ^1.0.2 + # sdk dependencies + flutter: + sdk: flutter + flutter_localizations: + sdk: flutter + +dev_dependencies: + # git related dependencies + git_test_dev: + git: + url: https://github.com/aa/dev.git + ref: 00000000000000dev + path: path_dev + # normal dependencies + lints: ^2.1.1 + test: any + # sdk dependencies + flutter_driver: + sdk: flutter + flutter_test: + sdk: flutter + +dependency_overrides: + # git related dependencies + git_test_override: + git: + url: https://github.com/aa/override.git + ref: 00000000000000override + path: path_override + +flutter: + uses-material-design: true + assets: + - assets/background.png + - directory/ + - directory/subdirectory/ + generate: true + fonts: + - family: test2 + fonts: + - asset: a/b/700.ttf + weight: 700 + - asset: a/b/600.ttf + weight: 600 + - asset: a/b/500.ttf + weight: 500 + - asset: a/b/400.ttf + weight: 400 + +msix_config: + display_name: Flutter App + publisher_display_name: Company Name + identity_name: company.suite.flutterapp + msix_version: 1.0.0.0 + logo_path: C:\path\to\logo.png + capabilities: 'internetClient, location, microphone, webcam' diff --git a/test/configuration_temp/pubspec_test.yaml b/test/configuration_temp/pubspec_test.yaml new file mode 100644 index 0000000..5245e25 --- /dev/null +++ b/test/configuration_temp/pubspec_test.yaml @@ -0,0 +1,7 @@ + remove: + flutter: + fonts: + - family: test + assets: + - assets/my_icon.png + \ No newline at end of file diff --git a/test/helper.dart b/test/helper.dart index 502b2dd..1661312 100644 --- a/test/helper.dart +++ b/test/helper.dart @@ -13,7 +13,10 @@ Future testSetUp() async { ..pubspecFile = File(pubspecPath) ..pubspecFlavorFile = File(pubspecFlavorPath) ..backupPubspecFile = File(backupPubspecFlavorPath) - ..flavor = 'test'; + ..backupPubspecOverridesFile = File(backupPubspecOverridesPath) + ..pubspecOverridesFile = File(pubspecOverridePath) + ..flavor = 'test' + ..pubGetAfterDone = false; GetIt.I.registerSingleton(config); @@ -25,6 +28,6 @@ Future tearDownSetup() async { GetIt.I.reset(); if (await Directory(tempFolderPath).exists()) { - await Directory(tempFolderPath).delete(recursive: true); + // await Directory(tempFolderPath).delete(recursive: true); } } diff --git a/test/overrides_yaml_check.dart b/test/overrides_yaml_check.dart new file mode 100644 index 0000000..1fb3ac6 --- /dev/null +++ b/test/overrides_yaml_check.dart @@ -0,0 +1,14 @@ +import 'yaml_check.dart'; + +class OverridesYamlTest extends YamlTest { + const OverridesYamlTest( + this.overridesYamlContent, + super.yamlContent, + super.flavorYamlContent, + super.config, + ); + + final String overridesYamlContent; + + mergeValues() {} +} diff --git a/test/pubm_test.dart b/test/pubm_test.dart index 606dda9..9744067 100644 --- a/test/pubm_test.dart +++ b/test/pubm_test.dart @@ -9,6 +9,7 @@ import 'package:yaml/yaml.dart'; import 'helper.dart'; import 'mock_pubspec_manager.dart'; +import 'overrides_yaml_check.dart'; import 'test_constants.dart'; import 'yaml_check.dart'; @@ -17,9 +18,14 @@ var tempFolderPath = p.join('test', 'configuration_temp'); var pubspecPath = p.join(tempFolderPath, 'pubspec.yaml'); var pubspecFlavorPath = p.join(tempFolderPath, 'pubspec_$flavor.yaml'); var backupPubspecFlavorPath = p.join(tempFolderPath, 'backup_pubspec.yaml'); +var pubspecOverridePath = p.join(tempFolderPath, 'pubspec_overrides.yaml'); +var backupPubspecOverridesPath = + p.join(tempFolderPath, 'backup_pubspec_overrides.yaml'); + late Configuration config; late MockPubspecManager testClass; late YamlTest yamlTest; +late OverridesYamlTest overridesYamlTest; void main() { const flavorYamlContent = ''' @@ -34,6 +40,12 @@ void main() { flavorYamlContent, config, ); + overridesYamlTest = OverridesYamlTest( + overridesYamlContent, + yamlContent, + flavorYamlContent, + config, + ); }); tearDown(() => tearDownSetup()); @@ -231,5 +243,10 @@ void main() { 'remove other values', () => yamlTest.removeOtherValues(), ); + + test( + 'Merge pubspec and pubspec_overrides', + () => overridesYamlTest.mergeValues(), + ); }); } diff --git a/test/test_constants.dart b/test/test_constants.dart index cb2ed95..44fd4a0 100644 --- a/test/test_constants.dart +++ b/test/test_constants.dart @@ -10,6 +10,10 @@ $flutterContent $otherContent '''; +const overridesYamlContent = ''' +$dependencyOverride + '''; + const name = 'name: pubm'; const description =