Skip to content

Commit

Permalink
fix(fancy): add node 14 compatibility (resolves #204)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 28, 2023
1 parent 28f1cd6 commit 2e72913
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/reporters/fancy.ts
@@ -1,10 +1,11 @@
import stringWidth from "string-width";
import _stringWidth from "string-width";
import isUnicodeSupported from "is-unicode-supported";
import { colors } from "../utils/color";
import { parseStack } from "../utils/error";
import { FormatOptions, LogObject } from "../types";
import { LogLevel, LogType } from "../constants";
import { BoxOpts, box } from "../utils/box";
import { stripAnsi } from "../utils";
import { BasicReporter } from "./basic";

export const TYPE_COLOR_MAP: { [k in LogType]?: string } = {
Expand Down Expand Up @@ -36,6 +37,14 @@ const TYPE_ICONS: { [k in LogType]?: string } = {
log: "",
};

function stringWidth(str: string) {
// https://github.com/unjs/consola/issues/204
if (!Intl.Segmenter) {
return stripAnsi(str).length;
}
return _stringWidth(str);
}

export class FancyReporter extends BasicReporter {
formatStack(stack: string) {
return (
Expand Down

0 comments on commit 2e72913

Please sign in to comment.