dts-bundle-generator
Version:
DTS Bundle Generator
21 lines (20 loc) • 854 B
JavaScript
import ts from 'typescript';
import { errorLog } from '../logger.js';
const formatDiagnosticsHost = {
getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => ts.sys.newLine,
};
export function checkProgramDiagnosticsErrors(program) {
if (!program.getCompilerOptions().declaration) {
throw new Error(`Something went wrong - the program doesn't have declaration option enabled`);
}
checkDiagnosticsErrors(ts.getPreEmitDiagnostics(program), 'Compiled with errors');
}
export function checkDiagnosticsErrors(diagnostics, failMessage) {
if (diagnostics.length === 0) {
return;
}
errorLog(ts.formatDiagnostics(diagnostics, formatDiagnosticsHost).trim());
throw new Error(failMessage);
}