Skip to content

Conversation

@djs-zmtc
Copy link

Added functionality to handle parsing the public/*.ps1 files for [Alias("aliasname")] in the function or Set-Alias commands outside the functions. Modified Build-Module to use this alias list to add the Export-ModuleMember command to the end of the PSM1. Modified Build-Manifest to add the AliasesToExport to the Manifest file.

I have tested this with a local Module I'm working on, and it seems to be working as expected. Not sure if you'll be able to incorporate this into your repo, but thought I'd do the PR so you can decide if you want to use it.

@belibug
Copy link
Owner

belibug commented Jun 23, 2025

This uses regex and pattern matching to find aliases, I have carefully avoided use regex to avoid unexpected outcomes. I will check if there are any native way to extract aliases.

Any suggestions welcome.

@djs-zmtc
Copy link
Author

djs-zmtc commented Jul 4, 2025

Sorry, I don't have any suggestions for alternatives to regex (at the moment). I've been using various forms of regex for over 30 years, so I don't give it much thought when I grab it from the toolbox. 😁

However, I can see your point. Regex can also come with a lot of unintended side-effects, often capturing (or missing) text you didn't intend. And because I tailored this for my specific requirements, I haven't thoroughly vetted the various alternate ways someone might place Alias code in their Powershell scripts/modules (I wrote it based on how I think Aliases should be placed, not necessarily every way they can be added).

As noted in the original PR, if my code doesn't fit how you want to implement things, that's perfectly okay. Just thought I'd offer it in case it filled a need.

If I come up with a native (non-regex) way to handle this, I'll send a new PR (if you haven't already implemented your own implementation by then).

@belibug
Copy link
Owner

belibug commented Aug 28, 2025

please check #14 where I added the AliasesToExport using native AST instead of regex. I want to credit you for bringing this up and suggesting the feature. Since actual code is already merged (and will be released soon), feel free to update the docs or add help in function so that I can merge your commit and credit you as contributor. Feel free to update help section of src/private/GetAliasNameFromFunction.ps1.

Thank you @djs-zmtc

@djs-zmtc
Copy link
Author

djs-zmtc commented Sep 3, 2025

No crediting is necessary. All I did was suggest the feature and one possible solution, you found the better solution. I appreciate the offer of credit for the suggestion, but my ego is fine with staying anonymous. 😁

@belibug belibug closed this Sep 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants