Skip to content

A PowerShell workspace dependency module manifest #14077

Closed

Description

Summary of the new feature/enhancement

PowerShell comes with native support for build modules using the New-ModuleManifest cmdlet, but doesn't necessarily come with the ability to describe a runtime's dependencies outside of a module. Just like Node runtime project's can use a package.json to describe the dependencies it has on npm libraries or .NET can use .csproj files to reference NuGet package (e.g. The runtime takes a dep. on a library which might also take dep. on more libraries creating a dep. graph), Nothing stops a runtime from wanting to take a dep. on a PowerShell module.

Use cases:

Simple use case - I want to share a .ps1 file with a colleague that deps. on 5 other modules without have to go through the process to build my own module and export functions, etc. Today my colleague would need to have those 5 modules installed and imported on their device for my ps1 file to run correctly. Sure you could just add the Install-Module cmdlet directly in the ps1, but it feels better to separate the concerns of my application code and my dependencies and have a more declarative approach to an infrastructural problem.

A complex use case - A Node project that that uses node-pty to spawn pwsh processes that run arbitrary PowerShell. A dockerfile is used to run Install-Module across a plethora of modules needed. Then after forking the pwsh process, it needs to import those same modules to perform it's duties. There does not seem to be a good way (that I have found at least) to document this kind of manifest and have it used to generate a valid runtime environment. Currently, if my process requires 25 modules to run, I need to explicitly install and import each one.

Proposed technical implementation details (optional)

To model it after the already tried and tested solutions that .NET and npm have used, I think introducing a modules.json file that describes the modules and their required versions via semantic versioning (Similar to how npm does here) is an acceptable approach. Once that file is created and your dependencies are described in the manifest, you could run Install-Module with no arguments and it would simply look for a modules.json file in your folder (and possibly the ancestors) and use that file to both Install and potentially Import modules in bulk.

With this change, you would no longer have to rely on a PowerShell profile to perform "automatic" loading of modules as it would be at a project (folder) level and not confined to the scope of a "user" on a device. This makes powershell projects and libraries more portable when the consuming technology is not a PS module itself as in the case of my Node use case above or even just a vanilla .ps1 file you wanted to shared with a co-worker via git.

One caveat to this all would be that where npm and NuGet package management involves adding the packages into the workspace where they can be gitignored and discarded between builds with a git clean, Install-Module currently only installs in a global location to the device which means you mutate the device's state and have no good way of "cleaning up" afterwards like you would with a bin or node_modules folder.

Activity

  1. added
    Issue-Enhancement
    on Nov 13, 2020
  2. changed the title [-]A PowerShell workspace module dependency manifest[/-] [+]A PowerShell workspace dependency module manifest[/+] on Nov 13, 2020
  3. iSazonov commented on Nov 13, 2020

    @iSazonov
    Collaborator

    Matthew Hintzke (@mhintzke) The topic is more for PowerShellGet. Currently MSFT team works actively on V3. You could read about the version in their blog and feedback in https://github.com/PowerShell/PowerShellGet and in PowerShell/PowerShell-RFC#237

    GitHub
    PowerShellGet is the package manager for PowerShell - PowerShell/PowerShellGet
  4. added
    Area-PowerShellGet
    Resolution-External
    on Nov 13, 2020
  5. ghost closed this as completedon Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-PowerShellGetIssue-EnhancementResolution-External

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions