stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.82k stars 148 forks source link

Writing to the stdin of a process launched with WebContainerInstance.spawn converts \r\n to \n\n #1341

Open paoloricciuti opened 7 months ago

paoloricciuti commented 7 months ago

Describe the bug

Kind of a niche one but i was trying to integrate sveltelab with the svelte language server (which use the vscode-json-rpc under the hood.

To trigger the language server i need to write the header followed by \r\n\r\n followed by the actual rpc message.

It was not working so i started modifying the node modules of vscode-json-rpc inside the webcontainer to get some log and i realized that whenever i wrote \r\n to the stdin what the process actually received was \n\n.

I don't know how to properly create a reproduction for this. 😶

Link to the blitz that caused the error

not a problem with stackblitz itself, but with @webcontainers/api

Steps to reproduce

As i've said i don't really know how to create a usable reproduction for this since it was me messing around with the node modules inside a webcontainer instance.

Expected behavior

\r\n should be sent as \r\n

Parity with Local

Screenshots

No response

Platform

Additional context

No response

Nemikolh commented 7 months ago

Hey @paoloricciuti !

I think this might be indeed a bug. A workaround would be to set process.setRawMode(true) and you get the expected value.

See this example: https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-with-terminal-pu4jpy?file=main.js

We just write \r\n to the process spawned and it obtains the correct data on stdin.

paoloricciuti commented 7 months ago

Hey @paoloricciuti !

I think this might be indeed a bug. A workaround would be to set process.setRawMode(true) and you get the expected value.

See this example: https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-with-terminal-pu4jpy?file=main.js

We just write \r\n to the process spawned and it obtains the correct data on stdin.

Yeah that's what I'm doing right now...I have a proxy process that just spawn the actual process and log every response back. But it adds a layer of complexity (also just tought of reporting anyway in case you want to fix it 😊)

jrvidal commented 7 months ago

This is not, strictly speaking, a bug, but a limitation of WebContainer itself (somewhat related to https://github.com/stackblitz/webcontainer-core/issues/971). The input stream of a process is actually a TTY, which by default normalizes line endings. We do have an idea for a "fix" (see this comment).

paoloricciuti commented 7 months ago

This is not, strictly speaking, a bug, but a limitation of WebContainer itself (somewhat related to #971). The input stream of a process is actually a TTY, which by default normalizes line endings. We do have an idea for a "fix" (see this comment).

That would be cool (as long as the normal mode that can actually attach to a shell is still there lol)

cryingpotat0 commented 5 months ago

Just chiming in to say I'm also running into this for the same use case and would love to have a way to directly address stdin/ stdout.