Skip to content

Commit

Permalink
Search downloaded packages in entire .pub-cache hosted directory in c…
Browse files Browse the repository at this point in the history
…ase path namining changes.
  • Loading branch information
Adam Gic committed Dec 19, 2023
1 parent 1074027 commit c13de4a
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 0.17.0
- bump dart SDK requirements to >=3.0.0
- Search downloaded packages in entire .pub-cache hosted directory in case path namining changes

## Version 0.16.3
- adds more diff result reporting options (cli, json, markdown)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/analyze/package_api_analyzer.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class _$_FileToAnalyzeEntryImpl implements __FileToAnalyzeEntry {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_FileToAnalyzeEntryImpl &&
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/executable_declaration.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class _$ExecutableParameterDeclarationImpl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ExecutableParameterDeclarationImpl &&
Expand Down Expand Up @@ -656,7 +656,7 @@ class _$ExecutableDeclarationImpl extends _ExecutableDeclaration {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ExecutableDeclarationImpl &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/field_declaration.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class _$FieldDeclarationImpl extends _FieldDeclaration {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FieldDeclarationImpl &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/interface_declaration.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class _$InterfaceDeclarationImpl extends _InterfaceDeclaration {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$InterfaceDeclarationImpl &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/package_api.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class _$PackageApiImpl extends _PackageApi {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PackageApiImpl &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/package_dependency.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class _$PackageDependencyImpl implements _PackageDependency {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PackageDependencyImpl &&
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/platform_constraints.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class _$IOSPlatformConstraintsImpl implements _IOSPlatformConstraints {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$IOSPlatformConstraintsImpl &&
Expand Down Expand Up @@ -277,7 +277,7 @@ class _$AndroidPlatformConstraintsImpl implements _AndroidPlatformConstraints {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$AndroidPlatformConstraintsImpl &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/type_alias_declaration.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class _$TypeAliasDeclarationImpl extends _TypeAliasDeclaration {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$TypeAliasDeclarationImpl &&
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/type_hierarchy.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class _$TypeIdentifierImpl extends _TypeIdentifier {
final String packageRelativeLibraryPath;

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$TypeIdentifierImpl &&
Expand Down Expand Up @@ -322,7 +322,7 @@ class _$_TypeHierarchyItemImpl extends __TypeHierarchyItem {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_TypeHierarchyItemImpl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class _$ExecutableParameterDeclarationStorageV3Impl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ExecutableParameterDeclarationStorageV3Impl &&
Expand Down Expand Up @@ -578,7 +578,7 @@ class _$ExecutableDeclarationStorageV3Impl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ExecutableDeclarationStorageV3Impl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class _$FieldDeclarationStorageV3Impl extends _FieldDeclarationStorageV3 {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FieldDeclarationStorageV3Impl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class _$InterfaceDeclarationStorageV3Impl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$InterfaceDeclarationStorageV3Impl &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/storage/v3/package_api_storage_v3.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class _$PackageApiStorageV3Impl extends _PackageApiStorageV3 {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PackageApiStorageV3Impl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class _$PackageDependencyStorageV3Impl extends _PackageDependencyStorageV3 {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PackageDependencyStorageV3Impl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class _$IOSPlatformConstraintsStorageV3Impl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$IOSPlatformConstraintsStorageV3Impl &&
Expand Down Expand Up @@ -307,7 +307,7 @@ class _$AndroidPlatformConstraintsStorageV3Impl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$AndroidPlatformConstraintsStorageV3Impl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class _$TypeAliasDeclarationStorageV3Impl
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$TypeAliasDeclarationStorageV3Impl &&
Expand Down
48 changes: 38 additions & 10 deletions lib/src/tooling/pub_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,54 @@ abstract class PubInteraction {

/// returns the cache path of a package with the given [packageName] and [version]
static String getPackagePathInCache(String packageName, String version) {
String getHostedDirectory(String cacheDir, String hostedUrl) {
return path.join(cacheDir, 'hosted', hostedUrl, '$packageName-$version');
String? findHostedDirectory(List<String> hostedUrls) {
for (final hostedUrl in hostedUrls) {
final packagePath = path.join(hostedUrl, '$packageName-$version');
if (Directory(packagePath).existsSync()) {
return packagePath;
} else {
return null;
}
}
return null;
}

final cacheDir = pubCacheDir;
final hostedDir = path.join(cacheDir, 'hosted');
List<String> hostedDirs = [];

if (Directory(hostedDir).existsSync()) {
Directory(hostedDir)
.listSync()
.map((entity) => entity.path)
.forEach((path) {
if (Directory(path).existsSync()) {
hostedDirs.add(path);
}
});
}

final envHostedUrl = Platform.environment['PUB_HOSTED_URL'];
final envHosted =
envHostedUrl == null ? null : Uri.parse(envHostedUrl).host;
if (envHosted == null) {

final List<String> hostPriorities = [
// first check PUB_HOSTED_URL from environment variable if set
if (envHosted != null) envHosted,
// Flutter 3.7 changed the name of the pub.dev directory => first test the old one, then the new one
var packageDirectory = getHostedDirectory(cacheDir, 'pub.dartlang.org');
if (Directory(packageDirectory).existsSync()) {
return packageDirectory;
'pub.dartlang.org',
'pub.dev',
];

for (final hostPriority in hostPriorities) {
final matchingHostedDirs =
hostedDirs.where((dir) => dir.startsWith(hostPriority)).toList();
final foundPackagePath = findHostedDirectory(matchingHostedDirs);
if (foundPackagePath != null) {
return foundPackagePath;
}
packageDirectory = getHostedDirectory(cacheDir, 'pub.dev');
return packageDirectory;
} else {
return getHostedDirectory(cacheDir, envHosted);
}
return findHostedDirectory(hostedDirs)!;
}

/// runs pub get in the given [packageDirectory]
Expand Down

0 comments on commit c13de4a

Please sign in to comment.