@@ -6,18 +6,12 @@ Import-Module -Name (
6
6
ForEach-Object - Process { Join-Path - Path $PSScriptRoot - ChildPath " $_ .psm1" }
7
7
) - Prefix ' GitHubActions' - Scope ' Local'
8
8
[SemVer ]$NodeJsMinimumVersion = [SemVer ]::Parse(' 14.15.0' )
9
- [SemVer ]$NpmMinimumVersion = [SemVer ]::Parse(' 6.14.8' )
10
- [SemVer ]$PnpmMinimumVersion = [SemVer ]::Parse(' 7.28.0' )
11
9
[RegEx ]$SemVerRegEx = ' v?\d+\.\d+\.\d+'
12
10
[String ]$WrapperRoot = Join-Path - Path $PSScriptRoot - ChildPath ' nodejs-wrapper'
13
11
[String ]$WrapperPackageFilePath = Join-Path - Path $WrapperRoot - ChildPath ' package.json'
14
- [String ]$WrapperPackageLockFilePath = Join-Path - Path $WrapperRoot - ChildPath ' pnpm-lock.yaml'
15
- [String ]$WrapperBundledFilePath = Join-Path - Path $WrapperRoot - ChildPath ' bundled.js'
16
- [String ]$WrapperUnbundledFilePath = Join-Path - Path $WrapperRoot - ChildPath ' unbundled.js'
12
+ [String ]$WrapperScriptFilePath = Join-Path - Path $WrapperRoot - ChildPath ' main.js'
17
13
[Boolean ]$EnvironmentTested = $False
18
14
[Boolean ]$EnvironmentResult = $False
19
- [Boolean ]$DependenciesTested = $False
20
- [Boolean ]$DependenciesResult = $False
21
15
<#
22
16
. SYNOPSIS
23
17
GitHub Actions - Internal - Convert From Base64 String To Utf8 String
@@ -58,89 +52,6 @@ Function Convert-FromUtf8StringToBase64String {
58
52
}
59
53
<#
60
54
. SYNOPSIS
61
- GitHub Actions - Internal - Install NodeJS Dependencies
62
- . DESCRIPTION
63
- Use to install NodeJS wrapper API dependencies when bundled wrapper failed and retry with unbundled wrapper.
64
- . OUTPUTS
65
- [Boolean] Test result.
66
- #>
67
- Function Install-NodeJsDependencies {
68
- [CmdletBinding ()]
69
- [OutputType ([Boolean ])]
70
- Param ()
71
- If ($DependenciesTested ) {
72
- Write-Output - InputObject $DependenciesResult
73
- Return
74
- }
75
- Try {
76
- Try {
77
- $Null = Get-Command - Name ' npm' - CommandType ' Application' - ErrorAction ' Stop' # `Get-Command` will throw error when nothing is found.
78
- }
79
- Catch {
80
- Throw ' Unable to find NPM!'
81
- }
82
- Try {
83
- [String ]$NpmVersionStdOut = npm -- version |
84
- Join-String - Separator " `n "
85
- If (
86
- $NpmVersionStdOut -inotmatch $SemVerRegEx -or
87
- $NpmMinimumVersion -igt [SemVer ]::Parse(($Matches [0 ] -ireplace ' ^v' , ' ' ))
88
- ) {
89
- Throw
90
- }
91
- }
92
- Catch {
93
- Throw ' NPM is not match the requirement!'
94
- }
95
- Try {
96
- $Null = Get-Command - Name ' pnpm' - CommandType ' Application' - ErrorAction ' Stop' # `Get-Command` will throw error when nothing is found.
97
- [String ]$PnpmVersionStdOut = pnpm -- version |
98
- Join-String - Separator " `n "
99
- If (
100
- $PnpmVersionStdOut -inotmatch $SemVerRegEx -or
101
- $PnpmMinimumVersion -igt [SemVer ]::Parse(($Matches [0 ] -ireplace ' ^v' , ' ' ))
102
- ) {
103
- Throw
104
- }
105
- }
106
- Catch {
107
- Try {
108
- $Null = npm install -- global pnpm@latest
109
- }
110
- Catch {
111
- Throw ' Unable to install PNPM!'
112
- }
113
- }
114
- Try {
115
- $CurrentWorkingRoot = Get-Location
116
- $Null = Set-Location - LiteralPath $WrapperRoot
117
- Try {
118
- $Null = pnpm install
119
- }
120
- Catch {
121
- Throw ' Unable to install NodeJS wrapper API dependencies!'
122
- }
123
- Finally {
124
- Set-Location - LiteralPath $CurrentWorkingRoot.Path
125
- }
126
- }
127
- Catch {
128
- Throw $_
129
- }
130
- }
131
- Catch {
132
- Write-Verbose - Message $_
133
- $Script :DependenciesTested = $True
134
- $Script :DependenciesResult = $False
135
- Write-Output - InputObject $DependenciesResult
136
- Return
137
- }
138
- $Script :DependenciesTested = $True
139
- $Script :DependenciesResult = $True
140
- Write-Output - InputObject $DependenciesResult
141
- }
142
- <#
143
- . SYNOPSIS
144
55
GitHub Actions - Invoke NodeJS Wrapper
145
56
. DESCRIPTION
146
57
Invoke NodeJS wrapper.
@@ -157,29 +68,26 @@ Function Invoke-NodeJsWrapper {
157
68
[OutputType (([PSCustomObject ], [PSCustomObject []]))]
158
69
Param (
159
70
[Parameter (Mandatory = $True , Position = 0 )][String ]$Name ,
160
- [Parameter (Mandatory = $True , Position = 1 )][Alias (' Arguments' )][Hashtable ]$Argument ,
161
- [Alias (' Debug' )][Switch ]$LocalDebug
71
+ [Parameter (Mandatory = $True , Position = 1 )][Alias (' Arguments' )][Hashtable ]$Argument
162
72
)
163
- If (! $LocalDebug.IsPresent ) {
164
- If (! (Test-NodeJsEnvironment )) {
165
- Write-Error - Message ' This function depends and requires to invoke with the compatible NodeJS environment!' - Category ' ResourceUnavailable'
166
- Return
167
- }
73
+ If (! (Test-NodeJsEnvironment )) {
74
+ Write-Error - Message ' This function depends and requires to invoke with the compatible NodeJS environment!' - Category ' ResourceUnavailable'
75
+ Return
168
76
}
169
- ForEach ($Item In @ ($WrapperPackageFilePath , $WrapperPackageLockFilePath , $WrapperBundledFilePath , $WrapperUnbundledFilePath )) {
77
+ ForEach ($Item In @ ($WrapperPackageFilePath , $WrapperScriptFilePath )) {
170
78
If (! (Test-Path - LiteralPath $Item - PathType ' Leaf' )) {
171
- Write-Error - Message " Wrapper resource `" $Item `" is missing!" - Category ' ResourceUnavailable'
79
+ Write-Error - Message " Unable to invoke NodeJS wrapper: Wrapper resource `" $Item `" is missing!" - Category ' ResourceUnavailable'
172
80
Return
173
81
}
174
82
}
175
- [String ]$ResultSeparator = " =====$ ( New-GitHubActionsRandomToken ) ====="
176
- [String ]$Base64Name = Convert-FromUtf8StringToBase64String - InputObject $Name
177
- [String ]$Base64Argument = $Argument |
178
- ConvertTo-Json - Depth 100 - Compress |
179
- Convert-FromUtf8StringToBase64String
180
- [String ]$Base64ResultSeparator = Convert-FromUtf8StringToBase64String - InputObject $ResultSeparator
181
83
Try {
182
- [String []]$Result = Invoke-Expression - Command " node --no-deprecation --no-warnings `" $WrapperBundledFilePath `" $Base64Name $Base64Argument $Base64ResultSeparator "
84
+ [String ]$ResultSeparator = " =====$ ( New-GitHubActionsRandomToken ) ====="
85
+ [String ]$Base64Name = Convert-FromUtf8StringToBase64String - InputObject $Name
86
+ [String ]$Base64Argument = $Argument |
87
+ ConvertTo-Json - Depth 100 - Compress |
88
+ Convert-FromUtf8StringToBase64String
89
+ [String ]$Base64ResultSeparator = Convert-FromUtf8StringToBase64String - InputObject $ResultSeparator
90
+ [String []]$Result = Invoke-Expression - Command " node --no-deprecation --no-warnings `" $WrapperScriptFilePath `" $Base64Name $Base64Argument $Base64ResultSeparator "
183
91
[UInt32 []]$ResultSkipIndexes = @ ()
184
92
For ([UInt32 ]$ResultIndex = 0 ; $ResultIndex -ilt $Result.Count ; $ResultIndex ++ ) {
185
93
[String ]$ResultLine = $Result [$ResultIndex ]
@@ -204,44 +112,9 @@ Function Invoke-NodeJsWrapper {
204
112
Convert-FromBase64StringToUtf8String |
205
113
ConvertFrom-Json - Depth 100 |
206
114
Write-Output
207
- Return
208
- }
209
- Catch {
210
- Write-Warning - Message " Unable to successfully invoke NodeJS bundled wrapper (`` $Name `` ): $_ "
211
- }
212
- Try {
213
- If (! (Install-NodeJsDependencies )) {
214
- Throw ' Unable to install NodeJS wrapper API dependencies!'
215
- }
216
- [String []]$Result = Invoke-Expression - Command " node --no-deprecation --no-warnings `" $WrapperUnbundledFilePath `" $Base64Name $Base64Argument $Base64ResultSeparator "
217
- [UInt32 []]$ResultSkipIndexes = @ ()
218
- For ([UInt32 ]$ResultIndex = 0 ; $ResultIndex -ilt $Result.Count ; $ResultIndex ++ ) {
219
- [String ]$ResultLine = $Result [$ResultIndex ]
220
- If ($ResultLine -imatch ' ^::.+?::.*$' ) {
221
- Write-Host - Object $ResultLine
222
- $ResultSkipIndexes += $ResultIndex
223
- Continue
224
- }
225
- If ($ResultLine -ieq $ResultSeparator ) {
226
- $ResultSkipIndexes += @ ($ResultIndex .. ($Result.Count - 1 ))
227
- Break
228
- }
229
- }
230
- If ($LASTEXITCODE -ine 0 ) {
231
- Throw " Unexpected exit code `` $LASTEXITCODE `` ! $ (
232
- $Result |
233
- Select-Object - SkipIndex $ResultSkipIndexes |
234
- Join-String - Separator " `n "
235
- ) "
236
- }
237
- $Result [$Result.Count - 1 ] |
238
- Convert-FromBase64StringToUtf8String |
239
- ConvertFrom-Json - Depth 100 |
240
- Write-Output
241
- Return
242
115
}
243
116
Catch {
244
- Write-Error - Message " Unable to successfully invoke NodeJS unbundled wrapper (`` $Name `` ): $_ " - Category ' InvalidData'
117
+ Write-Error - Message " Unable to successfully invoke NodeJS wrapper (`` $Name `` ): $_ " - Category ' InvalidData'
245
118
}
246
119
}
247
120
<#
0 commit comments