Skip to content

Commit cc67437

Browse files
committed
Amend Build project to target netstandard2.1
1 parent 3e58485 commit cc67437

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/GovUk.Frontend.AspNetCore.Build/DownloadNpmPackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override bool Execute()
3434

3535
async Task ExecuteAsync()
3636
{
37-
var includePatterns = Include?.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? ["**"];
37+
var includePatterns = Include?.Split('\n', StringSplitOptions.RemoveEmptyEntries)?.Select(s => s.Trim()) ?? ["**"];
3838

3939
var downloader = new NpmPackageDownloader();
4040
await downloader.DownloadPackage(Package, Version, PackageBaseDirectory ?? "", DestinationDirectory, includePatterns);

src/GovUk.Frontend.AspNetCore.Build/GovUk.Frontend.AspNetCore.Build.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>netstandard2.1</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<PackDependencies>false</PackDependencies>
77
<PackFolder>tools</PackFolder>
@@ -16,6 +16,7 @@
1616
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.8.27" />
1717
<!-- TODO Figure out how to get this out of the generated NuGet package's dependency list -->
1818
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" Pack="true" PrivateAssets="all" />
19+
<PackageReference Include="System.Text.Json" Version="8.0.5" Pack="true" PrivateAssets="all" />
1920
<PackageReference Include="MinVer" Version="2.3.1">
2021
<PrivateAssets>all</PrivateAssets>
2122
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/GovUk.Frontend.AspNetCore.Build/NpmPackageDownloader.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ public async Task DownloadPackage(
2727
string destinationDirectory,
2828
IEnumerable<string> includePatterns)
2929
{
30-
ArgumentNullException.ThrowIfNull(package);
31-
ArgumentNullException.ThrowIfNull(version);
32-
ArgumentNullException.ThrowIfNull(destinationDirectory);
30+
if (package is null)
31+
{
32+
throw new ArgumentNullException(nameof(package));
33+
}
34+
if (version is null)
35+
{
36+
throw new ArgumentNullException(nameof(version));
37+
}
38+
if (destinationDirectory is null)
39+
{
40+
throw new ArgumentNullException(nameof(destinationDirectory));
41+
}
3342

3443
Directory.CreateDirectory(destinationDirectory);
3544

@@ -60,13 +69,13 @@ public async Task DownloadPackage(
6069

6170
var results = matcher.Execute(contents);
6271

63-
await Parallel.ForEachAsync(
64-
results.Files,
65-
async (r, ct) =>
66-
{
67-
var hash = ((NpmPackageFileInfo)contents.GetFile(r.Path)!).Hash;
68-
await DownloadFileAsync(package, version, r.Path, hash, packageBaseDirectory, destinationDirectory, ct);
69-
});
72+
var tasks = results.Files.Select(r =>
73+
{
74+
var hash = ((NpmPackageFileInfo)contents.GetFile(r.Path)!).Hash;
75+
return DownloadFileAsync(package, version, r.Path, hash, packageBaseDirectory, destinationDirectory, CancellationToken.None);
76+
});
77+
78+
await Task.WhenAll(tasks);
7079
}
7180

7281
private async Task DownloadFileAsync(
@@ -85,7 +94,7 @@ private async Task DownloadFileAsync(
8594
{
8695
await using var efs = File.OpenRead(destinationPath);
8796
using var sha = SHA256.Create();
88-
var currentFileHash = Convert.ToBase64String(await sha.ComputeHashAsync(efs, cancellationToken));
97+
var currentFileHash = Convert.ToBase64String(sha.ComputeHash(efs));
8998

9099
if (currentFileHash == hash)
91100
{
@@ -102,7 +111,7 @@ private async Task DownloadFileAsync(
102111
Directory.CreateDirectory(destinationDirectory);
103112

104113
await using var fs = File.Create(destinationPath);
105-
await response.Content.CopyToAsync(fs, cancellationToken);
114+
await response.Content.CopyToAsync(fs);
106115
}
107116

108117
private async Task<DirectoryInfoBase> GetPackageContentsAsync(string package, string version)

0 commit comments

Comments
 (0)