Skip to content

Commit 398222d

Browse files
author
James Brundage
committed
Invoke-PipeScript: Changing how SourceGenerators are processed (#86)
1 parent f317c3c commit 398222d

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

Invoke-PipeScript.ps1

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -253,39 +253,34 @@
253253
# predetermine the output path
254254
$outputPath = $($Command.Source -replace $IsSourceGenerator, '.${ext}')
255255
# and attempt to find a transpiler.
256-
$foundTranspiler = Get-Transpiler -CouldPipe $Command
256+
$foundTranspiler = Get-Transpiler -CouldPipe $Command -ValidateInput $Command -ErrorAction Ignore
257+
257258

258259
# Push into the location of the file, so the current working directory will be accurate for any inline scripts.
259260
Push-Location ($command.Source | Split-Path)
260261

261262
# Get the output from the source generator.
262263
$pipescriptOutput =
263264
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 =
289284
# If the transpiler returned a [ScriptBlock]
290285
if ($transpilerOutput -is [Scriptblock]) {
291286
# recursively invoke.
@@ -295,9 +290,13 @@
295290
# otherwise, return the output of the transpiler.
296291
$transpilerOutput
297292
}
298-
break
293+
294+
# If the transpiler had output,
295+
if ($transpilerOutput) {
296+
$transpilerOutput # use that output
297+
break # and stop processing additional transpilers.
299298
}
300-
}
299+
}
301300
} else {
302301
# If we did not find a transpiler, treat the source code as PipeScript/PowerShell.
303302
$fileScriptBlock =
@@ -317,8 +316,12 @@
317316
}
318317

319318
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+
}
322325
}
323326

324327
# Now that the source generator has finished running, we can Pop-Location.

0 commit comments

Comments
 (0)