UNPKG

@ima/dev-utils

Version:

IMA.js dev utils used used mainly in @ima/cli and other dev-related utilities.

33 lines (32 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.webpackErrorParser = void 0; const stacktrace_parser_1 = require("stacktrace-parser"); const parserUtils_1 = require("./parserUtils"); /** * General webpack compile error parser which tries to parse all remaining * errors from error stack and stats params. */ function webpackErrorParser(error) { // Parse error message const compileError = { name: 'Webpack error', message: error.message.replace(/module not found: error:/gi, '').trim(), }; if (error.loc && error.moduleIdentifier) { // Extract error location from stats params. const { line, column } = (0, parserUtils_1.extractErrorLoc)(error.loc); const fileUri = (0, parserUtils_1.extractFileUri)(error.moduleIdentifier ?? ''); compileError.line = line; compileError.column = column; compileError.fileUri = fileUri; } else if (error.stack) { const parsedStack = (0, stacktrace_parser_1.parse)(error.stack); compileError.column = parsedStack[0].column || 1; compileError.fileUri = parsedStack[0].file || ''; compileError.line = parsedStack[0].lineNumber || 1; } return compileError; } exports.webpackErrorParser = webpackErrorParser;