Skip to content

Commit 5613497

Browse files
authored
Fix exporting multiple aliases for a single command
Merge pull request #85 from PoshCode/feature/AliasExportFix
2 parents 92b7253 + a72d40e commit 5613497

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

Source/Public/Build-Module.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function Build-Module {
219219
$ParseResult | MoveUsingStatements -Encoding "$($ModuleInfo.Encoding)"
220220

221221
if ($PublicFunctions -and -not $ModuleInfo.IgnoreAliasAttribute) {
222-
if (($AliasesToExport = ($ParseResult | GetCommandAlias)[$PublicFunctions] | Select-Object -Unique)) {
222+
if (($AliasesToExport = ($ParseResult | GetCommandAlias)[$PublicFunctions] | ForEach-Object { $_ } | Select-Object -Unique)) {
223223
Update-Metadata -Path $OutputManifest -PropertyName AliasesToExport -Value $AliasesToExport
224224
}
225225
}

Tests/Integration/Source1.Tests.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Describe "Build-Module With Source1" {
1212
$Metadata = Import-Metadata $Output.Path
1313

1414
It "Should update FunctionsToExport in the manifest" {
15-
$Metadata.FunctionsToExport | Should -Be @("Get-Source")
15+
$Metadata.FunctionsToExport | Should -Be @("Get-Source", "Set-Source")
1616
}
1717

1818
It "Should update AliasesToExport in the manifest" {
19-
$Metadata.AliasesToExport | Should -Be @("GS")
19+
$Metadata.AliasesToExport -match "GS" | Should -Not -BeNullOrEmpty
2020
}
2121

2222
It "Should de-dupe and move using statements to the top of the file" {
@@ -77,4 +77,16 @@ Describe "Build-Module With Source1" {
7777
(Select-String -Pattern "^#\s*using" -Path $Module).Count | Should -Be 2
7878
}
7979
}
80+
81+
Context "Regression test for #84: Multiple Aliases per command will Export" {
82+
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -Passthru
83+
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
84+
85+
$Metadata = Import-Metadata $Output.Path
86+
87+
It "Should update AliasesToExport in the manifest" {
88+
$Metadata.AliasesToExport | Should -Be @("GS","GSou", "SS", "SSou")
89+
}
90+
91+
}
8092
}

Tests/Integration/Source1/Public/Get-Source.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ using module ModuleBuilder
22

33
function Get-Source {
44
[CmdletBinding()]
5-
[Alias("gs")]
5+
[Alias("gs","gsou")]
66
param()
77
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function Set-Source {
2+
[CmdletBinding()]
3+
[Alias("ss", "ssou")]
4+
param()
5+
}

0 commit comments

Comments
 (0)