Skip to main content

Module: @ima/dev-utils

Classes

Interfaces

Type Aliases

ParsedErrorData

Ƭ ParsedErrorData: Object

Type declaration

NameType
column?number
fileUri?string
functionName?string
line?number
message?string
name?string
stack?string

Defined in

cliUtils.ts:13

Variables

COMPILE_ERROR_NEEDLES_RE

Const COMPILE_ERROR_NEEDLES_RE: RegExp[]

Defined in

compileErrorParser.ts:11


RE_SOURCE_MAPPING_URL

Const RE_SOURCE_MAPPING_URL: RegExp

Used to extract source mapping url injected at the end of a file with generated source maps (in separate file).

Defined in

helpers.ts:10


RE_VALID_FRAME_CHROME

Const RE_VALID_FRAME_CHROME: RegExp

Defined in

helpers.ts:2


RE_VALID_FRAME_FIREFOX

Const RE_VALID_FRAME_FIREFOX: RegExp

Defined in

helpers.ts:3


logger

Const logger: Logger

Create global logger instance

Defined in

logger.ts:172

Functions

createLogger

createLogger(name): Logger

Parameters

NameType
namestring

Returns

Logger

Defined in

logger.ts:175


createSourceFragment

createSourceFragment(line, source, contextLines?): FragmentLine[]

Create fragment of code lines around input line (above and below), created created from provided source code.

Parameters

NameTypeDefault valueDescription
linenumberundefinedSource code line number, around which you want to created source fragment.
sourcestringundefinedSource file's source code.
contextLines?number4Number of lines to generate, below and after watched line.

Returns

FragmentLine[]

Array of source code lines.

Defined in

sourceFragment.ts:18


extractSourceMappingUrl

extractSourceMappingUrl(fileUri, fileContents): string | null

Extracts sourceMappingURL from the provided file contents. Based on https://github.com/facebook/create-react-app/blob/main/packages/react-error-overlay/src/utils/getSourceMap.js#L79.

Parameters

NameTypeDescription
fileUristringThe uri of the source file.
fileContentsstringSource file file contents.

Returns

string | null

Defined in

sourceMapUtils.ts:11


formatError

formatError(parsedErrorData, rootDir?, uniqueTracker?): Promise<string>

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.

Parameters

NameTypeDescription
parsedErrorDataParsedErrorDataParsed error data object obtained from parseError function (or provided directly).
rootDir?stringOptional root directory used to print absolute URLs as relative to the current rootDir.
uniqueTracker?string[]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.

Defined in

cliUtils.ts:178


getSource

getSource(fileUri?, line?, column?): Promise<string[] | undefined>

Get source fragment from provided source metadata. Optionally it tries to parse original content if source maps are available.

Parameters

NameTypeDefault valueDescription
fileUri?stringundefinedsource file uri.
line?numberundefinederrored line number.
columnnumber0errored column number.

Returns

Promise<string[] | undefined>

Formatted error lines.

Defined in

cliUtils.ts:33


parseCompileError

parseCompileError(error): CompileError | null

Tries to parse error location from an error. Which can be either webpack stats error or simple Error object.

Parameters

NameTypeDescription
errorStatsError | Errorwebpack stats object or error instance.

Returns

CompileError | null

Parsed compile error.

Defined in

compileErrorParser.ts:37


parseError

parseError(error, type?): 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.

Parameters

NameTypeDescription
errorStatsError | Error-
type?"compile" | "runtime"Error type (affects error parsing).

Returns

Promise<ParsedErrorData>

Formatted error output.

Defined in

cliUtils.ts:124


printTime

printTime(): string

Prints current time in HH:MM:SS format.

Returns

string

Defined in

logger.ts:26


resolveErrorType

resolveErrorType(error): "compile" | "runtime"

Parameters

NameType
errorStatsError | Error

Returns

"compile" | "runtime"

Defined in

compileErrorParser.ts:16


time

time(): () => string

Returns time utility function, which when called returns formatted elapsed time from it's creation.

Returns

fn

Callback to return formatted elapsed time.

▸ (): string

Returns

string

Defined in

logger.ts:16