[PSS 2015] Primal Sense for modules

Post feature requests, product enhancement ideas, and other product-specific suggestions here. Do not post bug reports.
Forum rules
Do not post any licensing information in this forum.
User avatar
Posts: 257
Joined: Sun Mar 03, 2013 12:45 pm

[PSS 2015] Primal Sense for modules

Post by Bosparan » Wed Dec 16, 2015 9:10 am

Hi Guys,

when adding an Import-Module statement in a script to another script, PSS will provide primal sense for content contained within. When I do so for a Module, it ... doesn't work out as well.
Or at least, not always.
Imagine a big Module with dozens of scriptfiles in sub-folders (cause writing them all in the same file makes it pretty much unmanageable). Our own best practice is one dedicated file per function, one per other complex resource (eg.: c# Source code compiled at runtime) and one per simple type of resource (eg.: Aliases, Configuration items, ...).

Now, for this to load this properly, we need to Import them within the .psm1-file (the same file we point the original Import-Module at). This is often done like this:

Code: Select all

Get-ChildItem "$PSScriptRoot\Functions" | Select-Object -ExpandProperty FullName | ForEach-Object {
. $_
Which has the nice advantage of automatically importing all content you care to add later.
So far so good, PSS is incapable of interpreting this and thus will not provide primal sense for any function contained therein.
It won't recognize direct imports like this either:

Code: Select all

. "$PSScriptRoot\Functions\Get-Test.ps1"
I'd like for PSS to be able to provide Primal Sense for script modules more efficiently, so those too will benefit from the powerful help Primal Sense provides.

Ideas on how to realize this:

1) Parse and interprete
Going the hard way, interpreting the PSScriptRoot variable (and the various other ways to determine the current modulepath), then scanning it and loading all nested imports (including the parsing of get-childitem calls) to obtain a full list of imports.

- Heavy effort to implement the feature
- Error-Prone

+ Intuitive for the scripter
+ Usable on all Script-Modules, past and present

2) Information comments
Agree on a syntax how developers can communicate to PSS which files to load and interprete for Primal Sense purposes.
For example by placing a comment in the .psm1 file:

Code: Select all

#import "Functions\*.ps1"
- Not intuitive for scripters
- Not automatically included in already existing modules

+ Simple to implement the feature
+ Reliable for the scripter (Behavior is absolutely predictable)
+ Great control what primal sense is provided for

3) Exported Commands
A third solution is to scan all files in the module folder (+ Subfolders), but only provide Primal Sense for functions that are listed as exported commands (when using Get-Module -ListAvailable, interpreting the modulepath as in one of the $env:PSModulePath paths).

- Will only work on modules that properly mark their functions as exported (= Will not work on quite a few modules)

+ Furthers good coding practices
+ Simple to implement the feature
+ Automatically includes changes

All said, I'd prefer option three ... anything that reinforces good habits.


User avatar
Posts: 4741
Joined: Thu Aug 18, 2011 4:56 am

Re: [PSS 2015] Primal Sense for modules

Post by davidc » Fri Dec 18, 2015 2:15 pm

Once again, thank you for your feedback. I will pass these points along to the team.

SAPIEN Technologies, Inc.


Who is online

Users browsing this forum: No registered users and 3 guests