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

Update-ModuleManifest parameter surface should mirror New-ModuleManifest #1740

Open
IISResetMe opened this issue Oct 29, 2024 · 3 comments
Open

Comments

@IISResetMe
Copy link

Summary of the new feature / enhancement

The current implementation of Update-ModuleManifest does not accept empty arguments for a number of parameters, meaning it can't be used to clear array-like values from existing manifests:

Update-ModuleManifest .\Test\Test.psd1 -RequiredModules @()

Instead of updating the manifest with RequiredModules = @(), this actually throws a validation error because -RequiredModules doesn't accept empty arguments.

This issue was initially raised here.

Proposed technical implementation details (optional)

Update the cmdlet in src/code/UpdateModuleManifest.cs.

Parameters that should be decorated with [AllowEmptyCollection]:

  • NestedModules
  • TypesToProcess
  • FormatsToProcess
  • ScriptsToProcess
  • RequiredAssemblies
  • FileList
  • ModuleList
  • FunctionsToExport
  • AliasesToExport
  • VariablesToExport
  • CmdletsToExport
  • DscResourcesToExport
  • CompatiblePSEditions

There's a number of additional parameters for which [AllowNull]/[AllowEmptyString] might be appropriate too.

@iRon7
Copy link

iRon7 commented Oct 30, 2024

I think that the concerned parameters should allow for both $Null and an Empty Collection

  • In case the value is an (empty) collection, the value should convert to an (empty array) expression: @()
  • In case the value is $Null, the setting should reset to its original state:
    • For e.g. RequiredModules this means completely removing the concerned statement and replacing it with a comment:
      # RequiredModules = @()
    • For e.g. VariablesToExport assigning a wildcard (*), meaning replacing the statement with:
      VariablesToExport = '*'
function Update-ModuleManifest {
    param(
        [AllowNull()]
        [Object[]]$RequiredModules
    )
    
    if ($Null -eq $RequiredModules) {
        Write-Host 'Reset the setting to its original state'
    }
    else {
        Write-Host 'Convert the value to an expression'
        if (-not $RequiredModules) {
            Write-Host 'Even it is an empty collection'
        }
    }
}

PS C:\> Update-ModuleManifest -RequiredModules $Null
Reset the setting to its original state
PS C:\> Update-ModuleManifest -RequiredModules 1,2,3
Convert the value to an expression
PS C:\> Update-ModuleManifest -RequiredModules @()
Convert the value to an expression
Even it is an empty collection

@SydneyhSmith
Copy link
Collaborator

Thanks for this issue-- feel free to open a pr

@iRon7
Copy link

iRon7 commented Nov 1, 2024

Actually, it appears that there is a newer Update-PSModuleManifest (1.0.6) that does work as expected (except from the suggested $Null/Defaulting value):

Install-Module -Name Microsoft.PowerShell.PSResourceGet -RequiredVersion 1.0.6
Update-PSModuleManifest .\Test\Test.psd1 -RequiredModules @())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants