mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
* fix: warnings that name project files print control characters as visible escapes The CLI already escaped control characters in the text its own commands print, but warnings from core, producer and engine went to the terminal raw. A composition whose sub-composition path held ESC or BEL still drove the terminal through the bundler's "Skipping sub-composition" warning in `info --media` and `snapshot`. terminalText moves to core so there is one sanitiser, the CLI imports it from there, and the library warnings that carry project text (the bundler, the producer logger, the file server, render path skips, asset load failures, FrameCapture, the import map, fonts, figma and atomic file warnings) pass that text through it. * fix: every library warning that carries project text escapes control characters
111 lines
4.0 KiB
TypeScript
111 lines
4.0 KiB
TypeScript
import { terminalText } from "@hyperframes/core";
|
||
import { c } from "../ui/colors.js";
|
||
import type { ProjectLintResult } from "./lintProject.js";
|
||
|
||
export interface LintFormatOptions {
|
||
/** Show elementId in brackets after the code (default: true) */
|
||
showElementId?: boolean;
|
||
/** Show summary line with error/warning counts (default: false) */
|
||
showSummary?: boolean;
|
||
/** Group errors before warnings per file (default: false — interleaved) */
|
||
errorsFirst?: boolean;
|
||
/** Include info-level findings in output (default: false — only errors/warnings) */
|
||
verbose?: boolean;
|
||
}
|
||
|
||
/**
|
||
* Format lint findings for console output. Used by lint, render, and preview commands.
|
||
*/
|
||
export function formatLintFindings(
|
||
{ results, totalErrors, totalWarnings, totalInfos }: ProjectLintResult,
|
||
options: LintFormatOptions = {},
|
||
): string[] {
|
||
const {
|
||
showElementId = true,
|
||
showSummary = false,
|
||
errorsFirst = false,
|
||
verbose = false,
|
||
} = options;
|
||
const lines: string[] = [];
|
||
const multiFile = results.length > 1;
|
||
|
||
for (const { file, result } of results) {
|
||
if (result.findings.length === 0) continue;
|
||
|
||
const format = (finding: (typeof result.findings)[0]) => {
|
||
if (!verbose && finding.severity === "info") return;
|
||
const prefix =
|
||
finding.severity === "error"
|
||
? c.error("✗")
|
||
: finding.severity === "warning"
|
||
? c.warn("⚠")
|
||
: c.dim("ℹ");
|
||
const fileLabel = findingFileLabel(file, finding, multiFile);
|
||
const loc =
|
||
showElementId && finding.elementId
|
||
? ` ${c.accent(`[${terminalText(finding.elementId)}]`)}`
|
||
: "";
|
||
const message = terminalText(finding.message);
|
||
lines.push(` ${prefix} ${fileLabel}${c.bold(finding.code)}${loc}: ${message}`);
|
||
if (finding.fixHint) lines.push(` ${c.dim(`Fix: ${terminalText(finding.fixHint)}`)}`);
|
||
};
|
||
|
||
if (errorsFirst) {
|
||
for (const f of result.findings) if (f.severity === "error") format(f);
|
||
for (const f of result.findings) if (f.severity === "warning") format(f);
|
||
if (verbose) for (const f of result.findings) if (f.severity === "info") format(f);
|
||
} else {
|
||
for (const f of result.findings) format(f);
|
||
}
|
||
}
|
||
|
||
if (showSummary) {
|
||
const icon = totalErrors > 0 ? c.error("◇") : c.success("◇");
|
||
lines.push("");
|
||
lines.push(`${icon} ${formatLintCounts(totalErrors, totalWarnings, totalInfos, verbose)}`);
|
||
}
|
||
|
||
return lines;
|
||
}
|
||
|
||
function formatLintCounts(
|
||
totalErrors: number,
|
||
totalWarnings: number,
|
||
totalInfos: number,
|
||
verbose: boolean,
|
||
): string {
|
||
const parts = [`${totalErrors} error(s)`, `${totalWarnings} warning(s)`];
|
||
if (verbose && totalInfos > 0) parts.push(`${totalInfos} info(s)`);
|
||
return parts.join(", ");
|
||
}
|
||
|
||
/** Full findings in verbose mode, a one-line summary otherwise. `pointer` (summary
|
||
* mode) picks the hint: both name the lint command, "studio" also the Studio badge. --lint-verbose is
|
||
* not named: only render, preview and publish take it, and agents tried it on lint and check. */
|
||
export type LintMessageMode =
|
||
| { kind: "verbose"; options?: LintFormatOptions }
|
||
| { kind: "summary"; pointer?: "cli" | "studio" };
|
||
|
||
export function formatLintStartupMessage(
|
||
lintResult: ProjectLintResult,
|
||
mode: LintMessageMode,
|
||
): string[] {
|
||
if (mode.kind === "verbose") return formatLintFindings(lintResult, mode.options);
|
||
const counts = formatLintCounts(lintResult.totalErrors, lintResult.totalWarnings, 0, false);
|
||
const hint =
|
||
mode.pointer === "studio"
|
||
? "see the Lint badge in Studio, or run `hyperframes lint` for full output"
|
||
: "run `hyperframes lint` for full output";
|
||
return [` Lint: ${counts} — ${hint}.`];
|
||
}
|
||
|
||
function findingFileLabel(
|
||
file: string,
|
||
finding: import("@hyperframes/lint").HyperframeLintFinding,
|
||
multiFile: boolean,
|
||
): string {
|
||
if (finding.line === undefined) return multiFile ? c.dim(`[${terminalText(file)}] `) : "";
|
||
const column = finding.column === undefined ? "" : `:${finding.column}`;
|
||
return c.dim(`[${terminalText(finding.file ?? file)}:${finding.line}${column}] `);
|
||
}
|