UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

42 lines (38 loc) 1.38 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function getTSErrorFiles(options) { var _a, _b; var command = (_a = options === null || options === void 0 ? void 0 : options.command) !== null && _a !== void 0 ? _a : 'npx tsc --noEmit --pretty false --listEmittedFiles false || true'; var root = (_b = options === null || options === void 0 ? void 0 : options.root) !== null && _b !== void 0 ? _b : process.cwd(); // eslint-disable-next-line @typescript-eslint/no-require-imports var execSync = require('child_process').execSync; var res = execSync(command, { cwd: root, encoding: 'utf-8', stdio: 'pipe' }); var result = parseTypeScriptErrors(res); console.log('[getTSErrorFiles]', result); return result; } function parseTypeScriptErrors(errorString) { var errorLines = errorString.split('\n'); var errors = []; for (var _i = 0, errorLines_1 = errorLines; _i < errorLines_1.length; _i++) { var line = errorLines_1[_i]; var fileMatch = line.match(/^(.*?)\((\d+),(\d+)\):\s*error\s*(TS\d+):\s*(.*)$/); if (!fileMatch) { continue; } var result = { file: fileMatch[1], line: +fileMatch[2], column: +fileMatch[3], code: fileMatch[4], message: fileMatch[5] }; errors.push(result); } return errors; } exports.getTSErrorFiles = getTSErrorFiles;