@@ -28,6 +28,39 @@ Function Edit-ComposerConfig() {
2828 Set-ComposerAuth
2929}
3030
31+ # Function to merge auth.json fragments.
32+ Function Get-MergedAuthJson {
33+ [CmdletBinding ()]
34+ param (
35+ [Parameter (Mandatory )][string []] $ComposerAuth
36+ )
37+ if (Test-Path $composer_home \auth.json) {
38+ try {
39+ $existing = Get-Content $composer_home \auth.json - Raw | ConvertFrom-Json
40+ } catch {
41+ $existing = [PSCustomObject ]@ {}
42+ }
43+ } else {
44+ $existing = [PSCustomObject ]@ {}
45+ }
46+ foreach ($fragment in $ComposerAuth ) {
47+ $piece = (' {' + $fragment + ' }' ) | ConvertFrom-Json
48+ foreach ($prop in $piece.PSObject.Properties ) {
49+ if ($prop.Name -eq ' http-basic' ) {
50+ if (-not $existing .' http-basic' ) {
51+ $existing | Add-Member - MemberType NoteProperty - Name ' http-basic' - Value ([PSCustomObject ]@ {}) - Force
52+ }
53+ foreach ($domainProp in $prop.Value.PSObject.Properties ) {
54+ $existing .' http-basic' | Add-Member - MemberType NoteProperty - Name $domainProp.Name - Value $domainProp.Value - Force
55+ }
56+ } else {
57+ $existing | Add-Member - MemberType NoteProperty - Name $prop.Name - Value $prop.Value - Force
58+ }
59+ }
60+ }
61+ return $existing | ConvertTo-Json - Depth 5
62+ }
63+
3164# Function to setup authentication in composer.
3265Function Set-ComposerAuth () {
3366 if (Test-Path env:COMPOSER_AUTH_JSON) {
@@ -48,7 +81,7 @@ Function Set-ComposerAuth() {
4881 $composer_auth += ' "github-oauth": {"github.com": "' + $env: GITHUB_TOKEN + ' "}'
4982 }
5083 if ($composer_auth.length ) {
51- Add-Env COMPOSER_AUTH ( ' { ' + ( $composer_auth -join ' , ' ) + ' } ' )
84+ Set-Content - Path $composer_home \auth.json - Value ( Get-MergedAuthJson $composer_auth )
5285 }
5386}
5487
0 commit comments