Skip to content

Commit a2cff69

Browse files
Optimize polyfill with embedded options (#3805)
* chore(deps): update dependency polyfill to v9 * chore: enable embedded polyfill option for specific target frameworks * chore: replace FilePolyfill usage with direct File methods and clean up polyfill references * chore: update .NET version from net9.0 to net10.0 across multiple modules --------- Co-authored-by: Renovate Bot <renovate@whitesourcesoftware.com>
1 parent 5fff6ab commit a2cff69

File tree

26 files changed

+50
-58
lines changed

26 files changed

+50
-58
lines changed

.github/actions/execute-pipeline/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ inputs:
2323
netversion:
2424
description: 'Net version'
2525
required: false
26-
default: 'net9.0'
26+
default: 'net10.0'
2727

2828
runs:
2929
using: "composite"

Directory.Build.props

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,16 @@
6969
<None Include="$(MSBuildThisFileDirectory)assets/logo.jpg" Pack="true" PackagePath="\" />
7070
</ItemGroup>
7171

72-
</Project>
72+
<PropertyGroup>
73+
<PolyUseEmbeddedAttribute>true</PolyUseEmbeddedAttribute>
74+
</PropertyGroup>
75+
76+
<!-- Include Polyfill for all target frameworks in internal projects -->
77+
<ItemGroup>
78+
<PackageReference Include="Polyfill">
79+
<PrivateAssets>all</PrivateAssets>
80+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
81+
</PackageReference>
82+
</ItemGroup>
83+
84+
</Project>

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<PackageVersion Include="OneOf" Version="3.0.271" />
6060
<PackageVersion Include="OneOf.SourceGenerator" Version="3.0.271" />
6161
<PackageVersion Include="Polly" Version="8.6.4" />
62-
<PackageVersion Include="Polyfill" Version="8.9.1" />
62+
<PackageVersion Include="Polyfill" Version="9.0.1" />
6363
<PackageVersion Include="PublicApiGenerator" Version="11.5.0" />
6464
<PackageVersion Include="RandomDataGenerator.Net" Version="1.0.19.1" />
6565
<PackageVersion Include="Shouldly" Version="4.3.0" />

Polyfill.targets

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
<Project>
2-
<PropertyGroup Condition="'$(EnableTUnitPolyfills)' != 'false'">
3-
<PolyUseEmbeddedAttribute>true</PolyUseEmbeddedAttribute>
4-
</PropertyGroup>
5-
6-
<ItemGroup Condition="'$(EnableTUnitPolyfills)' != 'false'">
7-
<PackageReference Include="Polyfill">
8-
<PrivateAssets>all</PrivateAssets>
9-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
10-
</PackageReference>
11-
</ItemGroup>
2+
<!-- Polyfill is already added by Directory.Build.props for internal projects -->
3+
<!-- For NuGet consumers, it's added by TUnit.Core.targets with embedded attributes -->
124

135
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'!='.NETCoreApp'">
146
<PackageReference Include="System.Threading.Tasks.Extensions" />

Roslyn.props

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
<Project>
2-
3-
<PropertyGroup>
4-
<PolyUseEmbeddedAttribute>true</PolyUseEmbeddedAttribute>
5-
</PropertyGroup>
2+
<!-- Polyfill is added by Directory.Build.props for internal projects -->
63

74
<ItemGroup>
85
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(RoslynVersion).*"/>
96
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(RoslynVersion).*"/>
10-
<PackageReference Include="Polyfill">
11-
<PrivateAssets>all</PrivateAssets>
12-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13-
</PackageReference>
147
</ItemGroup>
158

169
</Project>

TUnit.Assertions.SourceGenerator.Tests/TestsBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Task RunTest(string inputFile, Func<string[], Task> assertions)
3737
public async Task RunTest(string inputFile, RunTestOptions runTestOptions, Func<string[], Task> assertions)
3838
{
3939
#if NET
40-
var source = await FilePolyfill.ReadAllTextAsync(inputFile);
40+
var source = await File.ReadAllTextAsync(inputFile);
4141
#else
4242
var source = File.ReadAllText(inputFile);
4343
#endif
@@ -80,7 +80,7 @@ namespace System.Diagnostics.CodeAnalysis;
8080
public class UnconditionalSuppressMessageAttribute : Attribute;
8181
""",
8282
#if NET
83-
..await Task.WhenAll(runTestOptions.AdditionalFiles.Select(x => FilePolyfill.ReadAllTextAsync(x))),
83+
..await Task.WhenAll(runTestOptions.AdditionalFiles.Select(x => File.ReadAllTextAsync(x))),
8484
#else
8585
..runTestOptions.AdditionalFiles.Select(x => File.ReadAllText(x)),
8686
#endif
@@ -160,8 +160,8 @@ Have you added required references and additional files?
160160

161161
verifyTask = verifyTask.OnVerifyMismatch(async (pair, message, verify) =>
162162
{
163-
var received = await FilePolyfill.ReadAllTextAsync(pair.ReceivedPath);
164-
var verified = await FilePolyfill.ReadAllTextAsync(pair.VerifiedPath);
163+
var received = await File.ReadAllTextAsync(pair.ReceivedPath);
164+
var verified = await File.ReadAllTextAsync(pair.VerifiedPath);
165165

166166
// Better diff message since original one is too large
167167
await Assert.That(Scrub(received)).IsEqualTo(Scrub(verified));

TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void TestMethod()
148148
private async Task RunTestWithInlineSource(string source)
149149
{
150150
var tempFile = Path.GetTempFileName() + ".cs";
151-
await FilePolyfill.WriteAllTextAsync(tempFile, source);
151+
await File.WriteAllTextAsync(tempFile, source);
152152

153153
try
154154
{

TUnit.Core.SourceGenerator.Tests/TestsBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Task RunTest(string inputFile, Func<string[], Task> assertions)
4343
public async Task RunTest(string inputFile, RunTestOptions runTestOptions, Func<string[], Task> assertions)
4444
{
4545
#if NET
46-
var source = await FilePolyfill.ReadAllTextAsync(inputFile);
46+
var source = await File.ReadAllTextAsync(inputFile);
4747
#else
4848
var source = File.ReadAllText(inputFile);
4949
#endif
@@ -86,7 +86,7 @@ namespace System.Diagnostics.CodeAnalysis;
8686
public class UnconditionalSuppressMessageAttribute : Attribute;
8787
""",
8888
#if NET
89-
..await Task.WhenAll(runTestOptions.AdditionalFiles.Select(x => FilePolyfill.ReadAllTextAsync(x))),
89+
..await Task.WhenAll(runTestOptions.AdditionalFiles.Select(x => File.ReadAllTextAsync(x))),
9090
#else
9191
..runTestOptions.AdditionalFiles.Select(x => File.ReadAllText(x)),
9292
#endif
@@ -172,8 +172,8 @@ Have you added required references and additional files?
172172
{
173173
verifyTask = verifyTask.OnVerifyMismatch(async (pair, message, verify) =>
174174
{
175-
var received = await FilePolyfill.ReadAllTextAsync(pair.ReceivedPath);
176-
var verified = await FilePolyfill.ReadAllTextAsync(pair.VerifiedPath);
175+
var received = await File.ReadAllTextAsync(pair.ReceivedPath);
176+
var verified = await File.ReadAllTextAsync(pair.VerifiedPath);
177177

178178
// Better diff message since original one is too large
179179
await Assert.That(Scrub(received)).IsEqualTo(Scrub(verified));

TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void TestWithConfiguration()
9595
private async Task RunTestWithInlineSource(string source)
9696
{
9797
var tempFile = Path.GetTempFileName() + ".cs";
98-
await FilePolyfill.WriteAllTextAsync(tempFile, source);
98+
await File.WriteAllTextAsync(tempFile, source);
9999

100100
try
101101
{

TUnit.Core.SourceGenerator.Tests/Verify.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ public async Task ToTask()
157157

158158
if (!File.Exists(_verifiedPath))
159159
{
160-
await FilePolyfill.WriteAllTextAsync(_receivedPath, NormalizeNewline(final));
160+
await File.WriteAllTextAsync(_receivedPath, NormalizeNewline(final));
161161
throw new InvalidOperationException($"No verified file found for '{name}'.");
162162
}
163163

164-
var approved = await FilePolyfill.ReadAllTextAsync(_verifiedPath);
164+
var approved = await File.ReadAllTextAsync(_verifiedPath);
165165

166166
if (!string.Equals(NormalizeNewline(final), NormalizeNewline(approved), StringComparison.Ordinal))
167167
{
168-
await FilePolyfill.WriteAllTextAsync(_receivedPath, NormalizeNewline(final));
168+
await File.WriteAllTextAsync(_receivedPath, NormalizeNewline(final));
169169

170170
if (_onVerifyMismatch != null)
171171
{

0 commit comments

Comments
 (0)