Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix exporting multiple aliases for a single command
  • Loading branch information
Jaykul committed Dec 18, 2019
commit a72d40ef155d761d926d72db923ba210ae389b02
2 changes: 1 addition & 1 deletion Source/Public/Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function Build-Module {
$ParseResult | MoveUsingStatements -Encoding "$($ModuleInfo.Encoding)"

if ($PublicFunctions -and -not $ModuleInfo.IgnoreAliasAttribute) {
if (($AliasesToExport = ($ParseResult | GetCommandAlias)[$PublicFunctions] | Select-Object -Unique)) {
if (($AliasesToExport = ($ParseResult | GetCommandAlias)[$PublicFunctions] | ForEach-Object { $_ } | Select-Object -Unique)) {
Update-Metadata -Path $OutputManifest -PropertyName AliasesToExport -Value $AliasesToExport
}
}
Expand Down
16 changes: 14 additions & 2 deletions Tests/Integration/Source1.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Describe "Build-Module With Source1" {
$Metadata = Import-Metadata $Output.Path

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

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

It "Should de-dupe and move using statements to the top of the file" {
Expand Down Expand Up @@ -77,4 +77,16 @@ Describe "Build-Module With Source1" {
(Select-String -Pattern "^#\s*using" -Path $Module).Count | Should -Be 2
}
}

Context "Regression test for #84: Multiple Aliases per command will Export" {
$Output = Build-Module $PSScriptRoot\Source1\build.psd1 -Passthru
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")

$Metadata = Import-Metadata $Output.Path

It "Should update AliasesToExport in the manifest" {
$Metadata.AliasesToExport | Should -Be @("GS","GSou", "SS", "SSou")
}

}
}
2 changes: 1 addition & 1 deletion Tests/Integration/Source1/Public/Get-Source.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ using module ModuleBuilder

function Get-Source {
[CmdletBinding()]
[Alias("gs")]
[Alias("gs","gsou")]
param()
}
5 changes: 5 additions & 0 deletions Tests/Integration/Source1/Public/Set-Source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Set-Source {
[CmdletBinding()]
[Alias("ss", "ssou")]
param()
}