webcontainer-core
webcontainer-core copied to clipboard
Writing to the stdin of a process launched with WebContainerInstance.spawn converts \r\n to \n\n
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
- [X] I have run the project in my local machine and I could not reproduce the issue.
Screenshots
No response
Platform
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari, Firefox]
- Version: [e.g. 91.1]
Additional context
No response
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.
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\nto the process spawned and it obtains the correct data onstdin.
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 😊)
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).
This is not, strictly speaking, a bug, but a limitation of WebContainer itself (somewhat related to #971). The
inputstream 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)
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.