@ima/dev-utils
Version:
IMA.js dev utils used used mainly in @ima/cli and other dev-related utilities.
54 lines (53 loc) • 2.44 kB
TypeScript
import { StatsError } from 'webpack';
export type ParsedErrorData = {
fileUri?: string;
line?: number;
column?: number;
name?: string;
message?: string;
stack?: string;
functionName?: string;
};
/**
* Get source fragment from provided source metadata.
* Optionally it tries to parse original content if
* source maps are available.
*
* @param {string?} fileUri source file uri.
* @param {number?} line errored line number.
* @param {number?} column errored column number.
* @returns {Promise<string[]>} Formatted error lines.
*/
export declare function getSource(fileUri?: string, line?: number, column?: number): Promise<string[] | undefined>;
/**
* Formats provided error object into readable format including
* the errored source code fragment with line highlight. Works
* with runtime and compile errors while trying to show all
* relevant information that can be extracted from provided object.
*
* @param {Error|StatsError} Error object to format.
* @param {string?} type Error type (affects error parsing).
* @param {string?} rootDir Optional root directory used to print
* absolute URLs as relative to the current rootDir.
* @param {string[]?} uniqueTracker Array of error identifiers to
* track uniques, if the error matches identifier already included
* in this array, this function returns empty string.
* @returns {Promise<string>} Formatted error output.
*/
export declare function parseError(error: Error | StatsError, type?: 'compile' | 'runtime'): Promise<ParsedErrorData>;
/**
* Formats provided error object into readable format including
* the errored source code fragment with line highlight. Works
* with runtime and compile errors while trying to show all
* relevant information that can be extracted from provided object.
*
* @param {ParsedErrorData} parsedErrorData Parsed error data object
* obtained from parseError function (or provided directly).
* @param {string?} rootDir Optional root directory used to print
* absolute URLs as relative to the current rootDir.
* @param {string[]?} uniqueTracker Array of error identifiers to
* track uniques, if the error matches identifier already included
* in this array, this function returns empty string.
* @returns {Promise<string>} Formatted error output.
*/
export declare function formatError(parsedErrorData: ParsedErrorData, rootDir?: string, uniqueTracker?: string[]): Promise<string>;