UNPKG

radish

Version:

Radish is a React-based static site generator that outputs plain HTML and CSS.

51 lines (50 loc) 1.36 kB
export function fromSuccess(input, output) { return { inputFile: input, outputFile: output }; } export function fromRenderError(e) { const [, frame] = e.stack?.split("\n") || []; if (!frame) throw e; const [, body = "", l, c] = frame.match(/\s*at \w+ \((.*):(\d+):(\d+)\)/) ?? []; if (!l || !c) throw e; const lineNo = Number(l), colNo = Number(c); const src = decodeURIComponent(body); const lines = src.split("\n"); let file = "", fileLineNo = 0; for (let i = lineNo; i >= 0; i--) { const line = lines[i]; if (line?.startsWith("// ")) { file = line.slice(3); fileLineNo = lineNo - i; break; } } if (!file) throw e; return { inputFile: file, error: { type: e.name, message: e.message, lineText: lines[lineNo - 1] ?? "", line: fileLineNo, column: colNo } }; } export function fromBuildError(result) { return { inputFile: result.location?.file ?? "", error: { type: "BundleError", message: result.text, lineText: result.location?.lineText ?? "", line: result.location?.line ?? 0, column: result.location?.column ?? 0 } }; }