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
8 changes: 1 addition & 7 deletions src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ internal sealed class BundleNuGetPackageCache : INuGetPackageCache
private readonly ILogger<BundleNuGetPackageCache> _logger;
private readonly IFeatures _features;

// List of deprecated packages that should be filtered by default
private static readonly HashSet<string> s_deprecatedPackages = new(StringComparer.OrdinalIgnoreCase)
{
"Aspire.Hosting.Dapr"
};

public BundleNuGetPackageCache(
IBundleService bundleService,
ILogger<BundleNuGetPackageCache> logger,
Expand Down Expand Up @@ -226,7 +220,7 @@ private IEnumerable<NuGetPackage> FilterPackages(IEnumerable<NuGetPackage> packa
// Apply deprecated package filter unless the user wants to show deprecated packages
if (isOfficialPackage && !_features.IsFeatureEnabled(KnownFeatures.ShowDeprecatedPackages, defaultValue: false))
{
return !s_deprecatedPackages.Contains(p.Id);
return !DeprecatedPackages.IsDeprecated(p.Id);
}

return isOfficialPackage;
Expand Down
23 changes: 16 additions & 7 deletions src/Aspire.Cli/NuGet/NuGetPackageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Aspire.Cli.DotNet;
using Aspire.Cli.Resources;
using System.Collections.Frozen;
using System.Globalization;
using Aspire.Cli.Telemetry;
using Microsoft.Extensions.Caching.Memory;
Expand All @@ -19,15 +20,23 @@ internal interface INuGetPackageCache
Task<IEnumerable<NuGetPackage>> GetPackagesAsync(DirectoryInfo workingDirectory, string packageId, Func<string, bool>? filter, bool prerelease, FileInfo? nugetConfigFile, bool useCache, CancellationToken cancellationToken);
}

/// <summary>
/// Packages that have been superseded and should be hidden from integration listings by default.
/// </summary>
internal static class DeprecatedPackages
{
private static readonly FrozenSet<string> s_all = new[]
{
"Aspire.Hosting.Dapr",
"Aspire.Hosting.NodeJs"
}.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use one of the StringComparers


public static bool IsDeprecated(string packageId) => s_all.Contains(packageId);
}

internal sealed class NuGetPackageCache(IDotNetCliRunner cliRunner, IMemoryCache memoryCache, AspireCliTelemetry telemetry, IFeatures features) : INuGetPackageCache
{
private const int SearchPageSize = 1000;

// List of deprecated packages that should be filtered by default
private static readonly HashSet<string> s_deprecatedPackages = new(StringComparer.OrdinalIgnoreCase)
{
"Aspire.Hosting.Dapr"
};

public async Task<IEnumerable<NuGetPackage>> GetTemplatePackagesAsync(DirectoryInfo workingDirectory, bool prerelease, FileInfo? nugetConfigFile, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -133,7 +142,7 @@ public async Task<IEnumerable<NuGetPackage>> GetPackagesAsync(DirectoryInfo work
// Apply deprecated package filter unless the user wants to show deprecated packages
if (isOfficialPackage && !features.IsFeatureEnabled(KnownFeatures.ShowDeprecatedPackages, defaultValue: false))
{
return !s_deprecatedPackages.Contains(p.Id);
return !DeprecatedPackages.IsDeprecated(p.Id);
}

return isOfficialPackage;
Expand Down
4 changes: 4 additions & 0 deletions tests/Aspire.Cli.Tests/NuGet/NuGetPackageCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public async Task DeprecatedPackagesAreFilteredByDefault()
return (0, [
new NuGetPackage { Id = "Aspire.Hosting.Redis", Version = "9.4.0", Source = "nuget.org" },
new NuGetPackage { Id = "Aspire.Hosting.Dapr", Version = "9.4.0", Source = "nuget.org" }, // Deprecated
new NuGetPackage { Id = "Aspire.Hosting.NodeJs", Version = "9.4.0", Source = "nuget.org" }, // Deprecated
new NuGetPackage { Id = "Aspire.Hosting.PostgreSQL", Version = "9.4.0", Source = "nuget.org" }
]);
};
Expand All @@ -78,6 +79,7 @@ public async Task DeprecatedPackagesAreFilteredByDefault()
Assert.Contains("Aspire.Hosting.Redis", packageIds);
Assert.Contains("Aspire.Hosting.PostgreSQL", packageIds);
Assert.DoesNotContain("Aspire.Hosting.Dapr", packageIds);
Assert.DoesNotContain("Aspire.Hosting.NodeJs", packageIds);
}

[Fact]
Expand All @@ -98,6 +100,7 @@ public async Task DeprecatedPackagesAreIncludedWhenShowDeprecatedPackagesEnabled
return (0, [
new NuGetPackage { Id = "Aspire.Hosting.Redis", Version = "9.4.0", Source = "nuget.org" },
new NuGetPackage { Id = "Aspire.Hosting.Dapr", Version = "9.4.0", Source = "nuget.org" }, // Deprecated
new NuGetPackage { Id = "Aspire.Hosting.NodeJs", Version = "9.4.0", Source = "nuget.org" }, // Deprecated
new NuGetPackage { Id = "Aspire.Hosting.PostgreSQL", Version = "9.4.0", Source = "nuget.org" }
]);
};
Expand All @@ -116,6 +119,7 @@ public async Task DeprecatedPackagesAreIncludedWhenShowDeprecatedPackagesEnabled
Assert.Contains("Aspire.Hosting.Redis", packageIds);
Assert.Contains("Aspire.Hosting.PostgreSQL", packageIds);
Assert.Contains("Aspire.Hosting.Dapr", packageIds);
Assert.Contains("Aspire.Hosting.NodeJs", packageIds);
}

[Fact]
Expand Down
Loading