PowerShellGetv2 icon indicating copy to clipboard operation
PowerShellGetv2 copied to clipboard

Update-ModuleManifest converts empty array @() to asterisk '*'

Open eedwards-sk opened this issue 6 years ago • 3 comments

Steps to reproduce

  1. create a module manifest with default values for CmdletsToExport, and AliasesToExport

snippet from foo.psd1:

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()
  1. update an unrelated field
Update-ModuleManifest -Path ./foo.psd1 -Prerelease 'foo'

Expected behavior

snippet from updated foo.psd1 remains the same:

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

Actual behavior

snippet from updated foo.psd1 has modified values for CmdletsToExport and AliasesToExport:

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = '*'

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.2
PSEdition                      Core
GitCommitId                    6.2.2
OS                             Darwin 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

eedwards-sk avatar Aug 22 '19 16:08 eedwards-sk

@eedwards-sk Please move the issue to PowerShellGet repo.

iSazonov avatar Oct 13 '19 17:10 iSazonov

/cc @SteveL-MSFT for information.

iSazonov avatar Oct 13 '19 17:10 iSazonov

Workaround is to use Update-ModuleManifest -Path $ModuleManiFestPath -AliasesToExport @($null) -FunctionsToExport @($null) -CmdletsToExport @($null).

However -VariablesToExport @($null) wont work since VariablesToExport parameter have the attribute [ValidateNotNullOrEmpty()] which Aliases, Functions and Cmdlets does not have.

My suggestion is to remove the attribute [ValidateNotNullOrEmpty()] from the VariablesToExport parameter and add "-or $VariablesToExport -is [array]" to the if($VariablesToExport) to better align with how Aliases, Functions and Cmdlets to export works.

Thumbs up if you want a Pull Request with this.

PhilipHaglund avatar Nov 19 '19 09:11 PhilipHaglund