Skip to content

Commit 8d23773

Browse files
committed
Fix #125 by calling Convert-Path for SourceDirectory
1 parent 8f591fd commit 8d23773

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

Source/ModuleBuilder.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Release Notes have to be here, so we can update them
1313
ReleaseNotes = '
14-
Now with Set/New-Alias support, and sorting of the source files.
14+
Fix case sensitivity of defaults for SourceDirectories and PublicFilter
1515
'
1616

1717
# Tags applied to this module. These help with module discovery in online galleries.

Source/Public/Build-Module.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ function Build-Module {
9696
# Folders which contain source .ps1 scripts to be concatenated into the module
9797
# Defaults to Enum, Classes, Private, Public
9898
[string[]]$SourceDirectories = @(
99-
"Enum", "Classes", "Private", "Public"
99+
"[Ee]num", "[Cc]lasses", "[Pp]rivate", "[Pp]ublic"
100100
),
101101

102102
# A Filter (relative to the module folder) for public functions
103103
# If non-empty, FunctionsToExport will be set with the file BaseNames of matching files
104104
# Defaults to Public\*.ps1
105105
[AllowEmptyString()]
106-
[string[]]$PublicFilter = "Public\*.ps1",
106+
[string[]]$PublicFilter = "[Pp]ublic/*.ps1",
107107

108108
# A switch that allows you to disable the update of the AliasesToExport
109109
# By default, (if PublicFilter is not empty, and this is not set)
@@ -206,8 +206,11 @@ function Build-Module {
206206

207207
# SilentlyContinue because there don't *HAVE* to be functions at all
208208
$AllScripts = @($ModuleInfo.SourceDirectories).ForEach{
209-
Get-ChildItem -Path (Join-Path -Path $ModuleInfo.ModuleBase -ChildPath $_) -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue |
210-
Sort-Object -Property 'FullName'
209+
# By explicitly converting, we support wildcards in the SourceDirectories parameter
210+
if ($SourceDirectory = Join-Path -Path $ModuleInfo.ModuleBase -ChildPath $_ | Convert-Path -ErrorAction SilentlyContinue) {
211+
Get-ChildItem -Path $SourceDirectory -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue |
212+
Sort-Object -Property 'FullName'
213+
}
211214
}
212215

213216
# We have to force the Encoding to string because PowerShell Core made up encodings

Tests/Integration/Source1.Tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,16 @@ Describe "Copies additional items specified in CopyPaths" {
326326
'TestDrive:/output/MyModule/1.0.0/lib/subdir/imaginary2.dll' | Should -FileContentMatch '2'
327327
}
328328
}
329+
330+
Describe "Regression test for #125: SourceDirectories supports wildcards" -Tag Integration, Regression {
331+
BeforeAll {
332+
# [Cc]lasses does not exist, but won't throw an error
333+
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -SourceDirectories "[Cc]lasses", "[Pp]rivate", "[Pp]ublic" -PublicFilter "[Pp]ublic/*.ps1" -Passthru -ErrorAction Stop
334+
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
335+
$Metadata = Import-Metadata $Output.Path
336+
}
337+
338+
It "Finds the public functions" {
339+
$Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
340+
}
341+
}

Tests/Public/Build-Module.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ Describe "Build-Module" {
137137
}
138138
}
139139

140-
141-
142140
Mock Push-Location {}
143141

142+
# So it doesn't have to exist
143+
Mock Convert-Path { $Path }
144144
Mock Get-ChildItem {
145145
[IO.FileInfo]"$TestDrive/Output/MyModule/Public/Get-MyInfo.ps1"
146146
}

Tests/Public/ConvertFrom-SourceLineNumber.Tests.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ Describe "ConvertFrom-SourceLineNumber" {
1212

1313
$global:TestCases = @(
1414
@{ outputLine = 36; sourceFile = ".${\}Private${\}TestUnExportedAliases.ps1"; sourceLine = 13; Module = $Convert_LineNumber_ModulePath }
15-
@{ outputLine = 43; sourceFile = ".${\}Public${\}Get-Source.ps1"; sourceLine = 5; Module = $Convert_LineNumber_ModulePath }
16-
@{ outputLine = 50; sourceFile = ".${\}Public${\}Set-Source.ps1"; sourceLine = 3; Module = $Convert_LineNumber_ModulePath }
15+
@{ outputLine = 43; sourceFile = ".${\}public${\}Get-Source.ps1"; sourceLine = 5; Module = $Convert_LineNumber_ModulePath }
16+
@{ outputLine = 50; sourceFile = ".${\}public${\}Set-Source.ps1"; sourceLine = 3; Module = $Convert_LineNumber_ModulePath }
1717
)
1818
}
1919
AfterAll {
2020
Pop-Location -StackName ConvertFrom-SourceLineNumber
2121
}
2222

23-
2423
It "Should map line <outputLine> in the Module to line <sourceLine> in the source of <sourceFile>" -TestCases $TestCases {
2524
param($outputLine, $sourceFile, $sourceLine, $module)
2625

0 commit comments

Comments
 (0)