UNPKG

@sanity/pkg-utils

Version:

Simple utilities for modern npm packages.

45 lines (44 loc) 1.41 kB
import path from "node:path"; import { ExtractorLogLevel } from "@microsoft/api-extractor"; import chalk from "chalk"; function printExtractMessages(ctx, messages) { const { cwd, logger } = ctx, warnings = messages.filter((msg) => msg.logLevel === ExtractorLogLevel.Warning); warnings.length && logger.log(); for (const msg of warnings) { const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath); msg.messageId !== "TS6307" && logger.log( [ chalk.cyan(sourceFilePath || "?"), `:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`, ` - ${chalk.yellow("warning")} ${chalk.gray(msg.messageId)} `, msg.text, ` ` ].join("") ); } const errors = messages.filter( (msg) => msg.logLevel === ExtractorLogLevel.Error ); !warnings.length && errors.length && logger.log(""); for (const msg of errors) { const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath); logger.log( [ chalk.cyan(sourceFilePath || "?"), `:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`, ` - ${chalk.red("error")} ${chalk.gray(msg.messageId)} `, msg.text, ` ` ].join("") ); } errors.length && process.exit(1); } export { printExtractMessages }; //# sourceMappingURL=printExtractMessages.js.map