Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert upgrade --unlock-transitive #4404

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading