Skip to content

Commit cfc29c0

Browse files
authored
Fix #44 bug finding module manifest without build manifest
Merge pull request #90 from johlju/fix/removal-of-buildmanifest
2 parents 3fe63f8 + 84709a8 commit cfc29c0

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

Source/Private/GetBuildInfo.ps1

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,13 @@ function GetBuildInfo {
7777
}
7878
Write-Debug "Finished parsing Build Manifest $BuildManifest"
7979

80-
$BuildInfo = $BuildInfo | Update-Object $ParameterValues
81-
Write-Debug "Using Module Manifest $($BuildInfo.SourcePath)"
82-
8380
$BuildManifestParent = if ($BuildManifest) {
8481
Split-Path -Parent $BuildManifest
8582
} else {
8683
Get-Location -PSProvider FileSystem
8784
}
8885

89-
if (-Not $BuildInfo.SourcePath) {
86+
if ((-not $BuildInfo.SourcePath) -and $ParameterValues["SourcePath"] -notmatch '\.psd1') {
9087
# Find a module manifest (or maybe several)
9188
$ModuleInfo = Get-ChildItem $BuildManifestParent -Recurse -Filter *.psd1 -ErrorAction SilentlyContinue |
9289
ImportModuleManifest -ErrorAction SilentlyContinue
@@ -102,13 +99,16 @@ function GetBuildInfo {
10299
}
103100
if (@($ModuleInfo).Count -eq 1) {
104101
Write-Debug "Updating BuildInfo SourcePath to $($ModuleInfo.Path)"
105-
$BuildInfo = $BuildInfo | Update-Object @{ SourcePath = $ModuleInfo.Path }
102+
$ParameterValues["SourcePath"] = $ModuleInfo.Path
106103
}
107-
if (-Not $BuildInfo.SourcePath) {
104+
if (-Not $ModuleInfo) {
108105
throw "Can't find a module manifest in $BuildManifestParent"
109106
}
110107
}
111108

109+
$BuildInfo = $BuildInfo | Update-Object $ParameterValues
110+
Write-Debug "Using Module Manifest $($BuildInfo.SourcePath)"
111+
112112
# Make sure the SourcePath is absolute and points at an actual file
113113
if (!(Split-Path -IsAbsolute $BuildInfo.SourcePath) -and $BuildManifestParent) {
114114
$BuildInfo.SourcePath = Join-Path $BuildManifestParent $BuildInfo.SourcePath | Convert-Path

Tests/Integration/Source1.Tests.ps1

+46-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ Describe "Regression test for #84: Multiple Aliases per command will Export" -Ta
8888
}
8989

9090
Describe "Supports building without a build.psd1" -Tag Integration {
91-
Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse
91+
Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse
92+
# This is the old build, with a build.psd1
93+
$Output = Build-Module TestDrive:\Source1\build.psd1 -Passthru
94+
$ManifestContent = Get-Content $Output.Path
95+
$ModuleContent = Get-Content ([IO.Path]::ChangeExtension($Output.Path, ".psm1"))
96+
Remove-Item (Split-Path $Output.Path) -Recurse
97+
98+
# Then remove the build.psd1 and rebuild it
9299
Remove-Item TestDrive:\Source1\build.psd1
93100

94101
$Build = @{ }
@@ -105,6 +112,8 @@ Describe "Supports building without a build.psd1" -Tag Integration {
105112

106113
It "Creates the same module as with a build.psd1" {
107114
$Build.Metadata = Import-Metadata $Build.Output.Path
115+
Get-Content $Build.Output.Path | Should -Be $ManifestContent
116+
Get-Content ([IO.Path]::ChangeExtension($Build.Output.Path, ".psm1")) | Should -Be $ModuleContent
108117
}
109118

110119
It "Should update AliasesToExport in the manifest" {
@@ -115,6 +124,42 @@ Describe "Supports building without a build.psd1" -Tag Integration {
115124
$Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
116125
}
117126
}
127+
Describe "Supports building discovering the module without a build.psd1" -Tag Integration {
128+
Copy-Item $PSScriptRoot\Source1 TestDrive:\source -Recurse
129+
130+
# This is the old build, with a build.psd1
131+
$Output = Build-Module TestDrive:\source\build.psd1 -Passthru
132+
$ManifestContent = Get-Content $Output.Path
133+
$ModuleContent = Get-Content ([IO.Path]::ChangeExtension($Output.Path, ".psm1"))
134+
Remove-Item (Split-Path $Output.Path) -Recurse
135+
136+
# Then remove the build.psd1 and rebuild it
137+
Remove-Item TestDrive:\source\build.psd1
138+
139+
Push-Location -StackName 'IntegrationTest' -Path TestDrive:\
140+
141+
$Build = @{ }
142+
143+
It "No longer fails if there's no build.psd1" {
144+
$Build.Output = Build-Module -Passthru
145+
}
146+
147+
It "Creates the same module as with a build.psd1" {
148+
$Build.Metadata = Import-Metadata $Build.Output.Path
149+
Get-Content $Build.Output.Path | Should -Be $ManifestContent
150+
Get-Content ([IO.Path]::ChangeExtension($Build.Output.Path, ".psm1")) | Should -Be $ModuleContent
151+
}
152+
153+
It "Should update AliasesToExport in the manifest" {
154+
$Build.Metadata.AliasesToExport | Should -Be @("GS", "GSou", "SS", "SSou")
155+
}
156+
157+
It "Should update FunctionsToExport in the manifest" {
158+
$Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
159+
}
160+
161+
Pop-Location -StackName 'IntegrationTest'
162+
}
118163

119164
Describe "Regression test for #88 not copying prefix files" -Tag Integration, Regression {
120165
$Output = Build-Module $PSScriptRoot\build.psd1 -Passthru

0 commit comments

Comments
 (0)