Skip to content

Commit 632f8f3

Browse files
committed
Changes to PR comments
* Rename some contract types * Remove blazor.webassembly.js
1 parent 85f695e commit 632f8f3

File tree

6 files changed

+64
-69
lines changed

6 files changed

+64
-69
lines changed

src/Components/Blazor/Build/src/Core/BootJsonWriter.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,28 @@ public static string GetBootJsonContent(string entryAssembly, string[] assemblyR
4141
/// </summary>
4242
readonly struct BootJsonData
4343
{
44+
/// <summary>
45+
/// Gets the name of the assembly with the application entry point
46+
/// </summary>
4447
public string EntryAssembly { get; }
45-
public IEnumerable<string> AssemblyReferences { get; }
48+
49+
/// <summary>
50+
/// Gets the closure of assemblies to be loaded by Blazor WASM. This includes the application entry assembly.
51+
/// </summary>
52+
public IEnumerable<string> Assemblies { get; }
53+
54+
/// <summary>
55+
/// Gets a value that determines if the linker is enabled.
56+
/// </summary>
4657
public bool LinkerEnabled { get; }
4758

4859
public BootJsonData(
4960
string entryAssembly,
50-
IEnumerable<string> assemblyReferences,
61+
IEnumerable<string> assemblies,
5162
bool linkerEnabled)
5263
{
5364
EntryAssembly = entryAssembly;
54-
AssemblyReferences = assemblyReferences;
65+
Assemblies = assemblies;
5566
LinkerEnabled = linkerEnabled;
5667
}
5768
}

src/Components/Blazor/Build/src/Core/RuntimeDependenciesResolver.cs

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,44 @@ public static IEnumerable<string> ResolveRuntimeDependenciesCore(
2929
string[] applicationDependencies,
3030
string[] monoBclDirectories)
3131
{
32-
var assembly = new AssemblyEntry(entryPoint, GetAssemblyName(entryPoint));
32+
var entryAssembly = new AssemblyEntry(entryPoint, GetAssemblyName(entryPoint));
3333

34-
var dependencies = applicationDependencies
35-
.Select(a => new AssemblyEntry(a, GetAssemblyName(a)))
36-
.ToArray();
34+
var dependencies = CreateAssemblyLookup(applicationDependencies);
3735

38-
var bcl = monoBclDirectories
39-
.SelectMany(d => Directory.EnumerateFiles(d, "*.dll").Select(f => Path.Combine(d, f)))
40-
.Select(a => new AssemblyEntry(a, GetAssemblyName(a)))
41-
.ToArray();
36+
var bcl = CreateAssemblyLookup(monoBclDirectories
37+
.SelectMany(d => Directory.EnumerateFiles(d, "*.dll").Select(f => Path.Combine(d, f))));
4238

4339
var assemblyResolutionContext = new AssemblyResolutionContext(
44-
assembly,
40+
entryAssembly,
4541
dependencies,
4642
bcl);
4743

4844
assemblyResolutionContext.ResolveAssemblies();
4945

5046
var paths = assemblyResolutionContext.Results.Select(r => r.Path);
5147
return paths.Concat(FindPdbs(paths));
48+
49+
static Dictionary<string, AssemblyEntry> CreateAssemblyLookup(IEnumerable<string> assemblyPaths)
50+
{
51+
var dictionary = new Dictionary<string, AssemblyEntry>(StringComparer.Ordinal);
52+
foreach (var path in assemblyPaths)
53+
{
54+
var assemblyName = AssemblyName.GetAssemblyName(path).Name;
55+
if (dictionary.TryGetValue(assemblyName, out var previous))
56+
{
57+
throw new InvalidOperationException($"Multiple assemblies found with the same assembly name '{assemblyName}':" +
58+
Environment.NewLine + string.Join(Environment.NewLine, previous, path));
59+
}
60+
dictionary[assemblyName] = new AssemblyEntry(path, assemblyName);
61+
}
62+
63+
return dictionary;
64+
}
5265
}
5366

54-
private static string GetAssemblyName(string entryPoint)
67+
private static string GetAssemblyName(string assemblyPath)
5568
{
56-
return AssemblyName.GetAssemblyName(entryPoint).Name;
69+
return AssemblyName.GetAssemblyName(assemblyPath).Name;
5770
}
5871

5972
private static IEnumerable<string> FindPdbs(IEnumerable<string> dllPaths)
@@ -66,26 +79,26 @@ private static IEnumerable<string> FindPdbs(IEnumerable<string> dllPaths)
6679
public class AssemblyResolutionContext
6780
{
6881
public AssemblyResolutionContext(
69-
AssemblyEntry assembly,
70-
AssemblyEntry[] dependencies,
71-
AssemblyEntry[] bcl)
82+
AssemblyEntry entryAssembly,
83+
Dictionary<string, AssemblyEntry> dependencies,
84+
Dictionary<string, AssemblyEntry> bcl)
7285
{
73-
Assembly = assembly;
86+
EntryAssembly = entryAssembly;
7487
Dependencies = dependencies;
7588
Bcl = bcl;
7689
}
7790

78-
public AssemblyEntry Assembly { get; }
79-
public AssemblyEntry[] Dependencies { get; }
80-
public AssemblyEntry[] Bcl { get; }
91+
public AssemblyEntry EntryAssembly { get; }
92+
public Dictionary<string, AssemblyEntry> Dependencies { get; }
93+
public Dictionary<string, AssemblyEntry> Bcl { get; }
8194

8295
public IList<AssemblyEntry> Results { get; } = new List<AssemblyEntry>();
8396

8497
internal void ResolveAssemblies()
8598
{
8699
var visitedAssemblies = new HashSet<string>();
87100
var pendingAssemblies = new Stack<string>();
88-
pendingAssemblies.Push(Assembly.Name);
101+
pendingAssemblies.Push(EntryAssembly.Name);
89102
ResolveAssembliesCore();
90103

91104
void ResolveAssembliesCore()
@@ -96,8 +109,7 @@ void ResolveAssembliesCore()
96109
{
97110
// Not all references will be resolvable within the Mono BCL.
98111
// Skipping unresolved assemblies here is equivalent to passing "--skip-unresolved true" to the Mono linker.
99-
var resolved = Resolve(current);
100-
if (resolved != null)
112+
if (Resolve(current) is AssemblyEntry resolved)
101113
{
102114
Results.Add(resolved);
103115
var references = GetAssemblyReferences(resolved.Path);
@@ -110,17 +122,22 @@ void ResolveAssembliesCore()
110122
}
111123
}
112124

113-
AssemblyEntry Resolve(string assemblyName)
125+
AssemblyEntry? Resolve(string assemblyName)
114126
{
115-
if (Assembly.Name == assemblyName)
127+
if (EntryAssembly.Name == assemblyName)
116128
{
117-
return Assembly;
129+
return EntryAssembly;
118130
}
119131

120132
// Resolution logic. For right now, we will prefer the mono BCL version of a given
121133
// assembly if there is a candidate assembly and an equivalent mono assembly.
122-
return Bcl.FirstOrDefault(c => c.Name == assemblyName) ??
123-
Dependencies.FirstOrDefault(c => c.Name == assemblyName);
134+
if (Bcl.TryGetValue(assemblyName, out var assembly) ||
135+
Dependencies.TryGetValue(assemblyName, out assembly))
136+
{
137+
return assembly;
138+
}
139+
140+
return null;
124141
}
125142

126143
static IReadOnlyList<string> GetAssemblyReferences(string assemblyPath)
@@ -157,16 +174,16 @@ static IReadOnlyList<string> GetAssemblyReferences(string assemblyPath)
157174
}
158175

159176
[DebuggerDisplay("{ToString(),nq}")]
160-
public class AssemblyEntry
177+
public readonly struct AssemblyEntry
161178
{
162179
public AssemblyEntry(string path, string name)
163180
{
164181
Path = path;
165182
Name = name;
166183
}
167184

168-
public string Path { get; set; }
169-
public string Name { get; set; }
185+
public string Path { get; }
186+
public string Name { get; }
170187

171188
public override string ToString() => Name;
172189
}

src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@
623623
Inputs="$(BlazorBuildBootJsonInputsCache);@(_BlazorDependencyInput)"
624624
Outputs="$(BlazorBootJsonIntermediateOutputPath)">
625625
<ItemGroup>
626-
<_AppReferences Include="@(BlazorItemOutput->WithMetadataValue('Type','Assembly')->WithMetadataValue('PrimaryOutput','')->'%(FileName)%(Extension)')" />
626+
<_AppReferences Include="@(BlazorItemOutput->WithMetadataValue('Type','Assembly')->'%(FileName)%(Extension)')" />
627627
<_AppReferences Include="@(BlazorItemOutput->WithMetadataValue('Type','Pdb')->'%(FileName)%(Extension)')" Condition="'$(BlazorEnableDebugging)' == 'true'" />
628628
</ItemGroup>
629629
<PropertyGroup>

src/Components/Blazor/Build/test/BootJsonWriterTest.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using Newtonsoft.Json;
55
using Newtonsoft.Json.Linq;
6-
using System;
7-
using System.Linq;
86
using Xunit;
97

108
namespace Microsoft.AspNetCore.Blazor.Build.Test
@@ -18,45 +16,13 @@ public void ProducesJsonReferencingAssemblyAndDependencies()
1816
var assemblyReferences = new string[] { "System.Abc.dll", "MyApp.ClassLib.dll", };
1917
var content = BootJsonWriter.GetBootJsonContent(
2018
"MyApp.Entrypoint.dll",
21-
"MyNamespace.MyType::MyMethod",
2219
assemblyReferences,
23-
Enumerable.Empty<EmbeddedResourceInfo>(),
2420
linkerEnabled: true);
2521

2622
// Assert
2723
var parsedContent = JsonConvert.DeserializeObject<JObject>(content);
2824
Assert.Equal("MyApp.Entrypoint.dll", parsedContent["main"].Value<string>());
29-
Assert.Equal("MyNamespace.MyType::MyMethod", parsedContent["entryPoint"].Value<string>());
3025
Assert.Equal(assemblyReferences, parsedContent["assemblyReferences"].Values<string>());
3126
}
32-
33-
[Fact]
34-
public void IncludesReferencesToEmbeddedContent()
35-
{
36-
// Arrange/Act
37-
var embeddedContent = new[]
38-
{
39-
new EmbeddedResourceInfo(EmbeddedResourceKind.Static, "my/static/file"),
40-
new EmbeddedResourceInfo(EmbeddedResourceKind.Css, "css/first.css"),
41-
new EmbeddedResourceInfo(EmbeddedResourceKind.JavaScript, "javascript/first.js"),
42-
new EmbeddedResourceInfo(EmbeddedResourceKind.Css, "css/second.css"),
43-
new EmbeddedResourceInfo(EmbeddedResourceKind.JavaScript, "javascript/second.js"),
44-
};
45-
var content = BootJsonWriter.GetBootJsonContent(
46-
"MyApp.Entrypoint",
47-
"MyNamespace.MyType::MyMethod",
48-
assemblyReferences: new[] { "Something.dll" },
49-
embeddedContent: embeddedContent,
50-
linkerEnabled: true);
51-
52-
// Assert
53-
var parsedContent = JsonConvert.DeserializeObject<JObject>(content);
54-
Assert.Equal(
55-
new[] { "css/first.css", "css/second.css" },
56-
parsedContent["cssReferences"].Values<string>());
57-
Assert.Equal(
58-
new[] { "javascript/first.js", "javascript/second.js" },
59-
parsedContent["jsReferences"].Values<string>());
60-
}
6127
}
6228
}

src/Components/Web.JS/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
22
dist/Debug/
3+
dist/Release/blazor.webassembly.js

src/Components/Web.JS/src/Boot.WebAssembly.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function boot(options?: any): Promise<void> {
4444
}
4545

4646
// Determine the URLs of the assemblies we want to load, then begin fetching them all
47-
const loadAssemblyUrls = bootConfig.assemblyReferences
47+
const loadAssemblyUrls = bootConfig.assemblies
4848
.map(filename => `_framework/_bin/${filename}`);
4949

5050
try {
@@ -67,7 +67,7 @@ async function fetchBootConfigAsync() {
6767
// Keep in sync with BootJsonData in Microsoft.AspNetCore.Blazor.Build
6868
interface BootJsonData {
6969
entryAssembly: string;
70-
assemblyReferences: string[];
70+
assemblies: string[];
7171
linkerEnabled: boolean;
7272
}
7373

0 commit comments

Comments
 (0)