UNPKG

myst-cli

Version:
34 lines (33 loc) 1.21 kB
import { addWarningForFile } from './addWarningForFile.js'; import { writeFileToFolder } from 'myst-cli-utils'; import { join } from 'node:path'; export function logMessagesFromVFile(session, file) { if (!file) return; const messages = file.messages; messages.forEach((message) => { const kind = message.fatal === null ? 'info' : message.fatal === false ? 'warn' : 'error'; addWarningForFile(session, file.path, message.message, kind, { position: message.position, note: message.note, url: message.url, ruleId: message.ruleId, /** This key can be combined with the ruleId to suppress a warning */ key: message.key, }); }); file.messages = []; } export function writeJsonLogs(session, name, logData) { const seen = new WeakSet(); const data = JSON.stringify(logData, function (_, value) { if (typeof value === 'object' && value !== null) { if (seen.has(value)) { return '[Circular]'; } seen.add(value); } return value; }, 2); writeFileToFolder(join(session.buildPath(), 'logs', name), data); }