Skip to content

Export alias create with Set-Alias and New-Alias #103

@johlju

Description

@johlju

ModuleBuilder is automatically exporting aliased in the module manifest if they are decorated with the attribute [Alias()].
The function that finds the alias to export is GetCommandAlias.

I suggest we extend the function GetCommandAlias to search for Set-Alias as well.

Set-Alias -Name 'Task.Generate_Conceptual_Help' -Value "$PSScriptRoot/tasks/Generate_Conceptual_Help.build.ps1"

This will help when using the pattern with separate file for each alias in the Public folder, like Task.Generate_Conceptual_Help.ps1. We should make sure to only parse script files in the folder Public to avoid the Set-Alias is also used for private functions which should not be exported.

The function GetCommandAlias here should be updated:

function GetCommandAlias {
[CmdletBinding()]
param(
# Path to the PSM1 file to amend
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
[System.Management.Automation.Language.Ast]$AST
)
begin {
$Result = [Ordered]@{}
}
process {
foreach($function in $AST.FindAll(
{ $Args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] },
$false )
) {
$Result[$function.Name] = $function.Body.ParamBlock.Attributes.Where{
$_.TypeName.Name -eq "Alias" }.PositionalArguments.Value
}
}
end {
$Result
}
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions