Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions 4 Source/Private/SetModuleContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function SetModuleContent {

# The encoding defaults to UTF8 (or UTF8NoBom on Core)
[Parameter(DontShow)]
[string]$Encoding = $(if($IsCoreCLR) { "UTF8NoBom" } else { "UTF8" })
[string]$Encoding = $(if($IsCoreCLR) { "UTF8Bom" } else { "UTF8" })
)
begin {
Push-Location $WorkingDirectory -StackName SetModuleContent
Expand Down Expand Up @@ -64,4 +64,4 @@ function SetModuleContent {
$SetContent.End()
Pop-Location -StackName SetModuleContent
}
}
}
10 changes: 5 additions & 5 deletions 10 Source/Public/Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function Build-Module {

# File encoding for output RootModule (defaults to UTF8)
# Converted to System.Text.Encoding for PowerShell 6 (and something else for PowerShell 5)
[ValidateSet("UTF8","UTF7","ASCII","Unicode","UTF32")]
[string]$Encoding = "UTF8",
[ValidateSet("UTF8", "UTF8Bom", "UTF8NoBom", "UTF7", "ASCII", "Unicode", "UTF32")]
[string]$Encoding = $(if($IsCoreCLR) { "UTF8Bom" } else { "UTF8" }),

# The prefix is either the path to a file (relative to the module folder) or text to put at the top of the file.
# If the value of prefix resolves to a file, that file will be read in, otherwise, the value will be used.
Expand All @@ -133,8 +133,8 @@ function Build-Module {
)

begin {
if ($Encoding -ne "UTF8") {
Write-Warning "We strongly recommend you build your script modules with UTF8 encoding for maximum cross-platform compatibility."
if ($Encoding -notmatch "UTF8") {
Write-Warning "For maximum portability, we strongly recommend you build your script modules with UTF8 encoding (with a BOM, for backwards compatibility to PowerShell 5)."
}
}
process {
Expand Down 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 16 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 2 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()
}
6 changes: 6 additions & 0 deletions 6 Tests/Integration/Source1/Public/Set-Source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function Set-Source {
[CmdletBinding()]
[Alias("ss", "ssou")]
param()
"sto͞o′pĭd"
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.