PowerShell / PSResourceGet

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

Update-ModuleManifest makes unintended changes #1308

Closed anamnavi closed 1 year ago

anamnavi commented 1 year ago

Prerequisites

Steps to reproduce

I downloaded the bicep package nupkg from PSGallery, and extracted and obtained the .psd1

Update-ModuleManifest -Path ./bicep.psd1 -Version "3.0.0"

Expected behavior

It should just update the ModuleVersion field in the .psd1.

Actual behavior

It updates the following which is unintended:
- CompanyName (was previously commented out and now it's uncommented out)
- Tags (the "@()" array syntax around them is removed, so this will fail parsing later on)
- Prerelease (was previously commented out and now it's uncommented out)

Also -Prerelease "  " can be passed as valid input, but should not be able to. We should follow sem version guidelines for what a prerelease string can contain ideally.

Error details

No response

Environment data

0.5.23-beta23

Visuals

No response

adityapatwardhan commented 1 year ago

I verified that the issue repros with Microsoft.PowerShell.PSResourceGet - Update-PSModuleManifest

anamnavi commented 1 year ago

For the second issue, the changes to tags entry in the module manifest is by design of New-ModuleManifest. Update-PSModuleManifest calls New-ModuleManifest (for which the param type is string[] for the following params: Tags, CompatiblePSEditions, CmdletsToExport, FunctionsToExport, VariablesToExport, AliasesToExport, and a handful of other parameters, per docs).

If a user generates the module manifest with New-ModuleManifest these parameters will be have their values listed as a string array without the @() syntax around the array (unless it was an empty entry and then the value is just @()). Since New-ModuleManifest is owned by the PowerShell project to change is it out of scope/design for PSResourceGet. At any rate it should not stop the user from being able to publish with that module manifest.

anamnavi commented 1 year ago

For the first issue, per the docs for New-ModuleManifest, if you omit or comment out the entry for CompanyName, when Update-PSModuleManifest calls into New-ModuleManifest it will create a CompanyName entry with a value of "Unknown".

anamnavi commented 1 year ago

For the third issue, I've added checks to ensure Prerelease value cannot be empty string or whitespace. I couldn't reproduce the issue of it uncommenting out a prerelease value. If a user has a module manifest with Prerelease entry like: # Prerelease = 'preview1' it will change it to # Prerelease = ''