Skip to content

PS: Extract source files found via PSModulePath#132

Merged
MathiasVP merged 4 commits intomainfrom
powershell-extract-implicit-models
Nov 6, 2024
Merged

PS: Extract source files found via PSModulePath#132
MathiasVP merged 4 commits intomainfrom
powershell-extract-implicit-models

Conversation

@MathiasVP
Copy link
Collaborator

PowerShell has a peculiar feature of "implicit module imports".

From https://learn.microsoft.com/en-us/powershell/scripting/developer/module/importing-a-powershell-module?view=powershell-7.4#implicitly-importing-a-module-powershell-30:

[...] modules are imported automatically when any cmdlet or function in the module is used in a command. This feature works on any module in a directory that is included in the value of the PSModulePath environment variable.

So when we see an invocation such as:

Foo 42

this may refer to a command defined in a file totally outside the source directory, and will be implicitly loaded into the current Powershell session.

To handle such scenarios this PR does several things:

  • It adds extraction of the files inside the directories pointed to by the PSModulePath environment variable. This can be disabled via a command-line argument to the extractor, but is enabled by default.
  • It adds .psd1 to the list of file extensions to extract, which are module manifest files. These module manifest files contain the information necessary to detect this "implicit loading"
  • Finally, we add a new extensional to check whether a source file was found via the PSModulePath environment variable.

@MathiasVP MathiasVP merged commit 43f986c into main Nov 6, 2024
@MathiasVP MathiasVP mentioned this pull request Nov 6, 2024
MathiasVP added a commit that referenced this pull request Nov 6, 2024
MathiasVP added a commit that referenced this pull request Feb 21, 2025
…licit-models"

This reverts commit 43f986c, reversing
changes made to e6f8df7.
MathiasVP added a commit that referenced this pull request Feb 24, 2025
…licit-models"

This reverts commit 43f986c, reversing
changes made to e6f8df7.

PS: Add back upgrade and downgrade scripts.
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.

1 participant