PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
493 stars 94 forks source link

Should have cmdlet to verify cmdlets in a given script #924

Open SteveL-MSFT opened 1 year ago

SteveL-MSFT commented 1 year ago

Summary of the new feature / enhancement

Maybe call it Resolve-Dependency which takes a path to a ps1 (or psm1), uses PowerShell to parse to AST extracting all the commands and seeing if they are actually available on the current system.

If it's a cmdlet and not on the system, discover which module via PowerShellGet to install for that cmdlet or if a native command, just give a warning message that it wasn't found on the system. For security, make it clear if the module is from an untrusted repository.

Proposed technical implementation details (optional)

No response

aguzev commented 1 year ago

Not every cmdlet mentioned in a script has a chance to be called on the current system. Simple scanning might give false positives when the ps1 contains multiple system-dependent implementations. Those cases remind conditional compilation in C* languages.


# … some code …

if ($IsWindows -and $aConditionEvaluatedInTheCodeAbove) {
   # … use Windows specific dependencies …
} elseif ($IsLinux) {
   # … use Linux specific dependencies …
}
ThomasNieto commented 1 year ago

Does this functionally actually need to exist? I say that because it seem this functionality is already covered when author creates the script/module and defines the dependencies in the PSScriptFileInfo comment block or RequiredModules key in the module manifest.

anamnavi commented 1 year ago

Solving for conditionals might not be in scope for this suggested script, but we'd like to get more feedback from the community.

aguzev commented 1 year ago

Sure, the scope should be under control. At the same time there is a good reason for Resolve-Dependency to keep a good distance from forcing users to install unnecessary dependencies.