Update-ModuleManifest parameter surface should mirror New-ModuleManifest
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.
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.
RequiredModulesthis means completely removing the concerned statement and replacing it with a comment:# RequiredModules = @() - For e.g.
VariablesToExportassigning a wildcard (*), meaning replacing the statement with:VariablesToExport = '*'
- For e.g.
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
Thanks for this issue-- feel free to open a pr
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 @())