diff --git a/Source/Private/GetBuildInfo.ps1 b/Source/Private/GetBuildInfo.ps1 index 458e6e3..bdebdff 100644 --- a/Source/Private/GetBuildInfo.ps1 +++ b/Source/Private/GetBuildInfo.ps1 @@ -77,16 +77,13 @@ function GetBuildInfo { } Write-Debug "Finished parsing Build Manifest $BuildManifest" - $BuildInfo = $BuildInfo | Update-Object $ParameterValues - Write-Debug "Using Module Manifest $($BuildInfo.SourcePath)" - $BuildManifestParent = if ($BuildManifest) { Split-Path -Parent $BuildManifest } else { Get-Location -PSProvider FileSystem } - if (-Not $BuildInfo.SourcePath) { + if ((-not $BuildInfo.SourcePath) -and $ParameterValues["SourcePath"] -notmatch '\.psd1') { # Find a module manifest (or maybe several) $ModuleInfo = Get-ChildItem $BuildManifestParent -Recurse -Filter *.psd1 -ErrorAction SilentlyContinue | ImportModuleManifest -ErrorAction SilentlyContinue @@ -102,13 +99,16 @@ function GetBuildInfo { } if (@($ModuleInfo).Count -eq 1) { Write-Debug "Updating BuildInfo SourcePath to $($ModuleInfo.Path)" - $BuildInfo = $BuildInfo | Update-Object @{ SourcePath = $ModuleInfo.Path } + $ParameterValues["SourcePath"] = $ModuleInfo.Path } - if (-Not $BuildInfo.SourcePath) { + if (-Not $ModuleInfo) { throw "Can't find a module manifest in $BuildManifestParent" } } + $BuildInfo = $BuildInfo | Update-Object $ParameterValues + Write-Debug "Using Module Manifest $($BuildInfo.SourcePath)" + # Make sure the SourcePath is absolute and points at an actual file if (!(Split-Path -IsAbsolute $BuildInfo.SourcePath) -and $BuildManifestParent) { $BuildInfo.SourcePath = Join-Path $BuildManifestParent $BuildInfo.SourcePath | Convert-Path diff --git a/Tests/Integration/Source1.Tests.ps1 b/Tests/Integration/Source1.Tests.ps1 index fab20ad..c32c291 100644 --- a/Tests/Integration/Source1.Tests.ps1 +++ b/Tests/Integration/Source1.Tests.ps1 @@ -88,7 +88,14 @@ Describe "Regression test for #84: Multiple Aliases per command will Export" -Ta } Describe "Supports building without a build.psd1" -Tag Integration { - Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse + Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse + # This is the old build, with a build.psd1 + $Output = Build-Module TestDrive:\Source1\build.psd1 -Passthru + $ManifestContent = Get-Content $Output.Path + $ModuleContent = Get-Content ([IO.Path]::ChangeExtension($Output.Path, ".psm1")) + Remove-Item (Split-Path $Output.Path) -Recurse + + # Then remove the build.psd1 and rebuild it Remove-Item TestDrive:\Source1\build.psd1 $Build = @{ } @@ -105,6 +112,8 @@ Describe "Supports building without a build.psd1" -Tag Integration { It "Creates the same module as with a build.psd1" { $Build.Metadata = Import-Metadata $Build.Output.Path + Get-Content $Build.Output.Path | Should -Be $ManifestContent + Get-Content ([IO.Path]::ChangeExtension($Build.Output.Path, ".psm1")) | Should -Be $ModuleContent } It "Should update AliasesToExport in the manifest" { @@ -115,6 +124,42 @@ Describe "Supports building without a build.psd1" -Tag Integration { $Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source") } } +Describe "Supports building discovering the module without a build.psd1" -Tag Integration { + Copy-Item $PSScriptRoot\Source1 TestDrive:\source -Recurse + + # This is the old build, with a build.psd1 + $Output = Build-Module TestDrive:\source\build.psd1 -Passthru + $ManifestContent = Get-Content $Output.Path + $ModuleContent = Get-Content ([IO.Path]::ChangeExtension($Output.Path, ".psm1")) + Remove-Item (Split-Path $Output.Path) -Recurse + + # Then remove the build.psd1 and rebuild it + Remove-Item TestDrive:\source\build.psd1 + + Push-Location -StackName 'IntegrationTest' -Path TestDrive:\ + + $Build = @{ } + + It "No longer fails if there's no build.psd1" { + $Build.Output = Build-Module -Passthru + } + + It "Creates the same module as with a build.psd1" { + $Build.Metadata = Import-Metadata $Build.Output.Path + Get-Content $Build.Output.Path | Should -Be $ManifestContent + Get-Content ([IO.Path]::ChangeExtension($Build.Output.Path, ".psm1")) | Should -Be $ModuleContent + } + + It "Should update AliasesToExport in the manifest" { + $Build.Metadata.AliasesToExport | Should -Be @("GS", "GSou", "SS", "SSou") + } + + It "Should update FunctionsToExport in the manifest" { + $Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source") + } + + Pop-Location -StackName 'IntegrationTest' +} Describe "Regression test for #88 not copying prefix files" -Tag Integration, Regression { $Output = Build-Module $PSScriptRoot\build.psd1 -Passthru