oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.48k stars 2.79k forks source link

I can't type any characters into the terminal. (STDIN, STDOUT) #11125

Closed nodirbekrajaboff closed 6 months ago

nodirbekrajaboff commented 6 months ago

What version of Bun is running?

1.1.8+89d25807f

What platform is your computer?

Linux 4.15.0-208-generic x86_64 x86_64

What steps can reproduce the bug?

I ran the file through bunjs and I can't type any letters through the terminal. This is only not working on my ubuntu server. In another server this codes working. This is my codes:

import { ENVLIST } from "@/config/env"; import getRootPath from "@/utils/get-root-path"; import readline from "readline"; import path from "node:path";

const rl = readline.createInterface({ input: process.stdin, output: process.stdout, });

const env = path.join(getRootPath(), ".env");

async function promptAndWriteEnv(index: number) { if (index < ENV_LIST.length) { if (!(await Bun.file(env).exists())) await Bun.write(env, "");

if (await checkIfExists(ENV_LIST[index])) {
  console.log(${ENV_LIST[index]} already exists in .env file.);
  promptAndWriteEnv(index + 1);
} else
  rl.question(Enter value for ${ENV_LIST[index]}: , async (value) => {
    let text = "";
    let result = "";

    const file = Bun.file(env);
    if (await file.exists()) {
      text += await file.text();
      result += ${text}\n${ENV_LIST[index]}=${
        !isNaN(Number(value)) ? value : "${value}"
      }\n;
    }

    Bun.write(
      env,
      result
        .replace(/(\r\n|\r|\n){2}/g, "$1")
        .replace(/(\r\n|\r|\n){3,}/g, "$1\n")
    );
    console.log(${ENV_LIST[index]} added to .env file successfully!);
    promptAndWriteEnv(index + 1);
  });

} else { console.log(".env file created successfully!"); rl.close(); } }

async function checkIfExists(variable: string) { const envData = await Bun.file(env).text(); const envLines = envData.split("\n"); for (const line of envLines) { const [key, ] = line.split("="); if (key.trim() === variable) return true; } return false; }

promptAndWriteEnv(0);

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

Jarred-Sumner commented 5 months ago

If you upgrade to a more recent Linux kernel this will likely be fixed