Skip to content
Merged
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
2 changes: 1 addition & 1 deletion app/bin/tools/search_benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Future<void> main(List<String> args) async {
final snapshot = SearchSnapshot.fromJson(content);
final index = InMemoryPackageIndex(
documents:
snapshot.documents!.values.where((d) => !isSoftRemoved(d.package)));
snapshot.documents!.values.where((d) => !isSdkPackage(d.package)));

// NOTE: please add more queries to this list, especially if there is a performance bottleneck.
final queries = [
Expand Down
2 changes: 1 addition & 1 deletion app/lib/frontend/handlers/custom_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import 'cache_control.dart';
Future<shelf.Response> apiDocumentationHandler(
shelf.Request request, String package) async {
checkPackageVersionParams(package);
if (isSoftRemoved(package)) {
if (isSdkPackage(package)) {
return jsonResponse({}, status: 404);
}

Expand Down
4 changes: 2 additions & 2 deletions app/lib/frontend/handlers/documentation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Future<shelf.Response> documentationHandler(shelf.Request request) async {
return notFoundHandler(request);
}
checkPackageVersionParams(docFilePath.package, docFilePath.version);
if (redirectPackageUrls.containsKey(docFilePath.package)) {
return redirectResponse(redirectPackageUrls[docFilePath.package]!);
if (isSdkPackage(docFilePath.package)) {
return redirectResponse(sdkPackageUrls[docFilePath.package]!);
}
if (!await packageBackend.isPackageVisible(docFilePath.package)) {
return notFoundHandler(request);
Expand Down
8 changes: 4 additions & 4 deletions app/lib/frontend/handlers/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ Future<shelf.Response> packageScoreLogTxtHandler(
String? version,
}) async {
checkPackageVersionParams(package, version);
if (redirectPackageUrls.containsKey(package)) {
return redirectResponse(redirectPackageUrls[package]!);
if (isSdkPackage(package)) {
return redirectResponse(sdkPackageUrls[package]!);
}
if (!await packageBackend.isPackageVisible(package)) {
return shelf.Response.notFound('no such package');
Expand Down Expand Up @@ -289,8 +289,8 @@ Future<shelf.Response> _handlePackagePage({
if (request.requestedUri.path != canonicalUrl) {
return redirectResponse(canonicalUrl);
}
if (redirectPackageUrls.containsKey(packageName)) {
return redirectResponse(redirectPackageUrls[packageName]!);
if (isSdkPackage(packageName)) {
return redirectResponse(sdkPackageUrls[packageName]!);
}
final Stopwatch sw = Stopwatch()..start();
String? cachedPage;
Expand Down
4 changes: 2 additions & 2 deletions app/lib/frontend/templates/views/pkg/info_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:pub_dev/service/download_counts/download_counts.dart';
import 'package:pubspec_parse/pubspec_parse.dart' as pubspek;

import '../../../../package/models.dart';
import '../../../../package/overrides.dart' show redirectPackageUrls;
import '../../../../package/overrides.dart' show sdkPackageUrls;
import '../../../../package/screenshots/backend.dart';
import '../../../../service/topics/models.dart';
import '../../../../shared/urls.dart' as urls;
Expand Down Expand Up @@ -238,7 +238,7 @@ d.Node? _dependencyListNode(Map<String, pubspek.Dependency>? dependencies) {
nodes.add(d.text(', '));
}
final dep = dependencies[p];
var href = redirectPackageUrls[p];
var href = sdkPackageUrls[p];
String? constraint;
if (href == null && dep is pubspek.HostedDependency) {
href = urls.pkgPageUrl(p);
Expand Down
6 changes: 3 additions & 3 deletions app/lib/package/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class PackageBackend {
.run()
.where((p) => p.isVisible)
.where((p) => p.isIncludedInRobots)
.where((p) => !isSoftRemoved(p.name!));
.where((p) => !isSdkPackage(p.name!));
}

/// Retrieves package versions ordered by their published date descending.
Expand All @@ -150,7 +150,7 @@ class PackageBackend {
final versions = await query.run().toList();
final results = <PackageVersion>[];
for (final v in versions) {
if (isSoftRemoved(v.package)) continue;
if (isSdkPackage(v.package)) continue;
if (!(await isPackageVisible(v.package))) continue;
results.add(v);
}
Expand Down Expand Up @@ -1011,7 +1011,7 @@ class PackageBackend {
// purpose of checking if the dependency exists, we skip them.
continue;
}
if (isSoftRemoved(name)) {
if (isSdkPackage(name)) {
continue;
}
if (nameTracker.hasPackage(name)) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/package/name_tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TrackedPackage {
updated: p.updated!,
latestVersion: p.latestVersion!,
lastPublished: p.lastVersionPublished!,
isVisible: p.isVisible && !isSoftRemoved(p.name!),
isVisible: p.isVisible && !isSdkPackage(p.name!),
);

@visibleForTesting
Expand Down
13 changes: 8 additions & 5 deletions app/lib/package/overrides.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ final _reservedPackageNames = <String>[
'flutterkit',
].map(reducePackageName).toList();

const redirectPackageUrls = <String, String>{
/// Mapping packages names to URLs that we need to redirect them to after they become SDK packages.
const sdkPackageUrls = <String, String>{
'flutter': 'https://api.flutter.dev/',
'flutter_driver':
'https://api.flutter.dev/flutter/flutter_driver/flutter_driver-library.html',
Expand Down Expand Up @@ -81,10 +82,12 @@ const devDependencyPackages = <String>{
'test_process',
};

/// A package is soft-removed when we keep it in the archives and index, but we
/// won't serve the package or the documentation page, or any data about it.
bool isSoftRemoved(String packageName) =>
redirectPackageUrls.containsKey(packageName);
/// A package may become an SDK package, after which we redirect
/// their UI page to a new location.
///
/// Note: we keep them in the archives, and keep serving their API information.
bool isSdkPackage(String packageName) =>
sdkPackageUrls.containsKey(packageName);

/// Whether the [name] is (very similar) to a reserved package name.
bool matchesReservedPackageName(String name) =>
Expand Down
2 changes: 1 addition & 1 deletion app/lib/search/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class SearchBackend {
if (!claim.valid) {
return;
}
if (isSoftRemoved(package)) {
if (isSdkPackage(package)) {
return;
}
// Skip if the last document timestamp is before [updated].
Expand Down