CapturingProcessHandler seems to always return LF line separators from stdout
已回答
I'm experimenting a bit with the BiomeJS Intellij plugin, because it currently does not change the line endings. After testing a bit, it seems that the output of the CapturingProcessHandler always only contain `\n`, regardless what the CLI returns.
The Code I tested with is on Github; but it always returns LF Separators. But when I run the exact command in a Python script, it will correctly show me the CRLF separators.
Can someone help me, or point me to the correct documentation, I could not find anything :(
Python Script for testing biome cli output
from subprocess import Popen, PIPE
cmd = [
r"C:\Program Files\nodejs\node.exe",
r"D:\test\node\node_modules\@biomejs\biome\bin\biome",
"check",
"--stdin-file-path",
r"D:/test/node/main.ts",
"--formatter-enabled=true",
"--write",
"--config-path",
r"D:/test/node"
]
ls = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
with open("D:/test/node/main.ts", "r") as f:
data = f.read()
stdout, stderr = ls.communicate(str.encode(data), timeout=3)
print(stdout)
Relevant IntelliJ Logs
2024-07-28 12:10:50,326 [1010948] INFO - STDOUT - C:\Program Files\nodejs\node.exe [D:\test\node\node_modules\@biomejs\biome\bin\biome, check, --stdin-file-path, D:/test/node/main.ts, --formatter-enabled=true, --write, --config-path, D:/test/node]
2024-07-28 12:10:50,380 [1011002] INFO - STDOUT - Out function test() {
2024-07-28 12:10:50,380 [1011002] INFO - STDOUT - console.log("TEST");
2024-07-28 12:10:50,380 [1011002] INFO - STDOUT - }
2024-07-28 12:10:50,380 [1011002] INFO - STDOUT -
2024-07-28 12:10:50,380 [1011002] INFO - STDOUT - LINE SEP process: 0
2024-07-28 12:10:50,380 [1011002] INFO - STDOUT - LINE SEP std: 0
2024-07-28 12:10:50,381 [1011003] INFO - STDOUT - LINE SEP applyChanges: 0
2024-07-28 12:10:50,381 [1011003] INFO - STDOUT - SEPS: 0 1
请先登录再写评论。
Hi,
Could you please share more context of the issue? What problem does it cause?
Hi,
BiomeJS can format on save and does so with stdin and stdout. That also includes the line separators, but because the command line output seems to be LF only, it does not format the line separators.
I can think of two way of fixing it:
1. Create `CapturingProcessHandler`, so it doesn't convert `\r\n` to `\n`:
2. Obtain output with `\n` instead of `\r\n`, but save it to a file using proper line separators, like Prettier does.