Skip to content

Commit c2fb49e

Browse files
committed
Test with VersionedOutputDirectory by default
1 parent 20610d8 commit c2fb49e

File tree

8 files changed

+98
-33
lines changed

8 files changed

+98
-33
lines changed

Source/Private/InitializeBuild.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ function InitializeBuild {
3333
) -join ' ')"
3434
$BuildInfo = GetBuildInfo -BuildManifest $BuildManifest -BuildCommandInvocation $BuildCommandInvocation
3535

36+
# Override VersionedOutputDirectory with UnversionedOutputDirectory
37+
if ($BuildInfo.UnversionedOutputDirectory -and $BuildInfo.VersionedOutputDirectory) {
38+
$BuildInfo.VersionedOutputDirectory = $false
39+
}
40+
3641
# Finally, add all the information in the module manifest to the return object
3742
if ($ModuleInfo = ImportModuleManifest $BuildInfo.SourcePath) {
3843
# Update the module manifest with our build configuration and output it

Source/Private/ResolveOutputFolder.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function ResolveOutputFolder {
5151
$OutputDirectory = Join-Path $OutputDirectory $ModuleName
5252
}
5353
# Ensure the OutputDirectory is not a parent of the SourceDirectory
54-
if (-not (GetRelativePath $OutputDirectory $Source).StartsWith("..")) {
54+
$RelativeOutputPath = GetRelativePath $OutputDirectory $Source
55+
if (-not $RelativeOutputPath.StartsWith("..") -and $RelativeOutputPath -ne $Source) {
5556
Write-Verbose "Added Version to OutputDirectory path: $OutputDirectory"
5657
$OutputDirectory = Join-Path $OutputDirectory $Version
5758
}

Source/Public/Build-Module.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function Build-Module {
3838
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseApprovedVerbs", "", Justification="Build is approved now")]
3939
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCmdletCorrectly", "")]
4040
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="Parameter handling is in InitializeBuild")]
41+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidDefaultValueSwitchParameter", "", Justification = "VersionedOutputDirectory is Deprecated")]
4142
[CmdletBinding(DefaultParameterSetName="SemanticVersion")]
4243
[Alias("build")]
4344
param(
@@ -54,16 +55,16 @@ function Build-Module {
5455
[string]$SourcePath = $(Get-Location -PSProvider FileSystem),
5556

5657
# Where to build the module. Defaults to "..\Output" adjacent to the "SourcePath" folder.
57-
# The actual OutputDirectory may be a subfolder of this, because the path always ends with \ModuleName or \ModuleName\Version
58-
# -OutputDirectory ..\Output, the actual path is ..\Output\ModuleName or ..\Output\ModuleName\1.2.3
59-
# -OutputDirectory ..\, the actual path is ..\Output\ModuleName or ..\Output\ModuleName\1.2.3
60-
# -OutputDirectory ..\b\10.2, the actual path is ..\b\10.2\ModuleName\1.2.3
61-
# -OutputDirectory ..\b\ModuleName\1.2.3, the actual path is ..\b\ModuleName\1.2.3
58+
# The ACTUAL output may be in a subfolder of this path ending with the module name and version
59+
# The default value is ..\Output which results in the build going to ..\Output\ModuleName\1.2.3
6260
[Alias("Destination")]
6361
[string]$OutputDirectory = "..\Output",
6462

65-
# If set (true) adds a folder named after the version number to the OutputDirectory
66-
[switch]$VersionedOutputDirectory,
63+
# DEPRECATED. Now defaults true, producing a OutputDirectory with a version number as the last folder
64+
[switch]$VersionedOutputDirectory = $true,
65+
66+
# Overrides the VersionedOutputDirectory, producing an OutputDirectory without a version number as the last folder
67+
[switch]$UnversionedOutputDirectory,
6768

6869
# Semantic version, like 1.0.3-beta01+sha.22c35ffff166f34addc49a3b80e622b543199cc5
6970
# If the SemVer has metadata (after a +), then the full Semver will be added to the ReleaseNotes
@@ -131,9 +132,8 @@ function Build-Module {
131132
# - Clean deletes the build output folder
132133
# - Build builds the module output
133134
# - CleanBuild first deletes the build output folder and then builds the module back into it
134-
# Note that if you specify -VersionedOutputDirectory, the folder to be deleted is the version folder
135-
# For -OutputDirectory ..\Output -SemVer 1.2.3 -Versioned the path to clean is ..\Output\ModuleName\1.2.3
136-
# For -OutputDirectory ..\, the path to clean is ..\Output\ModuleName (the ..\Output path wouldn't be removed)
135+
# Note that the folder to be deleted is the actual calculated output folder, with the version number
136+
# So for the default OutputDirectory with version 1.2.3, the path to clean is: ..\Output\ModuleName\1.2.3
137137
[ValidateSet("Clean", "Build", "CleanBuild")]
138138
[string]$Target = "CleanBuild",
139139

Tests/Integration/Source1.Tests.ps1

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,59 @@ Describe "Supports building without a build.psd1" -Tag Integration {
125125
$Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
126126
}
127127
}
128+
129+
130+
Describe "Defaults to VersionedOutputDirectory" -Tag Integration {
131+
Copy-Item $PSScriptRoot\Source1 TestDrive:\Source1 -Recurse
132+
# This is the old build, with a build.psd1
133+
$Output = Build-Module TestDrive:\Source1\build.psd1 -Passthru
134+
$ManifestContent = Get-Content $Output.Path
135+
$ModuleContent = Get-Content ([IO.Path]::ChangeExtension($Output.Path, ".psm1"))
136+
Remove-Item (Split-Path $Output.Path) -Recurse
137+
138+
# Then remove the build.psd1 and rebuild it
139+
Remove-Item TestDrive:\Source1\build.psd1
140+
141+
$Build = @{ }
142+
143+
It "Builds into a folder with version by default" {
144+
$BuildParameters = @{
145+
SourcePath = "TestDrive:\Source1\Source1.psd1"
146+
OutputDirectory = "TestDrive:\Output1"
147+
}
148+
149+
$Build.Output = Build-Module @BuildParameters -Passthru
150+
(Convert-FolderSeparator $Build.Output.Path) | Should -Be (Convert-FolderSeparator "TestDrive:\Output1\Source1\1.0.0\Source1.psd1")
151+
}
152+
153+
It "Builds into a folder with no version when UnversionedOutputDirectory" {
154+
$BuildParameters = @{
155+
SourcePath = "TestDrive:\Source1\Source1.psd1"
156+
OutputDirectory = "TestDrive:\Output2"
157+
UnversionedOutputDirectory = $true
158+
}
159+
160+
$Build.Output = Build-Module @BuildParameters -Passthru
161+
(Convert-FolderSeparator $Build.Output.Path) | Should -Be (Convert-FolderSeparator "TestDrive:\Output2\Source1\Source1.psd1")
162+
}
163+
164+
It "Creates the same module as with a build.psd1" {
165+
$Build.Metadata = Import-Metadata $Build.Output.Path
166+
Get-Content $Build.Output.Path | Should -Be $ManifestContent
167+
Get-Content ([IO.Path]::ChangeExtension($Build.Output.Path, ".psm1")) | Should -Be $ModuleContent
168+
}
169+
170+
It "Should update AliasesToExport in the manifest" {
171+
$Build.Metadata.AliasesToExport | Should -Be @("GS", "GSou", "SS", "SSou")
172+
}
173+
174+
It "Should update FunctionsToExport in the manifest" {
175+
$Build.Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
176+
}
177+
}
178+
179+
180+
128181
Describe "Supports building discovering the module without a build.psd1" -Tag Integration {
129182
Copy-Item $PSScriptRoot\Source1 TestDrive:\source -Recurse
130183

@@ -212,8 +265,8 @@ if ($PSVersionTable.Platform -eq "Win32NT") {
212265
$Result = Build-Module -SourcePath 'TestDrive:/MyModule.psd1' -Version "1.0.0" -OutputDirectory './output' -Encoding UTF8 -SourceDirectories @('Public') -Target Build -Passthru
213266

214267
It "Builds the Module in the designated output folder" {
215-
$Result.ModuleBase | Convert-FolderSeparator | Should -Be (Convert-FolderSeparator "TestDrive:/Output/MyModule")
216-
'TestDrive:/Output/MyModule/MyModule.psm1' | Convert-FolderSeparator | Should -FileContentMatch 'MATCHING TEST CONTENT'
268+
$Result.ModuleBase | Convert-FolderSeparator | Should -Be (Convert-FolderSeparator "TestDrive:/Output/MyModule/1.0.0")
269+
'TestDrive:/Output/MyModule/1.0.0/MyModule.psm1' | Convert-FolderSeparator | Should -FileContentMatch 'MATCHING TEST CONTENT'
217270
}
218271
}
219272
}
@@ -235,13 +288,13 @@ Describe "Copies additional items specified in CopyPaths" {
235288
$Result = Build-Module -SourcePath 'TestDrive:/build.psd1' -OutputDirectory './output' -Version '1.0.0' -Passthru -Target Build
236289

237290
It "Copies single files that are in CopyPaths" {
238-
(Convert-FolderSeparator $Result.ModuleBase) | Should -Be (Convert-FolderSeparator "$TestDrive/output/MyModule")
239-
'TestDrive:/output/MyModule/MyModule.format.ps1xml' | Should -Exist
240-
'TestDrive:/output/MyModule/MyModule.format.ps1xml' | Should -FileContentMatch '<Configuration />'
291+
(Convert-FolderSeparator $Result.ModuleBase) | Should -Be (Convert-FolderSeparator "$TestDrive/output/MyModule/1.0.0")
292+
'TestDrive:/output/MyModule/1.0.0/MyModule.format.ps1xml' | Should -Exist
293+
'TestDrive:/output/MyModule/1.0.0/MyModule.format.ps1xml' | Should -FileContentMatch '<Configuration />'
241294
}
242295

243296
It "Recursively copies all the files in folders that are in CopyPaths" {
244-
'TestDrive:/output/MyModule/lib/imaginary1.dll' | Should -FileContentMatch '1'
245-
'TestDrive:/output/MyModule/lib/subdir/imaginary2.dll' | Should -FileContentMatch '2'
297+
'TestDrive:/output/MyModule/1.0.0/lib/imaginary1.dll' | Should -FileContentMatch '1'
298+
'TestDrive:/output/MyModule/1.0.0/lib/subdir/imaginary2.dll' | Should -FileContentMatch '2'
246299
}
247300
}

Tests/Integration/Source1/build.psd1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@{
22
Path = "Source1.psd1"
33
OutputDirectory = "..\Result1"
4-
VersionedOutputDirectory = $true
5-
}
4+
}

Tests/Integration/build.psd1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@{
22
Path = "Source1\Source1.psd1"
33
OutputDirectory = "..\Result1"
4-
VersionedOutputDirectory = $true
54

65
# This file is not in Source1 it's here next to this build
76
Prefix = "..\using.ps1"

Tests/Private/InitializeBuild.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Describe "InitializeBuild" {
2626
$SourcePath = ".\Source",
2727
$SourceDirectories = @("Enum", "Classes", "Private", "Public"),
2828
$OutputDirectory = ".\Output",
29+
$VersionedOutputDirectory = $true,
30+
$UnversionedOutputDirectory = $true,
2931
$Suffix
3032
)
3133
try {
@@ -62,5 +64,9 @@ Describe "InitializeBuild" {
6264
It "Returns overriden values from parameters" {
6365
$Result.SourcePath | Should -Be (Convert-Path 'TestDrive:\Source\MyModule.psd1')
6466
}
67+
68+
It "Sets VersionedOutputDirectory FALSE when UnversionedOutputDirectory is TRUE" {
69+
$Result.VersionedOutputDirectory | Should -Be $false
70+
}
6571
}
6672
}

Tests/Private/ResolveOutputFolder.Tests.ps1

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ Describe "ResolveOutputFolder" {
55
filter ToTestDrive { "$_".Replace($TestDrive, "TestDrive:") }
66

77
$TestCases = [Hashtable[]]@(
8-
@{ Source = "Source"
9-
Output = "Output"
10-
Result = "Output/ModuleName"
11-
Forced = "Output/ModuleName/1.2.3"
12-
}
13-
@{ Output = "ModuleName/Output"
14-
Source = "ModuleName/Source"
15-
Result = "ModuleName/Output/ModuleName"
16-
Forced = "ModuleName/Output/ModuleName/1.2.3"
17-
}
188
@{ # Be like Jaykul
199
Source = "ModuleName/Source"
2010
Output = "ModuleName"
@@ -27,6 +17,18 @@ Describe "ResolveOutputFolder" {
2717
Result = "1/b/ModuleName"
2818
Forced = "1/b/ModuleName/1.2.3"
2919
}
20+
@{ # The default option would be Module/Source build to Module/Output
21+
Source = "ModuleName/Source"
22+
Output = "ModuleName/Output"
23+
Result = "ModuleName/Output/ModuleName"
24+
Forced = "ModuleName/Output/ModuleName/1.2.3"
25+
}
26+
@{ # Which is the same even without the common named parent
27+
Source = "Source"
28+
Output = "Output"
29+
Result = "Output/ModuleName"
30+
Forced = "Output/ModuleName/1.2.3"
31+
}
3032
@{ # An edge case, build straight to a modules folder
3133
Source = "ModuleName/Source"
3234
Output = "Modules"
@@ -57,8 +59,8 @@ Describe "ResolveOutputFolder" {
5759
param($Source, $Output, $Result)
5860

5961
$Parameters = @{
60-
Source = Convert-FolderSeparator "TestDrive:/$Source"
61-
Output = Convert-FolderSeparator "TestDrive:/$Output"
62+
Source = Convert-FolderSeparator "$TestDrive/$Source"
63+
Output = Convert-FolderSeparator "$TestDrive/$Output"
6264
}
6365

6466
$Actual = &$CommandInTest @Parameters -Name ModuleName -Target Build -Version 1.2.3 | ToTestDrive

0 commit comments

Comments
 (0)