Skip to content
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
15 changes: 14 additions & 1 deletion src/code/PublishPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ private Hashtable ParseRequiredModules(Hashtable parsedMetadataHash)
{
return null;
}

var requiredModules = parsedMetadataHash["requiredmodules"];

// Required modules can be:
Expand All @@ -752,6 +751,20 @@ private Hashtable ParseRequiredModules(Hashtable parsedMetadataHash)
}
}

var externalModuleDeps = parsedMetadataHash.ContainsKey("ExternalModuleDependencies") ?
parsedMetadataHash["ExternalModuleDependencies"] : null;

if (externalModuleDeps != null && LanguagePrimitives.TryConvertTo<string[]>(externalModuleDeps, out string[] externalModuleNames))
{
foreach (var extModName in externalModuleNames)
{
if (dependenciesHash.ContainsKey(extModName))
{
dependenciesHash.Remove(extModName);
}
}
}

return dependenciesHash;
}

Expand Down
12 changes: 12 additions & 0 deletions test/PublishPSResourceTests/PublishPSResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,18 @@ Describe "Test Publish-PSResource" -tags 'CI' {
(Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath
}

It "should publish a script with sExternalModuleDependencies that are not published" {
$scriptName = "test"
$scriptVersion = "1.0.0"
$scriptPath = Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1"
New-PSScriptFileInfo -Description 'test' -Version $scriptVersion -RequiredModules @{ModuleName='testModule'} -ExternalModuleDependencies 'testModule' -Path $scriptPath -Force

Publish-PSResource -Path $scriptPath

$expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg"
(Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath
}

It "should write error and not publish script when Author property is missing" {
$scriptName = "InvalidScriptMissingAuthor.ps1"
$scriptVersion = "1.0.0"
Expand Down