diff --git a/.gitignore b/.gitignore index 12c5b97..89d397c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ temp/ run.ps1 -dist/ \ No newline at end of file +dist/ +justfile \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index faceef8..c63bf02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/project.json b/project.json index 156440e..c86c16d 100644 --- a/project.json +++ b/project.json @@ -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", diff --git a/src/private/Build.Manifest.ps1 b/src/private/Build.Manifest.ps1 index 7fb8906..0fa0cdc 100644 --- a/src/private/Build.Manifest.ps1 +++ b/src/private/Build.Manifest.ps1 @@ -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 @@ -16,6 +18,7 @@ function Build-Manifest { Path = $data.ManifestFilePSD1 Description = $data.Description FunctionsToExport = $functionToExport + AliasesToExport = $aliasToExport RootModule = "$($data.ProjectName).psm1" ModuleVersion = $data.Version } diff --git a/src/private/GetAliasNameFromFunction.ps1 b/src/private/GetAliasNameFromFunction.ps1 new file mode 100644 index 0000000..9f29416 --- /dev/null +++ b/src/private/GetAliasNameFromFunction.ps1 @@ -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 + } +} \ No newline at end of file