Skip to content

Commit

Permalink
Display package versions from pubspec.lock, improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
greglittlefield-wf committed Aug 6, 2024
1 parent 50b6fc7 commit dc5cb89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
27 changes: 23 additions & 4 deletions lib/src/dart3_suggestors/required_props/bin/collect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:over_react_codemod/src/util/command.dart';
import 'package:over_react_codemod/src/util/command_runner.dart';
import 'package:package_config/package_config.dart';
import 'package:path/path.dart' as p;
import 'package:yaml/yaml.dart';

import '../collect/collected_data.sg.dart';
import '../collect/logging.dart';
Expand Down Expand Up @@ -157,6 +158,7 @@ Instructions

final processedPackages = <String>{};
for (final packageSpec in packages) {
logger.info('Processing $packageSpec...');
final packageName = packageSpec.packageName;
if (processedPackages.contains(packageName)) {
throw Exception('Already processed $packageName');
Expand Down Expand Up @@ -226,8 +228,6 @@ Future<CollectDataForPackageResult?> collectDataForPackage(
final rootPackageName = package.packageName;
final logger = Logger('prop_requiredness.${package.packageAndVersionId}');

logger.info("Collecting raw usage data for $rootPackageName...");

File? outputFile;
if (outputDirectory != null) {
outputFile = File(p.normalize(
Expand Down Expand Up @@ -257,10 +257,29 @@ Future<CollectDataForPackageResult?> collectDataForPackage(
return null;
}

logger.info('Performing pub upgrade to get newer versions of packages...');
// Get latest dependencies, to get latest versions of other packages.
await runCommandAndThrowIfFailed('dart', ['pub', 'upgrade'],
workingDirectory: packageInfo.root);

final packageVersionDescriptionsByName = <String, String>{
rootPackageName: package.sourceDescription,
};
final pubspecLock = loadYaml(
File(p.join(packageInfo.root, 'pubspec.lock')).readAsStringSync()) as Map;
(pubspecLock['packages'] as Map)
.cast<String, Map>()
.forEach((packageName, info) {
final version = info['version'] as String?;
if (version != null) {
packageVersionDescriptionsByName.putIfAbsent(packageName, () => version);
}
});
packageVersionDescriptionsByName[rootPackageName] = package.sourceDescription;
logger.info('Package versions: ${packageVersionDescriptionsByName}');


logger.info("Analyzing and collecting raw usage data...");
final units = getResolvedLibUnitsForPackage(package,
includeDependencyPackages: processDependencyPackages,
packageFilter: packageFilter);
Expand All @@ -270,8 +289,8 @@ Future<CollectDataForPackageResult?> collectDataForPackage(
rootPackageName: rootPackageName,
allowOtherPackageUnits: processDependencyPackages,
);
results.packageVersionDescriptionsByName[rootPackageName] =
package.sourceDescription;
results.packageVersionDescriptionsByName
.addAll(packageVersionDescriptionsByName);

if (outputFile != null) {
outputFile.parent.createSync(recursive: true);
Expand Down
8 changes: 0 additions & 8 deletions lib/src/dart3_suggestors/required_props/collect/collect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ Future<PackageResults> collectDataForUnits(
otherPackagesProcessed.add(packageName);
}

// TODO add version descriptions back in
// if (packageVersionDescriptionsByName[packageName] == null) {
// final versionDescription = packageInfo?.version;
// if (versionDescription != null) {
// packageVersionDescriptionsByName[packageName] = versionDescription;
// }
// }

allUsages.addAll(collectUsageDataForUnit(
unitResult: unitResult,
packageName: packageName,
Expand Down

0 comments on commit dc5cb89

Please sign in to comment.