Skip to content

Commit f33a5e7

Browse files
Update RazorSDK for latest Razor Compiler API breaking changes
1 parent 7aaefaf commit f33a5e7

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

src/RazorSdk/Tool/CompositeRazorProjectFileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override IEnumerable<RazorProjectItem> EnumerateItems(string basePath)
2727
}
2828
}
2929

30-
public override RazorProjectItem GetItem(string path, string fileKind)
30+
public override RazorProjectItem GetItem(string path, RazorFileKind? fileKind)
3131
{
3232
RazorProjectItem razorProjectItem = null;
3333
foreach (var fileSystem in FileSystems)

src/RazorSdk/Tool/GenerateCommand.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,13 @@ private static SourceItem[] GetSourceItems(List<string> sources, List<string> ou
329329
var items = new SourceItem[sources.Count];
330330
for (var i = 0; i < items.Length; i++)
331331
{
332-
var fileKind = fileKinds.Count > 0 ? fileKinds[i] : "mvc";
332+
var fileKind = fileKinds.Count > 0
333+
? ConvertFileKind(fileKinds[i])
334+
: RazorFileKind.Legacy;
335+
333336
if (AspNetCore.Razor.Language.FileKinds.IsComponent(fileKind))
334337
{
335-
fileKind = AspNetCore.Razor.Language.FileKinds.GetComponentFileKindFromFilePath(sources[i]);
338+
fileKind = GetComponentFileKindFromFilePath(sources[i]);
336339
}
337340

338341
var cssScopeValue = cssScopeAssociations.TryGetValue(sources[i], out var cssScopeIndex)
@@ -345,6 +348,33 @@ private static SourceItem[] GetSourceItems(List<string> sources, List<string> ou
345348
return items;
346349
}
347350

351+
private static RazorFileKind ConvertFileKind(string fileKind)
352+
{
353+
if (string.Equals(fileKind, "component", StringComparison.OrdinalIgnoreCase))
354+
{
355+
return RazorFileKind.Component;
356+
}
357+
358+
if (string.Equals(fileKind, "componentImport", StringComparison.OrdinalIgnoreCase))
359+
{
360+
return RazorFileKind.ComponentImport;
361+
}
362+
363+
if (string.Equals(fileKind, "mvc", StringComparison.OrdinalIgnoreCase))
364+
{
365+
return RazorFileKind.Legacy;
366+
}
367+
368+
return RazorFileKind.Legacy;
369+
}
370+
371+
private static RazorFileKind GetComponentFileKindFromFilePath(string filePath)
372+
{
373+
return AspNetCore.Razor.Language.FileKinds.TryGetFileKindFromPath(filePath, out var kind) && kind != RazorFileKind.Legacy
374+
? kind
375+
: RazorFileKind.Component;
376+
}
377+
348378
private OutputItem[] GenerateCode(RazorProjectEngine engine, SourceItem[] inputs)
349379
{
350380
var outputs = new OutputItem[inputs.Length];
@@ -377,7 +407,7 @@ public OutputItem(
377407

378408
private readonly struct SourceItem
379409
{
380-
public SourceItem(string sourcePath, string outputPath, string physicalRelativePath, string fileKind, string cssScope)
410+
public SourceItem(string sourcePath, string outputPath, string physicalRelativePath, RazorFileKind fileKind, string cssScope)
381411
{
382412
SourcePath = sourcePath;
383413
OutputPath = outputPath;
@@ -397,7 +427,7 @@ public SourceItem(string sourcePath, string outputPath, string physicalRelativeP
397427

398428
public string FilePath { get; }
399429

400-
public string FileKind { get; }
430+
public RazorFileKind FileKind { get; }
401431

402432
public string CssScope { get; }
403433
}

test/Microsoft.NET.Sdk.Razor.Tool.Tests/NotFoundProjectItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ internal class NotFoundProjectItem : RazorProjectItem
1616
/// <param name="basePath">The base path.</param>
1717
/// <param name="path">The path.</param>
1818
/// <param name="fileKind">The file kind</param>
19-
public NotFoundProjectItem(string basePath, string path, string fileKind)
19+
public NotFoundProjectItem(string basePath, string path, RazorFileKind? fileKind)
2020
{
2121
BasePath = basePath;
2222
FilePath = path;
23-
FileKind = fileKind ?? FileKinds.GetFileKindFromFilePath(path);
23+
FileKind = fileKind ?? FileKinds.GetFileKindFromPath(path);
2424
}
2525

2626
/// <inheritdoc />
@@ -30,7 +30,7 @@ public NotFoundProjectItem(string basePath, string path, string fileKind)
3030
public override string FilePath { get; }
3131

3232
/// <inheritdoc />
33-
public override string FileKind { get; }
33+
public override RazorFileKind FileKind { get; }
3434

3535
/// <inheritdoc />
3636
public override bool Exists => false;

test/Microsoft.NET.Sdk.Razor.Tool.Tests/TestRazorProjectItem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ namespace Microsoft.AspNetCore.Razor.Language
77
{
88
public class TestRazorProjectItem : RazorProjectItem
99
{
10-
private readonly string _fileKind;
10+
private readonly RazorFileKind? _fileKind;
1111

1212
public TestRazorProjectItem(
1313
string filePath,
1414
string physicalPath = null,
1515
string relativePhysicalPath = null,
1616
string basePath = "/",
17-
string fileKind = null,
17+
RazorFileKind? fileKind = null,
1818
string cssScope = null)
1919
{
2020
FilePath = filePath;
@@ -27,7 +27,7 @@ public TestRazorProjectItem(
2727

2828
public override string BasePath { get; }
2929

30-
public override string FileKind => _fileKind ?? base.FileKind;
30+
public override RazorFileKind FileKind => _fileKind ?? base.FileKind;
3131

3232
public override string FilePath { get; }
3333

0 commit comments

Comments
 (0)