Skip to content

Commit 540b090

Browse files
authored
Compress-PSResource -PassThru now passes FileInfo instead of string (#1720)
1 parent fe9c4d6 commit 540b090

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/code/CompressPSResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
55
using System.IO;
6-
using System.Linq;
76
using System.Management.Automation;
87

98
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
@@ -15,6 +14,7 @@ namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
1514
"PSResource",
1615
SupportsShouldProcess = true)]
1716
[Alias("cmres")]
17+
[OutputType(typeof(FileInfo))]
1818
public sealed class CompressPSResource : PSCmdlet
1919
{
2020
#region Parameters

src/code/PublishHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil
566566
{
567567
if (PassThru)
568568
{
569-
_cmdletPassedIn.WriteObject(System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg"));
569+
var nupkgPath = System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg");
570+
_cmdletPassedIn.WriteObject(new FileInfo(nupkgPath));
570571
}
571572
_cmdletPassedIn.WriteVerbose("Successfully packed the resource into a .nupkg");
572573
}

test/PublishPSResourceTests/CompressPSResource.Tests.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,17 @@ Describe "Test Compress-PSResource" -tags 'CI' {
154154
Test-Path -Path (Join-Path -Path $unzippedPath -ChildPath $testFile) | Should -Be $True
155155
}
156156

157-
It "Compress-PSResource -PassThru returns the path to the nupkg" {
157+
It "Compress-PSResource -PassThru returns a FileInfo object with the correct path" {
158158
$version = "1.0.0"
159159
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"
160160

161-
$nupkgPath = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru
161+
$fileInfoObject = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru
162162

163163
$expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg"
164-
$nupkgPath | Should -Be $expectedPath
164+
$fileInfoObject | Should -BeOfType 'System.IO.FileSystemInfo'
165+
$fileInfoObject.FullName | Should -Be $expectedPath
166+
$fileInfoObject.Extension | Should -Be '.nupkg'
167+
$fileInfoObject.Name | Should -Be "$script:PublishModuleName.$version.nupkg"
165168
}
166169

167170
<# Test for Signing the nupkg. Signing doesn't work

0 commit comments

Comments
 (0)