|
253 | 253 | # predetermine the output path |
254 | 254 | $outputPath = $($Command.Source -replace $IsSourceGenerator, '.${ext}') |
255 | 255 | # and attempt to find a transpiler. |
256 | | - $foundTranspiler = Get-Transpiler -CouldPipe $Command |
| 256 | + $foundTranspiler = Get-Transpiler -CouldPipe $Command -ValidateInput $Command -ErrorAction Ignore |
| 257 | + |
257 | 258 |
|
258 | 259 | # Push into the location of the file, so the current working directory will be accurate for any inline scripts. |
259 | 260 | Push-Location ($command.Source | Split-Path) |
260 | 261 |
|
261 | 262 | # Get the output from the source generator. |
262 | 263 | $pipescriptOutput = |
263 | 264 | if ($foundTranspiler) { # If we found transpilers |
264 | | - foreach ($ft in $foundTranspiler) { |
265 | | - if ($( |
266 | | - $eap = $ErrorActionPreference |
267 | | - $ErrorActionPreference = 'ignore' |
268 | | - # ensure they are valid |
269 | | - $ft.ExtensionCommand.Validate($Command, $true) |
270 | | - $ErrorActionPreference = $eap |
271 | | - )) { |
272 | | - # and run the transpiler. |
273 | | - |
274 | | - $null = |
275 | | - New-Event -SourceIdentifier 'PipeScript.SourceGenerator.Start' -MessageData ([PSCustomObject][Ordered]@{ |
276 | | - Transpiler = $ft.ExtensionCommand |
277 | | - SourcePath = $command.Source |
278 | | - }) |
279 | | - |
280 | | - $transpilerOutput = $command | & $ft.ExtensionCommand |
281 | | - |
282 | | - $null = |
283 | | - New-Event -SourceIdentifier 'PipeScript.SourceGenerator.Stop' -MessageData ([PSCustomObject][Ordered]@{ |
284 | | - Transpiler = $ft.ExtensionCommand |
285 | | - TranspilerOutput = $transpilerOutput |
286 | | - SourcePath = $command.Source |
287 | | - }) |
288 | | - |
| 265 | + foreach ($ft in $foundTranspiler) { |
| 266 | + # run them. |
| 267 | + |
| 268 | + $null = |
| 269 | + New-Event -SourceIdentifier 'PipeScript.SourceGenerator.Start' -MessageData ([PSCustomObject][Ordered]@{ |
| 270 | + Transpiler = $ft.ExtensionCommand |
| 271 | + SourcePath = $command.Source |
| 272 | + }) |
| 273 | + |
| 274 | + $transpilerOutput = $command | & $ft.ExtensionCommand |
| 275 | + |
| 276 | + $null = |
| 277 | + New-Event -SourceIdentifier 'PipeScript.SourceGenerator.Stop' -MessageData ([PSCustomObject][Ordered]@{ |
| 278 | + Transpiler = $ft.ExtensionCommand |
| 279 | + TranspilerOutput = $transpilerOutput |
| 280 | + SourcePath = $command.Source |
| 281 | + }) |
| 282 | + |
| 283 | + $transpilerOutput = |
289 | 284 | # If the transpiler returned a [ScriptBlock] |
290 | 285 | if ($transpilerOutput -is [Scriptblock]) { |
291 | 286 | # recursively invoke. |
|
295 | 290 | # otherwise, return the output of the transpiler. |
296 | 291 | $transpilerOutput |
297 | 292 | } |
298 | | - break |
| 293 | + |
| 294 | + # If the transpiler had output, |
| 295 | + if ($transpilerOutput) { |
| 296 | + $transpilerOutput # use that output |
| 297 | + break # and stop processing additional transpilers. |
299 | 298 | } |
300 | | - } |
| 299 | + } |
301 | 300 | } else { |
302 | 301 | # If we did not find a transpiler, treat the source code as PipeScript/PowerShell. |
303 | 302 | $fileScriptBlock = |
|
317 | 316 | } |
318 | 317 |
|
319 | 318 | if (-not $fileScriptBlock) { return } |
320 | | - $InvokePipeScriptParameters.Command = $fileScriptBlock |
321 | | - Invoke-PipeScript @InvokePipeScriptParameters |
| 319 | + if ($command.Source -match '\.psm{0,1}1{0,1}$') { |
| 320 | + $fileScriptBlock |
| 321 | + } else { |
| 322 | + $InvokePipeScriptParameters.Command = $fileScriptBlock |
| 323 | + Invoke-PipeScript @InvokePipeScriptParameters |
| 324 | + } |
322 | 325 | } |
323 | 326 |
|
324 | 327 | # Now that the source generator has finished running, we can Pop-Location. |
|
0 commit comments