@@ -504,6 +504,29 @@ function Start-PSPackage {
504504 }
505505 }
506506 }
507+ ' osxpkg' {
508+ $HostArchitecture = " x86_64"
509+ if ($MacOSRuntime -match " -arm64" ) {
510+ $HostArchitecture = " arm64"
511+ }
512+ Write-Verbose " HostArchitecture = $HostArchitecture " - Verbose
513+
514+ $Arguments = @ {
515+ Type = ' osxpkg'
516+ PackageSourcePath = $Source
517+ Name = $Name
518+ Version = $Version
519+ Force = $Force
520+ NoSudo = $NoSudo
521+ LTS = $LTS
522+ HostArchitecture = $HostArchitecture
523+ }
524+
525+
526+ if ($PSCmdlet.ShouldProcess (" Create macOS Package" )) {
527+ New-UnixPackage @Arguments
528+ }
529+ }
507530 default {
508531 $Arguments = @ {
509532 Type = $_
@@ -803,6 +826,19 @@ function New-UnixPackage {
803826 $Dict = New-Object " System.Management.Automation.RuntimeDefinedParameterDictionary"
804827 $Dict.Add (" Distribution" , $Parameter ) > $null
805828 return $Dict
829+ } elseif ($Type -eq " osxpkg" ) {
830+ # Add a dynamic parameter '-HostArchitecture' when the specified package type is 'osxpkg'.
831+ # The '-HostArchitecture' parameter is used to indicate which Mac processor this package is targeting,
832+ # Intel (x86_64) or Apple Silicon (arm64).
833+ $ParameterAttr = New-Object " System.Management.Automation.ParameterAttribute"
834+ $ValidateSetAttr = New-Object " System.Management.Automation.ValidateSetAttribute" - ArgumentList " x86_64" , " arm64"
835+ $Attributes = New-Object " System.Collections.ObjectModel.Collection`` 1[System.Attribute]"
836+ $Attributes.Add ($ParameterAttr ) > $null
837+ $Attributes.Add ($ValidateSetAttr ) > $null
838+ $Parameter = New-Object " System.Management.Automation.RuntimeDefinedParameter" - ArgumentList (" HostArchitecture" , [string ], $Attributes )
839+ $Dict = New-Object " System.Management.Automation.RuntimeDefinedParameterDictionary"
840+ $Dict.Add (" HostArchitecture" , $Parameter ) > $null
841+ return $Dict
806842 }
807843 }
808844
@@ -856,6 +892,7 @@ function New-UnixPackage {
856892 throw ($ErrorMessage -f " macOS" )
857893 }
858894
895+ $HostArchitecture = $PSBoundParameters [' HostArchitecture' ]
859896 $DebDistro = ' macOS'
860897 }
861898 }
@@ -1013,7 +1050,7 @@ function New-UnixPackage {
10131050 if ($Environment.IsMacOS ) {
10141051 if ($PSCmdlet.ShouldProcess (" Add distribution information and Fix PackageName" ))
10151052 {
1016- $createdPackage = New-MacOsDistributionPackage - FpmPackage $createdPackage - IsPreview:$IsPreview
1053+ $createdPackage = New-MacOsDistributionPackage - FpmPackage $createdPackage - HostArchitecture $HostArchitecture - IsPreview:$IsPreview
10171054 }
10181055 }
10191056
@@ -1063,6 +1100,11 @@ function New-MacOsDistributionPackage
10631100 param (
10641101 [Parameter (Mandatory , HelpMessage = ' The FileInfo of the file created by FPM' )]
10651102 [System.IO.FileInfo ]$FpmPackage ,
1103+
1104+ [Parameter (HelpMessage = ' x86_64 for Intel or arm64 for Apple Silicon' )]
1105+ [ValidateSet (" x86_64" , " arm64" )]
1106+ [string ] $HostArchitecture = " x86_64" ,
1107+
10661108 [Switch ] $IsPreview
10671109 )
10681110
@@ -1112,7 +1154,8 @@ function New-MacOsDistributionPackage
11121154 # 2 - package path
11131155 # 3 - minimum os version
11141156 # 4 - Package Identifier
1115- $PackagingStrings.OsxDistributionTemplate -f " PowerShell - $packageVersion " , $packageVersion , $packageName , ' 10.14' , $packageId | Out-File - Encoding ascii - FilePath $distributionXmlPath - Force
1157+ # 5 - host architecture (x86_64 for Intel or arm64 for Apple Silicon)
1158+ $PackagingStrings.OsxDistributionTemplate -f " PowerShell - $packageVersion " , $packageVersion , $packageName , ' 10.14' , $packageId , $HostArchitecture | Out-File - Encoding ascii - FilePath $distributionXmlPath - Force
11161159
11171160 Write-Log " Applying distribution.xml to package..."
11181161 Push-Location $tempDir
0 commit comments