Skip to content

Commit

Permalink
Fix BackgroundWorker imports generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyaulee committed Jan 25, 2025
1 parent b3ddcfd commit 477f42a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@
<ProjectReference Include="..\Blazor.BrowserExtension.Analyzer\Blazor.BrowserExtension.Analyzer.csproj" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Blazor.BrowserExtension.Build.Test" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Build.Framework;
using Blazor.BrowserExtension.Build.Tasks.Helpers;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -104,7 +105,7 @@ private static List<string> GetImports(ITaskItem[] jsAssets, string[] includeCon
private static string GetRelativePath(ITaskItem item)
{
var basePath = item.GetMetadata("BasePath");
var relativePath = item.GetMetadata("RelativePath");
var relativePath = FingerprintHelper.RemoveFingerprintSegment(item.GetMetadata("RelativePath"));
return string.Join("/", Path.Combine(basePath, relativePath).Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries).Select(part => part.TrimStart('_')));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.RegularExpressions;

namespace Blazor.BrowserExtension.Build.Tasks.Helpers
{
internal static partial class FingerprintHelper
{

#if NET7_0_OR_GREATER
[GeneratedRegex(@"#\[.+\][!\?]?")]
private static partial Regex GetFingerprintRegex();
#else
private static Regex GetFingerprintRegex() => new(@"#\[.+\][!\?]?");
#endif

public static string RemoveFingerprintSegment(string path)
{
return GetFingerprintRegex().Replace(path, string.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

<ItemGroup>
<_StaticWebAsset_Build_JsAssets Include="@(StaticWebAsset)" Condition="$([System.String]::new('%(RelativePath)').EndsWith('.js'))" />
<_StaticWebAsset_Build_JsAssets Include="@(WasmStaticWebAsset)" Condition="$([System.String]::new('%(RelativePath)').EndsWith('.js'))" />
</ItemGroup>

<Message Importance="normal" Text="Generating background worker file '$(_BrowserExtension_Project_IntermediateOutput_BackgroundWorkerFile_FilePath)'" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Blazor.BrowserExtension.Build.Tasks.Helpers;
using FluentAssertions;
using Xunit;

namespace Blazor.BrowserExtension.Build.Test.Tasks.Helpers
{
public class FingerprintHelperTest
{
[Theory]
[InlineData("app#[.{fingerprint}]?.js", "app.js")]
public void TestRemoveFingerprintSegment(string input, string expected)
{
// Act
var actual = FingerprintHelper.RemoveFingerprintSegment(input);

// Assert
actual.Should().Be(expected);
}
}
}

0 comments on commit 477f42a

Please sign in to comment.