Upgrade Ava to v4
This commit is contained in:
parent
9a40cc5274
commit
ce89f1b611
1153 changed files with 27264 additions and 95308 deletions
29
node_modules/ava/lib/code-excerpt.js
generated
vendored
29
node_modules/ava/lib/code-excerpt.js
generated
vendored
|
|
@ -1,14 +1,14 @@
|
|||
'use strict';
|
||||
const fs = require('fs');
|
||||
const equalLength = require('equal-length');
|
||||
const codeExcerpt = require('code-excerpt');
|
||||
const truncate = require('cli-truncate');
|
||||
const chalk = require('./chalk').get();
|
||||
import fs from 'node:fs';
|
||||
|
||||
import truncate from 'cli-truncate';
|
||||
import codeExcerpt from 'code-excerpt';
|
||||
|
||||
import {chalk} from './chalk.js';
|
||||
|
||||
const formatLineNumber = (lineNumber, maxLineNumber) =>
|
||||
' '.repeat(Math.max(0, String(maxLineNumber).length - String(lineNumber).length)) + lineNumber;
|
||||
|
||||
module.exports = (source, options = {}) => {
|
||||
export default function exceptCode(source, options = {}) {
|
||||
if (!source.isWithinProject || source.isDependency) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ module.exports = (source, options = {}) => {
|
|||
|
||||
let contents;
|
||||
try {
|
||||
contents = fs.readFileSync(file, 'utf8');
|
||||
contents = fs.readFileSync(new URL(file), 'utf8');
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -30,25 +30,20 @@ module.exports = (source, options = {}) => {
|
|||
|
||||
const lines = excerpt.map(item => ({
|
||||
line: item.line,
|
||||
value: truncate(item.value, maxWidth - String(line).length - 5)
|
||||
value: truncate(item.value, maxWidth - String(line).length - 5),
|
||||
}));
|
||||
|
||||
const joinedLines = lines.map(line => line.value).join('\n');
|
||||
const extendedLines = equalLength(joinedLines).split('\n');
|
||||
const extendedWidth = Math.max(...lines.map(item => item.value.length));
|
||||
|
||||
return lines
|
||||
.map((item, index) => ({
|
||||
line: item.line,
|
||||
value: extendedLines[index]
|
||||
}))
|
||||
.map(item => {
|
||||
const isErrorSource = item.line === line;
|
||||
|
||||
const lineNumber = formatLineNumber(item.line, line) + ':';
|
||||
const coloredLineNumber = isErrorSource ? lineNumber : chalk.grey(lineNumber);
|
||||
const result = ` ${coloredLineNumber} ${item.value}`;
|
||||
const result = ` ${coloredLineNumber} ${item.value.padEnd(extendedWidth)}`;
|
||||
|
||||
return isErrorSource ? chalk.bgRed(result) : result;
|
||||
})
|
||||
.join('\n');
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue