From d87b7ed3d5956254964137253b32215d80147fc3 Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Fri, 1 Aug 2025 10:51:03 -0400 Subject: [PATCH 1/2] Don't redirect stdin when running headless. Fixes https://github.com/gren-lang/compiler/issues/341 --- src/Main.gren | 44 ++++++++++++++++++++++++++----------------- src/Terminal/Run.gren | 1 + 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Main.gren b/src/Main.gren index b84e9798..7924cf3d 100644 --- a/src/Main.gren +++ b/src/Main.gren @@ -170,10 +170,10 @@ type Msg , downloadResult : Result (HttpClient.Error Bytes) (HttpClient.Response Bytes) } | CompilerInstalled (Result FileSystem.Error Path) - | CompilerInitialized { quiet : Bool, backendStreams : ChildProcess.StreamIO, encodedCommand : Bytes } + | CompilerInitialized { headless : Bool, backendStreams : ChildProcess.StreamIO, encodedCommand : Bytes } | CompilerRan Int | CompiledForRun { path : Path, exitCode : Int } - | RunStarted Process.Id + | RunStarted { processId : Process.Id, streams : Maybe ChildProcess.StreamIO } | RunExited Int | RedirectTerminalIO (Result @@ -257,19 +257,29 @@ update msg model = CompilerInstalled (Ok compilerPath) -> parseUserArgs model compilerPath - CompilerInitialized { backendStreams, encodedCommand, quiet } -> + CompilerInitialized { backendStreams, encodedCommand, headless } -> Cmd.batch - [ Stream.write encodedCommand backendStreams.input - |> Task.map (\_ -> { source = model.stdin, target = backendStreams.input }) - |> Task.mapError - (\err -> - { error = err - , source = model.stdin - , target = backendStreams.input - } - ) - |> Task.attempt RedirectTerminalIO - , if quiet then + [ if headless then + Stream.write encodedCommand backendStreams.input + |> Task.map (\_ -> {}) + |> Task.onError + (\e -> + Stream.Log.line model.stderr (Stream.errorToString e) + |> Task.andThen (\_ -> Node.exitWithCode 1) + ) + |> Task.execute + else + Stream.write encodedCommand backendStreams.input + |> Task.map (\_ -> { source = model.stdin, target = backendStreams.input }) + |> Task.mapError + (\err -> + { error = err + , source = model.stdin + , target = backendStreams.input + } + ) + |> Task.attempt RedirectTerminalIO + , if headless then Cmd.none else Task.succeed { source = backendStreams.output, target = model.stdout } @@ -288,7 +298,7 @@ update msg model = , fsPermission = model.fsPermission , pathToString = model.pathToString , path = path - , onInit = \{ processId } -> RunStarted processId + , onInit = RunStarted , onExit = RunExited } |> Task.onError @@ -391,7 +401,7 @@ parseUserArgs model compilerPath = Just streams -> CompilerInitialized { backendStreams = streams - , quiet = False + , headless = False , encodedCommand = Compiler.Backend.encodeCommand { interactiveSession = model.interactive @@ -544,7 +554,7 @@ parseUserArgs model compilerPath = CompilerInitialized { backendStreams = streams , encodedCommand = encodedCommand - , quiet = True + , headless = True } ) , onCompiled = diff --git a/src/Terminal/Run.gren b/src/Terminal/Run.gren index 80f19fd8..3a70e9b5 100644 --- a/src/Terminal/Run.gren +++ b/src/Terminal/Run.gren @@ -208,6 +208,7 @@ run config = runWith command = ChildProcess.defaultSpawnOptions config.onInit config.onExit + |> (\opts -> { opts | connection = ChildProcess.Integrated }) |> ChildProcess.spawn config.cpPermission command [ path ] |> Task.succeed in From e1b4334a9f62ff1867f8ea4745fa3787c7841f29 Mon Sep 17 00:00:00 2001 From: Justin Blake Date: Mon, 4 Aug 2025 06:40:26 -0400 Subject: [PATCH 2/2] Clean up RedirectTerminalIO message The streams that were being passed are never used. --- src/Main.gren | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/Main.gren b/src/Main.gren index 7924cf3d..4929c402 100644 --- a/src/Main.gren +++ b/src/Main.gren @@ -177,10 +177,7 @@ type Msg | RunExited Int | RedirectTerminalIO (Result - { error : Stream.Error - , source : Stream.Readable Bytes - , target : Stream.Writable Bytes - } + Stream.Error { source : Stream.Readable Bytes , target : Stream.Writable Bytes } @@ -271,13 +268,6 @@ update msg model = else Stream.write encodedCommand backendStreams.input |> Task.map (\_ -> { source = model.stdin, target = backendStreams.input }) - |> Task.mapError - (\err -> - { error = err - , source = model.stdin - , target = backendStreams.input - } - ) |> Task.attempt RedirectTerminalIO , if headless then Cmd.none @@ -323,16 +313,9 @@ update msg model = Stream.read streams.source |> Task.andThen (\str -> Stream.write str streams.target) |> Task.map (\_ -> streams) - |> Task.mapError - (\err -> - { error = err - , source = streams.source - , target = streams.target - } - ) |> Task.attempt RedirectTerminalIO - RedirectTerminalIO (Err { error, source, target }) -> + RedirectTerminalIO (Err error) -> when error is Stream.Closed -> Cmd.none