Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ScriptsToInclude to the Module Manifest. #24253

Open
iRon7 opened this issue Sep 6, 2024 · 3 comments
Open

Add ScriptsToInclude to the Module Manifest. #24253

iRon7 opened this issue Sep 6, 2024 · 3 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@iRon7
Copy link

iRon7 commented Sep 6, 2024

Summary of the new feature / enhancement

To extent on issue #18740 Best practice: import functions in a module with a more practical propose:
Adding a ScriptsToInclude to Module manifest elements would IMO allow for a safer (in terms of making module design misstakes) way to include scripts than dot-sourcing (invoking) multiple scripts from the <module>.psm1 file where only the embedded function (usually with the same name as the script file) is ment to be included.

Proposed technical implementation details (optional)

My expectation of a ScriptsToInclude module manifest element, is that it loads one or more scripts (possibly supporting wildcards) into the module as a function using the script name as the function name similar as installing a script from the PowerShell Gallery (Install-Script -Name <MyScript>).

Maintaining (as debugging) the script apart (or not) from the module would also be easier as one might simply be able to test it by using it's file name .\MyScript.ps1 (without dot-sourcing first) and even would be able compare the result with the already loaded module function (just named MyScript).

@iRon7 iRon7 added Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. labels Sep 6, 2024
@rhubarb-geek-nz
Copy link

Thanks for the link to the previous issue. I thought that had the best solution.

The ideal form of a script module is a single psm1 file and no dot-sourced scripts. Your approach is trying to shift the responsibility of what the module packager should be doing onto the import process.

Regarding the testing, Pester will let you test complete modules so all the tools are already there.

@iRon7
Copy link
Author

iRon7 commented Sep 10, 2024

@rhubarb-geek-nz ,

Thanks for the feedback, what I meant with testing, is just testing the script(function) and not testing the whole module (which eventually comes at the end of the module deployment).
Meaning that your "best solution" requires someone to completely rebuild the module and fully test that for every single development step in the concerned script(function). Meaning that Pester might throw dozens of errors after your rebuild, where a simple direct check from the terminal prompt, like $InputObject | .\MyScript -Some parameters could have immediately reveal a simple scripting misstake. Besides, by rebuilding and reloading the whole module, you will loose the reference of how the the orginal function reacted in the prior full module release..

@rhubarb-geek-nz
Copy link

Besides by rebuilding and reloading the whole module, you will loose the reference of how the the orginal function reacted in the prior full module release..

Not really. That is all part of Test-Driven-Development and software versioning.

You should always be able to refer to how a previous revision behaves by simply running the previous revision of the module.

Likewise your tests should be written first and define how you want the module to behave. You write the code to meet the tests.

Your tests should alert you when your module changes in expected behaviour.

For every bug, defect, change etc add more tests to your suite so you are defining exactly how your module behaves and prevent regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

2 participants