Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions PowerForge.Tests/ModuleInformationReaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.IO;

namespace PowerForge.Tests;

public sealed class ModuleInformationReaderTests
{
[Fact]
public void Read_PrefersPrereleaseFromPsData()
{
var projectRoot = CreateModuleProject(
"""
@{
RootModule = 'Sample.psm1'
ModuleVersion = '1.2.3'
PrivateData = @{
PSData = @{
Prerelease = 'preview1'
}
}
}
""");

var reader = new ModuleInformationReader();

var result = reader.Read(projectRoot);

Assert.Equal("preview1", result.PreRelease);
}

[Fact]
public void Read_FallsBackToTopLevelPrerelease()
{
var projectRoot = CreateModuleProject(
"""
@{
RootModule = 'Sample.psm1'
ModuleVersion = '1.2.3'
Prerelease = 'beta2'
}
""");

var reader = new ModuleInformationReader();

var result = reader.Read(projectRoot);

Assert.Equal("beta2", result.PreRelease);
}

private static string CreateModuleProject(string manifestContent)
{
var projectRoot = Path.Combine(Path.GetTempPath(), "PowerForgeModuleInformationTests", Path.GetRandomFileName());
Directory.CreateDirectory(projectRoot);

File.WriteAllText(Path.Combine(projectRoot, "Sample.psd1"), manifestContent);
File.WriteAllText(Path.Combine(projectRoot, "Sample.psm1"), string.Empty);

return projectRoot;
}
}
4 changes: 4 additions & 0 deletions PowerForge/Models/ModuleInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public sealed class ModuleInformation
public string? RootModule { get; }
/// <summary>PowerShell version requirement from the manifest (PowerShellVersion).</summary>
public string? PowerShellVersion { get; }
/// <summary>Prerelease label from the manifest when present.</summary>
public string? PreRelease { get; }
/// <summary>GUID value from the manifest (GUID), when present and parseable.</summary>
public Guid? Guid { get; }
/// <summary>Typed RequiredModules entries extracted from the manifest.</summary>
Expand All @@ -36,6 +38,7 @@ public ModuleInformation(
string? moduleVersion,
string? rootModule,
string? powerShellVersion,
string? preRelease,
Guid? guid,
RequiredModuleReference[] requiredModules,
string? manifestText)
Expand All @@ -46,6 +49,7 @@ public ModuleInformation(
ModuleVersion = moduleVersion;
RootModule = rootModule;
PowerShellVersion = powerShellVersion;
PreRelease = preRelease;
Guid = guid;
RequiredModules = requiredModules ?? Array.Empty<RequiredModuleReference>();
ManifestText = manifestText;
Expand Down
11 changes: 11 additions & 0 deletions PowerForge/Services/ModuleInformationReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public ModuleInformation Read(string projectPath)
string? moduleVersion = null;
string? rootModule = null;
string? powerShellVersion = null;
string? preRelease = null;
Guid? guid = null;
RequiredModuleReference[] requiredModules = Array.Empty<RequiredModuleReference>();
string? manifestText = null;
Expand All @@ -52,6 +53,15 @@ public ModuleInformation Read(string projectPath)
rootModule = rm;
if (ManifestEditor.TryGetTopLevelString(manifestPath, "PowerShellVersion", out var psv))
powerShellVersion = psv;
if (ManifestEditor.TryGetPsDataStringArray(manifestPath, "Prerelease", out var prereleaseValues) &&
prereleaseValues is { Length: > 0 })
{
preRelease = prereleaseValues[0];
}
else if (ManifestEditor.TryGetTopLevelString(manifestPath, "Prerelease", out var topLevelPrerelease))
{
preRelease = topLevelPrerelease;
}
if (ManifestEditor.TryGetTopLevelString(manifestPath, "GUID", out var guidString))
{
if (System.Guid.TryParse(guidString, out var g))
Expand Down Expand Up @@ -82,6 +92,7 @@ public ModuleInformation Read(string projectPath)
moduleVersion: moduleVersion,
rootModule: rootModule,
powerShellVersion: powerShellVersion,
preRelease: preRelease,
guid: guid,
requiredModules: requiredModules,
manifestText: manifestText);
Expand Down
Loading