unjs / consola

🐨 Elegant Console Logger for Node.js and Browser
Other
5.78k stars 165 forks source link

'box()' function does not work with a title >=2 chars longer than the content length #300

Open GRyanParoz opened 2 weeks ago

GRyanParoz commented 2 weeks ago

Environment

Consola version 3.2.3

Tested using Bun v1.1.12 and Node.js 18.20.3 (Stackblitz)

Reproduction

https://stackblitz.com/edit/stackblitz-starters-zlz8zk?file=index.js

Describe the bug

If the box function from consola/utils (or consola.box) is called with a "title" option that contains a string 2 characters longer than the content itself, an error is thrown and the box is not drawn.

Additional context

The error is coming from String.repeat, seemingly because the number of repeated characters is calculated by subtracting the title length from the content length or something similar.

Logs

RangeError: String.prototype.repeat argument must be greater than or equal to 0 and not be Infinity
      at repeat (:1:21)
      at box (<private-project>/node_modules/consola/dist/utils.mjs:246:18)
      at previewJson (<private-project>/src/logger.ts:17:13)
      at <private-project>/src/deploy-schema.ts:23:5

Bun v1.1.12 (Linux x64)
error: script "schema:deploy" exited with code 1

-----

Error: repeat count must be non-negative
    at _evaluate (https://stackblitzstarterszlz8zk-vfqw.w-corp-staticblitz.com/blitz.12d46890.js:40:783715)

Node.js 18.20.3