sindresorhus/ora

ora blinks after using writeFileSync.

SparkElf opened this issue · 1 comments

os:ubuntu 20.04
env:nodejs 14.18.0
code:

export class Logger {
    logger: Ora
    constructor() {
        this.logger = ora()
    }
    start(s): Logger {
        this.logger = ora().start(chalk.bold(s))
        return this
    }
    fail(s): Logger {
        if (this.logger.isSpinning)
            this.logger.fail(chalk.red.bold(s))
        else
            this.logger = ora().fail(chalk.red.bold(s))
        if (s instanceof Error)
            console.log(s)
        return this
    }
    succeed(s): Logger {
        if (this.logger.isSpinning)
            this.logger.succeed(chalk.bold(s))
        else
            this.logger = ora().succeed(chalk.bold(s))
        return this
    }

}
export function Log(): Logger {
    return new Logger()
}
export const log = Log()

 log.start('connecting')
  let { data, headers } = await axios.get<Stream>(url, {
    timeout: 30 * SECOND,
    responseType: "stream"
  })
  //BUG:ora blinks
  writeFileSync('axios.log', toJsonBeautiful(headers))
  log.succeed('connect succeed')

See https://github.com/sindresorhus/ora#why-does-the-spinner-freeze

This is just how JavaScript works. That's why async methods should be preferred in Node.js.