Module: @ima/dev-utils
Classes
Interfaces
Type Aliases
ParsedErrorData
Ƭ ParsedErrorData: Object
Type declaration
Name | Type |
---|---|
column? | number |
fileUri? | string |
functionName? | string |
line? | number |
message? | string |
name? | string |
stack? | string |
Defined in
packages/dev-utils/src/cliUtils.ts:13
Variables
COMPILE_ERROR_NEEDLES_RE
• Const
COMPILE_ERROR_NEEDLES_RE: RegExp
[]
Defined in
packages/dev-utils/src/compileErrorParser/index.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
packages/dev-utils/src/helpers.ts:10
RE_VALID_FRAME_CHROME
• Const
RE_VALID_FRAME_CHROME: RegExp
Defined in
packages/dev-utils/src/helpers.ts:2
RE_VALID_FRAME_FIREFOX
• Const
RE_VALID_FRAME_FIREFOX: RegExp
Defined in
packages/dev-utils/src/helpers.ts:3
logger
• Const
logger: Logger
Create global logger instance
Defined in
packages/dev-utils/src/logger.ts:172
Functions
createLogger
▸ createLogger(name
): Logger
Parameters
Name | Type |
---|---|
name | string |
Returns
Defined in
packages/dev-utils/src/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
Name | Type | Default value | Description |
---|---|---|---|
line | number | undefined | Source code line number, around which you want to created source fragment. |
source | string | undefined | Source file's source code. |
contextLines? | number | 4 | Number of lines to generate, below and after watched line. |
Returns
Array of source code lines.
Defined in
packages/dev-utils/src/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
Name | Type | Description |
---|---|---|
fileUri | string | The uri of the source file. |
fileContents | string | Source file file contents. |
Returns
string
| null
Defined in
packages/dev-utils/src/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
Name | Type | Description |
---|---|---|
parsedErrorData | ParsedErrorData | Parsed error data object obtained from parseError function (or provided directly). |
rootDir? | string | Optional 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
packages/dev-utils/src/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
Name | Type | Default value | Description |
---|---|---|---|
fileUri? | string | undefined | source file uri. |
line? | number | undefined | errored line number. |
column | number | 0 | errored column number. |
Returns
Promise
<string
[] | undefined
>
Formatted error lines.
Defined in
packages/dev-utils/src/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
Name | Type | Description |
---|---|---|
error | StatsError | Error | webpack stats object or error instance. |
Returns
CompileError
| null
Parsed compile error.
Defined in
packages/dev-utils/src/compileErrorParser/index.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
Name | Type | Description |
---|---|---|
error | StatsError | Error | - |
type? | "compile" | "runtime" | Error type (affects error parsing). |
Returns
Promise
<ParsedErrorData
>
Formatted error output.
Defined in
packages/dev-utils/src/cliUtils.ts:124
printTime
▸ printTime(): string
Prints current time in HH:MM:SS format.
Returns
string
Defined in
packages/dev-utils/src/logger.ts:26
resolveErrorType
▸ resolveErrorType(error
): "compile"
| "runtime"
Parameters
Name | Type |
---|---|
error | StatsError | Error |
Returns
"compile"
| "runtime"
Defined in
packages/dev-utils/src/compileErrorParser/index.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