From 01f4565e0ab5ee50c03c0ed667da62a7775db33f Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Thu, 6 Jun 2024 11:44:57 +0200 Subject: [PATCH] Make install --force work for path dependencies --- .../lib/src/cli/install/install_command.dart | 16 +++++++++++----- .../realm_dart/lib/src/cli/install/options.dart | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/realm_dart/lib/src/cli/install/install_command.dart b/packages/realm_dart/lib/src/cli/install/install_command.dart index 5d44ba5db..16efc914d 100644 --- a/packages/realm_dart/lib/src/cli/install/install_command.dart +++ b/packages/realm_dart/lib/src/cli/install/install_command.dart @@ -59,9 +59,14 @@ class InstallCommand extends Command { return false; } - Future downloadAndExtractBinaries(Directory destinationDir, Version version, String archiveName) async { + Future downloadAndExtractBinaries(Directory destinationDir, Version version, String archiveName, bool force) async { if (await shouldSkipDownload(destinationDir.absolute.path, version.toString())) { - return; + if (!force) { + return; + } + + print('Deleting existing binaries because --force was supplied.'); + await destinationDir.delete(recursive: true); } if (!await destinationDir.exists()) { @@ -130,8 +135,9 @@ class InstallCommand extends Command { final flavorName = flavor.packageName; final realmDependency = pubspec.dependencyOverrides[flavorName] ?? pubspec.dependencies[flavorName]; - if (realmDependency is PathDependency) { - print('Path dependency for $flavorName found. Skipping install of native lib (assuming local development)'); + if (realmDependency is PathDependency && !options.force) { + print( + 'Path dependency for $flavorName found. Skipping install of native lib (assuming local development). If you want to force install, add --force to the command invocation.'); return; } if (realmDependency == null) { @@ -145,7 +151,7 @@ class InstallCommand extends Command { final binaryPath = getBinaryPath(realmPackagePath, isFlutter: flavor == Flavor.flutter); print(binaryPath); final archiveName = '${options.targetOsType!.name}.tar.gz'; - await downloadAndExtractBinaries(binaryPath, realmPubspec.version!, archiveName); + await downloadAndExtractBinaries(binaryPath, realmPubspec.version!, archiveName, options.force); print('Realm install command finished.'); } diff --git a/packages/realm_dart/lib/src/cli/install/options.dart b/packages/realm_dart/lib/src/cli/install/options.dart index f9c1440b6..6a1148e31 100644 --- a/packages/realm_dart/lib/src/cli/install/options.dart +++ b/packages/realm_dart/lib/src/cli/install/options.dart @@ -15,7 +15,7 @@ class Options { @CliOption(hide: true, help: 'Download binary from http://localhost:8000/.', defaultsTo: false) bool debug; - @CliOption(hide: true, help: 'Force install, even if we would normally skip it.', defaultsTo: false) + @CliOption(help: 'Force install, even if we would normally skip it.', abbr: 'f', defaultsTo: false) bool force; Options({this.targetOsType, this.force = false, this.debug = false});