Skip to content

Commit

Permalink
Revert --unlock-transitive
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm committed Oct 7, 2024
1 parent a2026fa commit e04e13c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 38 deletions.
42 changes: 9 additions & 33 deletions lib/src/command/upgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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, '
Expand Down Expand Up @@ -107,27 +101,11 @@ class UpgradeCommand extends PubCommand {

bool get _precompile => argResults.flag('precompile');

late final Future<List<String>> _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<List<String>> _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<String> get _packagesToUpgrade => argResults.rest;

bool get _upgradeNullSafety =>
argResults.flag('nullsafety') || argResults.flag('null-safety');
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -179,7 +157,7 @@ Consider using the Dart 2.19 sdk to migrate to null safety.''');
Future<void> _runUpgrade(Entrypoint e, {bool onlySummary = false}) async {
await e.acquireDependencies(
SolveType.upgrade,
unlock: await _packagesToUpgrade,
unlock: _packagesToUpgrade,
dryRun: _dryRun,
precompile: _precompile,
summaryOnly: onlySummary,
Expand All @@ -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<List<String>> _directDependenciesToUpgrade() async {
List<String> _directDependenciesToUpgrade() {
assert(_upgradeMajorVersions);

final directDeps = {
Expand All @@ -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 <dependencies>` must
be direct 'dependencies' or 'dev_dependencies', following packages are not:
Expand All @@ -221,7 +198,7 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
}

Future<void> _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 = <String, PackageId>{};
Expand Down Expand Up @@ -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,
);
Expand All @@ -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({
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/src/entrypoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ See $workspacesDocUrl for more information.''',
/// pubspec.yaml and all dependencies downloaded.
Future<void> acquireDependencies(
SolveType type, {
Iterable<String> unlock = const [],
Iterable<String>? unlock,
bool dryRun = false,
bool precompile = false,
bool summaryOnly = false,
Expand Down Expand Up @@ -547,7 +547,7 @@ Try running `$topLevelProgram pub get` to create `$lockFilePath`.''');
cache,
workspaceRoot,
lockFile: lockFile,
unlock: unlock,
unlock: unlock ?? [],
);
});
} on SolveFailure catch (e) {
Expand All @@ -557,7 +557,7 @@ Try running `$topLevelProgram pub get` to create `$lockFilePath`.''');
this,
type,
e.incompatibility,
unlock,
unlock ?? [],
cache,
),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/testdata/goldens/help_test/pub upgrade --help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=<dir> Run this in the directory <dir>.

Expand Down

0 comments on commit e04e13c

Please sign in to comment.