Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
temp/
run.ps1
dist/
dist/
justfile
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [1.1.0] - 2025-08-28

## Added

- Now Module manifest includes `AliasesToExport`. This helps loading aliases without explicitly importing modules to session.
- thanks to @djs-zmtc for suggesting the feature

## [1.0.0] - 2025-03-11

### Added
Expand Down
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ProjectName": "ModuleTools",
"Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.",
"Version": "1.0.0",
"Version": "1.1.0",
"copyResourcesToModuleRoot": false,
"Manifest": {
"Author": "Manjunath Beli",
Expand Down
7 changes: 5 additions & 2 deletions src/private/Build.Manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ function Build-Manifest {

$PubFunctionFiles = Get-ChildItem -Path $data.PublicDir -Filter *.ps1
$functionToExport = @()
$PubFunctionFiles | ForEach-Object {
$functionToExport += Get-FunctionNameFromFile -filePath $_.FullName
$aliasToExport = @()
$PubFunctionFiles.FullName | ForEach-Object {
$functionToExport += Get-FunctionNameFromFile -filePath $_
$aliasToExport += Get-AliasInFunctionFromFile -filePath $_
}

$ManfiestAllowedParams = (Get-Command New-ModuleManifest).Parameters.Keys
Expand All @@ -16,6 +18,7 @@ function Build-Manifest {
Path = $data.ManifestFilePSD1
Description = $data.Description
FunctionsToExport = $functionToExport
AliasesToExport = $aliasToExport
RootModule = "$($data.ProjectName).psm1"
ModuleVersion = $data.Version
}
Expand Down
26 changes: 26 additions & 0 deletions src/private/GetAliasNameFromFunction.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<#
.SYNOPSIS
Retrieves information about alias in a given function/file so it can be added to module manifest

.DESCRIPTION
Adding alias to module manifest and exporting it will ensure that functions can be called using alias without importing explicitly
#>
function Get-AliasInFunctionFromFile {
param($filePath)
try {
$ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)

$functionNodes = $ast.FindAll({
param($node)
$node -is [System.Management.Automation.Language.FunctionDefinitionAst]
}, $true)

$function = $functionNodes[0]
$paramsAttributes = $function.Body.ParamBlock.Attributes

$aliases = ($paramsAttributes | Where-Object { $_.TypeName -like 'Alias' } | ForEach-Object PositionalArguments).Value
$aliases
} catch {
return
}
}
Loading