diff --git a/src/code/CompressPSResource.cs b/src/code/CompressPSResource.cs index ba79425df..95b95a4e3 100644 --- a/src/code/CompressPSResource.cs +++ b/src/code/CompressPSResource.cs @@ -36,7 +36,13 @@ public sealed class CompressPSResource : PSCmdlet public string DestinationPath { get; set; } /// - /// Bypasses validating a resource module manifest before publishing. + /// When specified, passes the full path of the nupkg through the pipeline. + /// + [Parameter(Mandatory = false, HelpMessage = "Pass the full path of the nupkg through the pipeline")] + public SwitchParameter PassThru { get; set; } + + /// + /// Bypasses validating a resource module manifest before compressing. /// [Parameter] public SwitchParameter SkipModuleManifestValidate { get; set; } @@ -61,6 +67,7 @@ protected override void BeginProcessing() this, Path, DestinationPath, + PassThru, SkipModuleManifestValidate); _publishHelper.CheckAllParameterPaths(); diff --git a/src/code/PublishHelper.cs b/src/code/PublishHelper.cs index 8fc2575ad..861bbfab3 100644 --- a/src/code/PublishHelper.cs +++ b/src/code/PublishHelper.cs @@ -61,18 +61,20 @@ internal enum CallerCmdlet private string outputDir = string.Empty; internal bool ScriptError = false; internal bool ShouldProcess = true; + internal bool PassThru = false; #endregion #region Constructors - internal PublishHelper(PSCmdlet cmdlet, string path, string destinationPath, bool skipModuleManifestValidate) + internal PublishHelper(PSCmdlet cmdlet, string path, string destinationPath, bool passThru, bool skipModuleManifestValidate) { _callerCmdlet = CallerCmdlet.CompressPSResource; _cmdOperation = "Compress"; _cmdletPassedIn = cmdlet; Path = path; DestinationPath = destinationPath; + PassThru = passThru; SkipModuleManifestValidate = skipModuleManifestValidate; outputDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString()); outputNupkgDir = destinationPath; @@ -562,6 +564,10 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil if (success) { + if (PassThru) + { + _cmdletPassedIn.WriteObject(System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg")); + } _cmdletPassedIn.WriteVerbose("Successfully packed the resource into a .nupkg"); } else diff --git a/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 b/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 index cdccee7f6..778c225bb 100644 --- a/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 +++ b/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 @@ -153,6 +153,17 @@ Describe "Test Compress-PSResource" -tags 'CI' { Test-Path -Path (Join-Path -Path $unzippedPath -ChildPath $testFile) | Should -Be $True } + + It "Compress-PSResource -PassThru returns the path to the nupkg" { + $version = "1.0.0" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" + + $nupkgPath = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg" + $nupkgPath | Should -Be $expectedPath + } + <# Test for Signing the nupkg. Signing doesn't work It "Compressed Module is able to be signed with a certificate" { $version = "1.0.0"