Son CV dans un terminal web en Javascript! https://terminal-cv.gregandev.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
terminal-cv/node_modules/@parcel/utils/lib/prettyDiagnostic.js

139 lines
3.3 KiB

1 year ago
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = prettyDiagnostic;
function _codeframe() {
const data = _interopRequireDefault(require("@parcel/codeframe"));
_codeframe = function () {
return data;
};
return data;
}
function _markdownAnsi() {
const data = _interopRequireDefault(require("@parcel/markdown-ansi"));
_markdownAnsi = function () {
return data;
};
return data;
}
function _chalk() {
const data = _interopRequireDefault(require("chalk"));
_chalk = function () {
return data;
};
return data;
}
function _path() {
const data = _interopRequireDefault(require("path"));
_path = function () {
return data;
};
return data;
}
function _nullthrows() {
const data = _interopRequireDefault(require("nullthrows"));
_nullthrows = function () {
return data;
};
return data;
}
function _terminalLink() {
const data = _interopRequireDefault(require("terminal-link"));
_terminalLink = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// $FlowFixMe
async function prettyDiagnostic(diagnostic, options, terminalWidth) {
let {
origin,
message,
stack,
codeFrames,
hints,
skipFormatting,
documentationURL
} = diagnostic;
let result = {
message: (0, _markdownAnsi().default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi().default)(message)),
stack: '',
codeframe: '',
hints: [],
documentation: ''
};
if (codeFrames != null) {
for (let codeFrame of codeFrames) {
var _codeFrame$code;
let filePath = codeFrame.filePath;
if (filePath != null && options && !_path().default.isAbsolute(filePath)) {
filePath = _path().default.join(options.projectRoot, filePath);
}
let highlights = codeFrame.codeHighlights;
let code = (_codeFrame$code = codeFrame.code) !== null && _codeFrame$code !== void 0 ? _codeFrame$code : options && (await options.inputFS.readFile((0, _nullthrows().default)(filePath), 'utf8'));
let formattedCodeFrame = '';
if (code != null) {
formattedCodeFrame = (0, _codeframe().default)(code, highlights, {
useColor: true,
syntaxHighlighting: true,
language: // $FlowFixMe sketchy null checks do not matter here...
codeFrame.language || (filePath != null ? _path().default.extname(filePath).substr(1) : undefined),
terminalWidth
});
}
result.codeframe += typeof filePath !== 'string' ? '' : _chalk().default.gray.underline(`${filePath}:${highlights[0].start.line}:${highlights[0].start.column}\n`);
result.codeframe += formattedCodeFrame;
if (codeFrame !== codeFrames[codeFrames.length - 1]) {
result.codeframe += '\n\n';
}
}
}
if (stack != null) {
result.stack = stack;
}
if (Array.isArray(hints) && hints.length) {
result.hints = hints.map(h => {
return (0, _markdownAnsi().default)(h);
});
}
if (documentationURL != null) {
result.documentation = (0, _terminalLink().default)('Learn more', documentationURL, {
fallback: (text, url) => `${text}: ${url}`
});
}
return result;
}