From e04e13c79ffbacd624b4ac11fb1b6663b1d1b1d1 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Mon, 7 Oct 2024 10:19:05 +0000 Subject: [PATCH] Revert --unlock-transitive --- lib/src/command/upgrade.dart | 42 ++++--------------- lib/src/entrypoint.dart | 6 +-- pubspec.yaml | 2 +- .../goldens/help_test/pub upgrade --help.txt | 1 - 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/lib/src/command/upgrade.dart b/lib/src/command/upgrade.dart index c0092b201..0f2abec63 100644 --- a/lib/src/command/upgrade.dart +++ b/lib/src/command/upgrade.dart @@ -70,12 +70,6 @@ class UpgradeCommand extends PubCommand { negatable: false, ); - argParser.addFlag( - 'unlock-transitive', - help: 'Also upgrades the transitive dependencies ' - 'of the listed [dependencies]', - ); - argParser.addFlag( 'major-versions', help: 'Upgrades packages to their latest resolvable versions, ' @@ -107,27 +101,11 @@ class UpgradeCommand extends PubCommand { bool get _precompile => argResults.flag('precompile'); - late final Future> _packagesToUpgrade = - _computePackagesToUpgrade(); - /// List of package names to upgrade, if empty then upgrade all packages. /// /// This allows the user to specify list of names that they want the /// upgrade command to affect. - Future> _computePackagesToUpgrade() async { - if (argResults.flag('unlock-transitive')) { - final graph = await entrypoint.packageGraph; - return argResults.rest - .expand( - (package) => - graph.transitiveDependencies(package).map((p) => p.name), - ) - .toSet() - .toList(); - } else { - return argResults.rest; - } - } + List get _packagesToUpgrade => argResults.rest; bool get _upgradeNullSafety => argResults.flag('nullsafety') || argResults.flag('null-safety'); @@ -164,7 +142,7 @@ Consider using the Dart 2.19 sdk to migrate to null safety.'''); ); } final changes = - entrypoint.tighten(packagesToUpgrade: await _packagesToUpgrade); + entrypoint.tighten(packagesToUpgrade: _packagesToUpgrade); entrypoint.applyChanges(changes, _dryRun); } } @@ -179,7 +157,7 @@ Consider using the Dart 2.19 sdk to migrate to null safety.'''); Future _runUpgrade(Entrypoint e, {bool onlySummary = false}) async { await e.acquireDependencies( SolveType.upgrade, - unlock: await _packagesToUpgrade, + unlock: _packagesToUpgrade, dryRun: _dryRun, precompile: _precompile, summaryOnly: onlySummary, @@ -193,7 +171,7 @@ Consider using the Dart 2.19 sdk to migrate to null safety.'''); /// given. /// /// This assumes that `--major-versions` was passed. - Future> _directDependenciesToUpgrade() async { + List _directDependenciesToUpgrade() { assert(_upgradeMajorVersions); final directDeps = { @@ -202,13 +180,12 @@ Consider using the Dart 2.19 sdk to migrate to null safety.'''); ...package.devDependencies.keys, ], }.toList(); - final packagesToUpgrade = await _packagesToUpgrade; final toUpgrade = - packagesToUpgrade.isEmpty ? directDeps : packagesToUpgrade; + _packagesToUpgrade.isEmpty ? directDeps : _packagesToUpgrade; // Check that all package names in upgradeOnly are direct-dependencies final notInDeps = toUpgrade.where((n) => !directDeps.contains(n)); - if (argResults.rest.any(notInDeps.contains)) { + if (toUpgrade.any(notInDeps.contains)) { usageException(''' Dependencies specified in `$topLevelProgram pub upgrade --major-versions ` must be direct 'dependencies' or 'dev_dependencies', following packages are not: @@ -221,7 +198,7 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not: } Future _runUpgradeMajorVersions() async { - final toUpgrade = await _directDependenciesToUpgrade(); + final toUpgrade = _directDependenciesToUpgrade(); // Solve [resolvablePubspec] in-memory and consolidate the resolved // versions of the packages into a map for quick searching. final resolvedPackages = {}; @@ -290,7 +267,7 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not: }), ); changes = entrypoint.tighten( - packagesToUpgrade: await _packagesToUpgrade, + packagesToUpgrade: _packagesToUpgrade, existingChanges: changes, packageVersions: solveResult.packages, ); @@ -302,7 +279,7 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not: // But without a specific package we want to get as many non-major updates // as possible (SolveType.upgrade). final solveType = - (await _packagesToUpgrade).isEmpty ? SolveType.upgrade : SolveType.get; + _packagesToUpgrade.isEmpty ? SolveType.upgrade : SolveType.get; entrypoint.applyChanges(changes, _dryRun); await entrypoint.withUpdatedRootPubspecs({ @@ -313,7 +290,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not: solveType, dryRun: _dryRun, precompile: !_dryRun && _precompile, - unlock: await _packagesToUpgrade, ); // If any of the packages to upgrade are dependency overrides, then we diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart index 693c9a2c1..f57aeb9e7 100644 --- a/lib/src/entrypoint.dart +++ b/lib/src/entrypoint.dart @@ -515,7 +515,7 @@ See $workspacesDocUrl for more information.''', /// pubspec.yaml and all dependencies downloaded. Future acquireDependencies( SolveType type, { - Iterable unlock = const [], + Iterable? unlock, bool dryRun = false, bool precompile = false, bool summaryOnly = false, @@ -547,7 +547,7 @@ Try running `$topLevelProgram pub get` to create `$lockFilePath`.'''); cache, workspaceRoot, lockFile: lockFile, - unlock: unlock, + unlock: unlock ?? [], ); }); } on SolveFailure catch (e) { @@ -557,7 +557,7 @@ Try running `$topLevelProgram pub get` to create `$lockFilePath`.'''); this, type, e.incompatibility, - unlock, + unlock ?? [], cache, ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 5ff42ae3d..423b53d7c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,7 +26,7 @@ dependencies: tar: ^2.0.0 typed_data: ^1.3.2 yaml: ^3.1.2 - yaml_edit: ^2.2.1 + yaml_edit: ^2.1.1 dev_dependencies: checks: ^0.3.0 diff --git a/test/testdata/goldens/help_test/pub upgrade --help.txt b/test/testdata/goldens/help_test/pub upgrade --help.txt index aea028b80..2721d13ed 100644 --- a/test/testdata/goldens/help_test/pub upgrade --help.txt +++ b/test/testdata/goldens/help_test/pub upgrade --help.txt @@ -10,7 +10,6 @@ Usage: pub upgrade [dependencies...] -n, --dry-run Report what dependencies would change but don't change any. --[no-]precompile Precompile executables in immediate dependencies. --tighten Updates lower bounds in pubspec.yaml to match the resolved version. - --[no-]transitive Also upgrades the transitive dependencies of the listed [dependencies] --major-versions Upgrades packages to their latest resolvable versions, and updates pubspec.yaml. -C, --directory= Run this in the directory .