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

Commit 4da5da6

Browse files
committed
Fix Update-ModuleManifest clears FunctionsToExport, AliasesToExport and NestedModules
1 parent fc69488 commit 4da5da6

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

Tests/PSGetUpdateModuleManifest.Tests.ps1

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {
118118
# Action:
119119
# Update-ModuleManifest -Path [Path]
120120
#
121-
# Expected Result: The updated manifest should have the same proerty values.
121+
# Expected Result: The updated manifest should have the same property values.
122122
#
123123
It UpdateModuleManifestWithNoAdditionalParameters2 {
124124

@@ -144,6 +144,30 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {
144144

145145
AssertEquals $updatedModuleInfo.CompanyName $editedModuleInfo.CompanyName "Company name should be $expectedCompanyName"
146146
AssertEquals $($text.length) $expectedLength "Number of wildcards should be $expectedLength"
147+
}
148+
149+
# Purpose: Validate Update-ModuleManifest will not reset original parameter values to default values
150+
#
151+
# Action:
152+
# Update-ModuleManifest -Path [Path]
153+
#
154+
# Expected Result: The updated manifest should have the same property values.
155+
#
156+
It UpdateModuleManifestWithNoAdditionalParameters3 {
157+
158+
New-ModuleManifest -Path $script:testManifestPath -ModuleVersion '1.0' -FunctionsToExport 'function1' -NestedModules 'module1' -AliasesToExport 'alias1'
159+
$expectedLength = 4
160+
Update-ModuleManifest -Path $script:testManifestPath
161+
162+
Import-LocalizedData -BindingVariable ModuleManifestHashTable `
163+
-FileName (Microsoft.PowerShell.Management\Split-Path $script:testManifestPath -Leaf) `
164+
-BaseDirectory (Microsoft.PowerShell.Management\Split-Path $script:testManifestPath -Parent) `
165+
-ErrorAction SilentlyContinue `
166+
-WarningAction SilentlyContinue
167+
168+
AssertEquals $ModuleManifestHashTable.FunctionsToExport 'function1' "FunctionsToExport should be 'function1'"
169+
AssertEquals $ModuleManifestHashTable.NestedModules 'module1' "NestedModules should be 'module1'"
170+
AssertEquals $ModuleManifestHashTable.AliasesToExport 'alias1' "AliasesToExport should be 'alias1'"
147171
}
148172

149173
# Purpose: Validate Update-ModuleManifest will keep the original property values for DefaultCommandPrefix,
@@ -197,8 +221,6 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {
197221
}
198222
}
199223

200-
201-
202224
# Purpose: Update a module manifest with same parameters
203225
#
204226
# Action: Update-ModuleManifest -Path [path] -NestedModules -Guid -Author -CompanyName -Copyright -RootModule -ModuleVersion...
@@ -636,7 +658,6 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {
636658

637659
}
638660

639-
640661
# Purpose: Validate Update-ModuleManifest will throw errors when there are paths defined in FilePath that are not in the module base
641662
#
642663
# Action:

src/PowerShellGet/public/psgetfunctions/Update-ModuleManifest.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,9 @@ function Update-ModuleManifest
273273
{
274274
$params.Add("NestedModules",$NestedModules)
275275
}
276-
elseif($moduleInfo.NestedModules)
276+
elseif($ModuleManifestHashTable -and $ModuleManifestHashTable.ContainsKey("NestedModules"))
277277
{
278-
#Get the original module info from ManifestHashTab
279-
if($ModuleManifestHashTable -and $ModuleManifestHashTable.ContainsKey("NestedModules"))
280-
{
281-
$params.Add("NestedModules",$ModuleManifestHashtable.NestedModules)
282-
}
278+
$params.Add("NestedModules",$ModuleManifestHashtable.NestedModules)
283279
}
284280

285281
#Guid is read-only property
@@ -522,6 +518,10 @@ function Update-ModuleManifest
522518
$params.Add("FunctionsToExport",($moduleInfo.ExportedFunctions.Keys -split ' '))
523519
}
524520
}
521+
elseif ($ModuleManifestHashTable -and $ModuleManifestHashTable.ContainsKey("FunctionsToExport"))
522+
{
523+
$params.Add("FunctionsToExport", $ModuleManifestHashTable['FunctionsToExport'])
524+
}
525525

526526
if($AliasesToExport)
527527
{
@@ -548,6 +548,10 @@ function Update-ModuleManifest
548548
$params.Add("AliasesToExport",($moduleInfo.ExportedAliases.Keys -split ' '))
549549
}
550550
}
551+
elseif ($ModuleManifestHashTable -and $ModuleManifestHashTable.ContainsKey("AliasesToExport"))
552+
{
553+
$params.Add("AliasesToExport", $ModuleManifestHashTable['AliasesToExport'])
554+
}
551555

552556
if($VariablesToExport)
553557
{
@@ -588,7 +592,7 @@ function Update-ModuleManifest
588592
ForEach-Object { $parts = $_ -split '-', 2; $parts[-1] = $parts[-1] -replace "^$($moduleInfo.Prefix)"; $parts -join '-' }
589593
$params.Add("CmdletsToExport", $originalCmdlets)
590594
}
591-
else
595+
else
592596
{
593597
$params.Add("CmdletsToExport",($moduleInfo.ExportedCmdlets.Keys -split ' '))
594598
}

0 commit comments

Comments
 (0)