Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fable CLI 3.7 watch stales #2727

Closed
AngelMunoz opened this issue Jan 13, 2022 · 8 comments
Closed

Fable CLI 3.7 watch stales #2727

AngelMunoz opened this issue Jan 13, 2022 · 8 comments

Comments

@AngelMunoz
Copy link

Description

Hey! sorry to bother again
When invoking the fable cli 3.7.0-beta-* in watch mode through a library like CliWrap it never goes into watch mode this behavior is not observed in v3.6.3 using the same conditions

Fable: F# to JS compiler 3.7.0-beta-009
Thanks to the contributor! @fbehrens

Parsing src\fable37-cli.fsproj...
src> cmd /C dotnet restore fable37-cli.fsproj
  Determining projects to restore...
  All projects are up-to-date for restore.
Project and references (1 source files) parsed in 2125ms

Started Fable compilation...

Repro code

Here's a reproduction repository: https://github.com/AngelMunoz/fable37-cli

Expected and actual results

I expect to observe the same behavior as Fable 3.6.3, it should compile and start watching for file changes

Related information

  • Fable version: dotnet fable --version: 3.7.0-beta-009
  • Operating system: Windows 11
@AngelMunoz
Copy link
Author

Note: invoking the CLI manually dotnet fable watch ./src/project.fsproj doesn't fail... so I'm not sure if it is related to something with a stdout redirect

@alfonsogarciacaro
Copy link
Member

Ah, I see. Does watch mode doesn't work at all (no JS files are generated) or you just don't see the logs on screen? For Fable 3.7 I tried to bring back the one-line logs because they're very nice to see the progress of compilation:

screencast

But it may happen they don't play well with this CliWrap tool. I'm trying to disable the logs in CI where usually rewriting the same line is not possible. Maybe is there a way to also detect when the tool is being called as a subprocess?

let inSameLineIfNotCI (msg: string) =
if isVerbose() then
Console.Out.WriteLine(msg)
elif not isCi then
// If the message is longer than the terminal width it will jump to next line
let msg = if msg.Length > 80 then msg.[..80] + "..." else msg
let curCursorLeft = Console.CursorLeft
Console.SetCursorPosition(0, Console.CursorTop)
Console.Out.Write(msg)
let diff = curCursorLeft - msg.Length
if diff > 0 then
Console.Out.Write(String.replicate diff " ")
Console.SetCursorPosition(msg.Length, Console.CursorTop)

@AngelMunoz
Copy link
Author

I think they are generated, I need to check further, but CliWrap allows me to set env vars for the process perhaps I can add the CI env var, I'll test in a couple of hours and let you know

@AngelMunoz
Copy link
Author

Well it weren't a few hours I could find a spot

I see. Does watch mode doesn't work at all (no JS files are generated)

I just checked and no, no files are generated at all

Setting the CI flag (.WithEnvironmentVariables(fun env -> env.Set("CI", "1") |> ignore)) does indeed make it work! it isn't as pretty but works nicely
image

@alfonsogarciacaro
Copy link
Member

Hmm, interesting. So I guess that trying to move the cursor when being called from CliWrap is breaking/freezing the process somehow. Maybe opening an issue about that in CliWrap? Or you may need to spawn the process with its own shell.

@AngelMunoz
Copy link
Author

AngelMunoz commented Jan 14, 2022

Had a talk with CliWrap's author on discord he was kind enough to give this issue a glance

Hi. Moving the cursor should not affect CliWrap anyhow, however the actual code that does this (i.e. calling Console.SetCursorPosition in Fable compiler) would most likely throw. I don't remember exactly. Are you sure the process doesn't outright crash? If so, it might write something to stderr.

Interestingly it doesn't seem to throw or crash the process (maybe it does? I just know that the program keeps running waiting for the command to finish)

Also Alfonso said:

Maybe is there a way to also detect when the tool is being called as a subprocess?

You can do that by checking if the output is redirected via Console.IsOutputRedirected. If true, it's running through some automation tool and not in a shell.

You might be able to use this one instead of the CI env var possibly?

The best way to debug this would be to add Debugger.Attach() somewhere inside Fable compiler, probably put a breakpoint also in StreamPipeTarget (created by PipeTarget.ToStream(...), then call the CLI from CliWrap, and then see what happens exactly

I Will try to investigate further over the weekend if I have a chance in the meantime I can workaround this issue with the CI env var, I'll let you know if I find something

@alfonsogarciacaro
Copy link
Member

Thanks for checking with CliWrap author @AngelMunoz! I've added the Console.IsOutputRedirected check, can you please try with beta-011?

@AngelMunoz
Copy link
Author

Just in time before I go to sleep 😴 it worked!

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants