webcontainer-core icon indicating copy to clipboard operation
webcontainer-core copied to clipboard

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

Open paoloricciuti opened this issue 1 year ago • 5 comments
trafficstars

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

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

paoloricciuti avatar Feb 22 '24 17:02 paoloricciuti

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.

Nemikolh avatar Feb 23 '24 21:02 Nemikolh

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 😊)

paoloricciuti avatar Feb 23 '24 21:02 paoloricciuti

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).

jrvidal avatar Feb 24 '24 08:02 jrvidal

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)

paoloricciuti avatar Feb 24 '24 09:02 paoloricciuti

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.

cryingpotat0 avatar Apr 20 '24 06:04 cryingpotat0