Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Fix Update-ModuleManifest clears FunctionsToExport, AliasesToExport, NestedModules #373 #415

Merged
merged 3 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions Tests/PSGetUpdateModuleManifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {
# Action:
# Update-ModuleManifest -Path [Path]
#
# Expected Result: The updated manifest should have the same proerty values.
# Expected Result: The updated manifest should have the same property values.
#
It UpdateModuleManifestWithNoAdditionalParameters2 {

Expand All @@ -144,6 +144,29 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {

AssertEquals $updatedModuleInfo.CompanyName $editedModuleInfo.CompanyName "Company name should be $expectedCompanyName"
AssertEquals $($text.length) $expectedLength "Number of wildcards should be $expectedLength"
}

# Purpose: Validate Update-ModuleManifest will not reset original parameter values to default values
#
# Action:
# Update-ModuleManifest -Path [Path]
#
# Expected Result: The updated manifest should have the same property values.
#
It UpdateModuleManifestWithNoAdditionalParameters3 {

New-ModuleManifest -Path $script:testManifestPath -ModuleVersion '1.0' -FunctionsToExport 'function1' -NestedModules 'Microsoft.PowerShell.Management' -AliasesToExport 'alias1'
Update-ModuleManifest -Path $script:testManifestPath

Import-LocalizedData -BindingVariable ModuleManifestHashTable `
-FileName (Microsoft.PowerShell.Management\Split-Path $script:testManifestPath -Leaf) `
-BaseDirectory (Microsoft.PowerShell.Management\Split-Path $script:testManifestPath -Parent) `
-ErrorAction SilentlyContinue `
-WarningAction SilentlyContinue

AssertEquals $ModuleManifestHashTable.FunctionsToExport 'function1' "FunctionsToExport should be 'function1'"
AssertEquals $ModuleManifestHashTable.NestedModules 'Microsoft.PowerShell.Management' "NestedModules should be 'module1'"
AssertEquals $ModuleManifestHashTable.AliasesToExport 'alias1' "AliasesToExport should be 'alias1'"
}

# Purpose: Validate Update-ModuleManifest will keep the original property values for DefaultCommandPrefix,
Expand Down Expand Up @@ -214,7 +237,6 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {
AssertEquals $updatedModuleInfo.AliasesToExport.Count 0 "AliasesToExport count should be 0"
}


# Purpose: Update a module manifest with same parameters
#
# Action: Update-ModuleManifest -Path [path] -NestedModules -Guid -Author -CompanyName -Copyright -RootModule -ModuleVersion...
Expand Down Expand Up @@ -652,7 +674,6 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {

}


# Purpose: Validate Update-ModuleManifest will throw errors when there are paths defined in FilePath that are not in the module base
#
# Action:
Expand Down
18 changes: 11 additions & 7 deletions src/PowerShellGet/public/psgetfunctions/Update-ModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,9 @@ function Update-ModuleManifest
{
$params.Add("NestedModules",$NestedModules)
}
elseif($moduleInfo.NestedModules)
elseif($ModuleManifestHashTable -and $ModuleManifestHashTable.ContainsKey("NestedModules"))
{
#Get the original module info from ManifestHashTab
if($ModuleManifestHashTable -and $ModuleManifestHashTable.ContainsKey("NestedModules"))
{
$params.Add("NestedModules",$ModuleManifestHashtable.NestedModules)
}
$params.Add("NestedModules",$ModuleManifestHashtable.NestedModules)
}

#Guid is read-only property
Expand Down Expand Up @@ -519,6 +515,10 @@ function Update-ModuleManifest
$params.Add("FunctionsToExport",($moduleInfo.ExportedFunctions.Keys -split ' '))
}
}
elseif ($ModuleManifestHashTable -and $ModuleManifestHashTable.ContainsKey("FunctionsToExport"))
{
$params.Add("FunctionsToExport", $ModuleManifestHashTable['FunctionsToExport'])
}

if($AliasesToExport -or $AliasesToExport -is [array])
{
Expand All @@ -545,6 +545,10 @@ function Update-ModuleManifest
$params.Add("AliasesToExport",($moduleInfo.ExportedAliases.Keys -split ' '))
}
}
elseif ($ModuleManifestHashTable -and $ModuleManifestHashTable.ContainsKey("AliasesToExport"))
{
$params.Add("AliasesToExport", $ModuleManifestHashTable['AliasesToExport'])
}

if($VariablesToExport)
{
Expand Down Expand Up @@ -585,7 +589,7 @@ function Update-ModuleManifest
ForEach-Object { $parts = $_ -split '-', 2; $parts[-1] = $parts[-1] -replace "^$($moduleInfo.Prefix)"; $parts -join '-' }
$params.Add("CmdletsToExport", $originalCmdlets)
}
else
else
{
$params.Add("CmdletsToExport",($moduleInfo.ExportedCmdlets.Keys -split ' '))
}
Expand Down