Skip to content

Commit d449f68

Browse files
🚀 [Feature]: Get info about loaded aliases after build (#53)
## Description - Update module manifest with aliases, based on loaded aliases after build. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 5d13716 commit d449f68

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

scripts/helpers/Build-PSModule.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,11 @@ function Build-PSModule {
4545
Build-PSModuleBase -ModuleName $ModuleName -ModuleSourceFolder $moduleSourceFolder -ModuleOutputFolder $moduleOutputFolder
4646
Build-PSModuleManifest -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder
4747
Build-PSModuleRootModule -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder
48+
Update-PSModuleManifestAliasesToExport -ModuleName $ModuleName -ModuleOutputFolder $moduleOutputFolder
4849
Build-PSModuleDocumentation -ModuleName $ModuleName -DocsOutputFolder $docsOutputFolder
50+
51+
$outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1"
52+
Start-LogGroup 'Build manifest file - Final Result'
53+
Show-FileContent -Path $outputManifestPath
54+
Stop-LogGroup
4955
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function Update-PSModuleManifestAliasesToExport {
2+
<#
3+
.SYNOPSIS
4+
Updates the aliases to export in the module manifest.
5+
#>
6+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
7+
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
8+
Justification = 'Updates a file that is being built.'
9+
)]
10+
[CmdletBinding()]
11+
param(
12+
# Name of the module.
13+
[Parameter(Mandatory)]
14+
[string] $ModuleName,
15+
16+
# Folder where the module is outputted.
17+
[Parameter(Mandatory)]
18+
[System.IO.DirectoryInfo] $ModuleOutputFolder
19+
)
20+
21+
$aliases = Get-Command -Module $ModuleName -CommandType Alias
22+
$outputManifestPath = Join-Path -Path $ModuleOutputFolder -ChildPath "$ModuleName.psd1"
23+
Set-ModuleManifest -Path $outputManifestPath -AliasesToExport $aliases.Name -Verbose:$false
24+
}

tests/src/public/New-PSModuleTest.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function New-PSModuleTest {
1919
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
2020
Justification = 'Reason for suppressing'
2121
)]
22+
[Alias('New-PSModuleTestAlias1')]
23+
[Alias('New-PSModuleTestAlias2')]
2224
[CmdletBinding()]
2325
param (
2426
# Name of the person to greet.
@@ -27,3 +29,9 @@ function New-PSModuleTest {
2729
)
2830
Write-Output "Hello, $Name!"
2931
}
32+
33+
New-Alias New-PSModuleTestAlias3 New-PSModuleTest
34+
New-Alias -Name New-PSModuleTestAlias4 -Value New-PSModuleTest
35+
36+
37+
Set-Alias New-PSModuleTestAlias5 New-PSModuleTest

0 commit comments

Comments
 (0)