This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
import { Formatter } from './Formatter';
declare function createBasicFormatter(): Formatter;
export { createBasicFormatter };

View File

@@ -0,0 +1,12 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
function createBasicFormatter() {
return function basicFormatter(issue) {
return chalk_1.default.grey(issue.code + ': ') + issue.message;
};
}
exports.createBasicFormatter = createBasicFormatter;

View File

@@ -0,0 +1,4 @@
import { Formatter } from './Formatter';
import { BabelCodeFrameOptions } from './types/babel__code-frame';
declare function createCodeFrameFormatter(options?: BabelCodeFrameOptions): Formatter;
export { createCodeFrameFormatter, BabelCodeFrameOptions };

View File

@@ -0,0 +1,28 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const os_1 = __importDefault(require("os"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const code_frame_1 = require("@babel/code-frame");
const BasicFormatter_1 = require("./BasicFormatter");
function createCodeFrameFormatter(options) {
const basicFormatter = BasicFormatter_1.createBasicFormatter();
return function codeFrameFormatter(issue) {
const source = issue.file && fs_extra_1.default.existsSync(issue.file) && fs_extra_1.default.readFileSync(issue.file, 'utf-8');
let frame = '';
if (source && issue.location) {
frame = code_frame_1.codeFrameColumns(source, issue.location, Object.assign({ highlightCode: true }, (options || {})))
.split('\n')
.map((line) => ' ' + line)
.join(os_1.default.EOL);
}
const lines = [basicFormatter(issue)];
if (frame) {
lines.push(frame);
}
return lines.join(os_1.default.EOL);
};
}
exports.createCodeFrameFormatter = createCodeFrameFormatter;

View File

@@ -0,0 +1,3 @@
import { Issue } from '../issue';
declare type Formatter = (issue: Issue) => string;
export { Formatter };

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,5 @@
import { FormatterOptions } from './FormatterOptions';
import { Formatter } from './Formatter';
declare type FormatterConfiguration = Formatter;
declare function createFormatterConfiguration(options: FormatterOptions | undefined): Formatter;
export { FormatterConfiguration, createFormatterConfiguration };

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FormatterFactory_1 = require("./FormatterFactory");
function createFormatterConfiguration(options) {
return FormatterFactory_1.createFormatter(options ? (typeof options === 'object' ? options.type || 'codeframe' : options) : 'codeframe', options && typeof options === 'object' ? options.options || {} : {});
}
exports.createFormatterConfiguration = createFormatterConfiguration;

View File

@@ -0,0 +1,13 @@
import { Formatter } from './Formatter';
import { BabelCodeFrameOptions } from './CodeFrameFormatter';
declare type NotConfigurableFormatterType = undefined | 'basic' | Formatter;
declare type ConfigurableFormatterType = 'codeframe';
declare type FormatterType = NotConfigurableFormatterType | ConfigurableFormatterType;
declare type ConfigurableFormatterOptions = {
codeframe: BabelCodeFrameOptions;
};
declare type ComplexFormatterOptions<T extends FormatterType> = T extends ConfigurableFormatterType ? ConfigurableFormatterOptions[T] : never;
declare function createFormatter<T extends NotConfigurableFormatterType>(type?: T): Formatter;
declare function createFormatter<T extends ConfigurableFormatterType>(type: T, options?: ConfigurableFormatterOptions[T]): Formatter;
declare function createFormatter<T extends FormatterType>(type: T, options?: object): Formatter;
export { createFormatter, FormatterType, ComplexFormatterOptions, NotConfigurableFormatterType, ConfigurableFormatterType, ConfigurableFormatterOptions, };

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const CodeFrameFormatter_1 = require("./CodeFrameFormatter");
const BasicFormatter_1 = require("./BasicFormatter");
// declare function implementation
function createFormatter(type, options) {
if (typeof type === 'function') {
return type;
}
if (typeof type === 'undefined' || type === 'basic') {
return BasicFormatter_1.createBasicFormatter();
}
if (type === 'codeframe') {
return CodeFrameFormatter_1.createCodeFrameFormatter(options);
}
throw new Error(`Unknown "${type}" formatter. Available types are: "basic", "codeframe" or a custom function.`);
}
exports.createFormatter = createFormatter;

View File

@@ -0,0 +1,7 @@
import { ComplexFormatterOptions, FormatterType } from './FormatterFactory';
declare type ComplexFormatterPreferences<T extends FormatterType = FormatterType> = {
type: T;
options?: ComplexFormatterOptions<T>;
};
declare type FormatterOptions = FormatterType | ComplexFormatterPreferences;
export { FormatterOptions };

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,3 @@
import { Formatter } from './Formatter';
declare function createWebpackFormatter(formatter: Formatter): Formatter;
export { createWebpackFormatter };

View File

@@ -0,0 +1,28 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const os_1 = __importDefault(require("os"));
const chalk_1 = __importDefault(require("chalk"));
const path_1 = __importDefault(require("path"));
const issue_1 = require("../issue");
const forwardSlash_1 = __importDefault(require("../utils/path/forwardSlash"));
function createWebpackFormatter(formatter) {
// mimics webpack error formatter
return function webpackFormatter(issue) {
const color = issue.severity === 'warning' ? chalk_1.default.yellow.bold : chalk_1.default.red.bold;
const severity = issue.severity.toUpperCase();
if (issue.file) {
let location = forwardSlash_1.default(path_1.default.relative(process.cwd(), issue.file));
if (issue.location) {
location += `:${issue_1.formatIssueLocation(issue.location)}`;
}
return [color(`${severity} in ${location}`), formatter(issue), ''].join(os_1.default.EOL);
}
else {
return [color(`${severity} in `) + formatter(issue), ''].join(os_1.default.EOL);
}
};
}
exports.createWebpackFormatter = createWebpackFormatter;

View File

@@ -0,0 +1,7 @@
export * from './Formatter';
export * from './BasicFormatter';
export * from './CodeFrameFormatter';
export * from './WebpackFormatter';
export * from './FormatterFactory';
export * from './FormatterOptions';
export * from './FormatterConfiguration';

View File

@@ -0,0 +1,10 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./BasicFormatter"));
__export(require("./CodeFrameFormatter"));
__export(require("./WebpackFormatter"));
__export(require("./FormatterFactory"));
__export(require("./FormatterConfiguration"));

View File

@@ -0,0 +1,21 @@
export interface BabelCodeFrameOptions {
/** Syntax highlight the code as JavaScript for terminals. default: false */
highlightCode?: boolean;
/** The number of lines to show above the error. default: 2 */
linesAbove?: number;
/** The number of lines to show below the error. default: 3 */
linesBelow?: number;
/**
* Forcibly syntax highlight the code as JavaScript (for non-terminals);
* overrides highlightCode.
* default: false
*/
forceColor?: boolean;
/**
* Pass in a string to be displayed inline (if possible) next to the
* highlighted location in the code. If it can't be positioned inline,
* it will be placed above the code frame.
* default: nothing
*/
message?: string;
}

View File

@@ -0,0 +1,7 @@
"use strict";
// Base on the type definitions for @babel/code-frame 7.0
// Project: https://github.com/babel/babel/tree/main/packages/babel-code-frame, https://babeljs.io
// Definitions by: Mohsen Azimi <https://github.com/mohsen1>
// Forbes Lindesay <https://github.com/ForbesLindesay>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Object.defineProperty(exports, "__esModule", { value: true });