ts-project-builder
Version:
Rollup-based TypeScript builder with multi-format output and built-in common plugins.
1 lines • 3.79 kB
Source Map (JSON)
{"version":3,"file":"logging.mjs","sources":["../../../src/utils/rollup/logging.ts"],"sourcesContent":["import type { RollupError } from 'rollup';\n\nimport {\n bold,\n cyan,\n dim,\n red,\n} from './colors';\nimport { relativeId } from './relativeId';\n\n// log to stderr to keep `rollup main.js > bundle.js` from breaking\nexport const stderr = (...parameters: readonly unknown[]) => process.stderr.write(`${parameters.join('')}\\n`);\nexport function handleError(error: RollupError) {\n const name = error.name || (error.cause as Error)?.name;\n const nameSection = name ? `${name}: ` : '';\n const pluginSection = error.plugin ? `(plugin ${error.plugin}) ` : '';\n const message = `${pluginSection}${nameSection}${error.message}`;\n const outputLines = [bold(red(`[!] ${bold(message.toString())}`))];\n if (error.url) outputLines.push(cyan(error.url));\n if (error.loc) {\n outputLines.push(`${relativeId((error.loc.file || error.id)!)}:${error.loc.line}:${error.loc.column}`);\n } else if (error.id) outputLines.push(relativeId(error.id));\n if (error.frame) outputLines.push(dim(error.frame));\n if (error.stack) outputLines.push(dim(error.stack?.replace(`${nameSection}${error.message}\\n`, '')));\n // ES2022: Error.prototype.cause is optional\n if (error.cause) {\n let cause = error.cause as Error | undefined;\n const causeErrorLines = [];\n let indent = '';\n while (cause) {\n indent += ' ';\n const message = cause.stack || cause;\n causeErrorLines.push(...`[cause] ${message}`.split('\\n').map((line) => `${indent}${line}`));\n cause = cause.cause as Error | undefined;\n }\n\n outputLines.push(dim(causeErrorLines.join('\\n')));\n }\n\n outputLines.push('', '');\n stderr(outputLines.join('\\n'));\n}\n"],"names":[],"mappings":";;;AAUA;AACa,MAAA,MAAM,GAAG,CAAC,GAAG,UAA8B,KAAK,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,EAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAI,EAAA,CAAA;AACtG,SAAU,WAAW,CAAC,KAAkB,EAAA;IAC1C,MAAM,IAAI,GAAG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