src/format-webpack-stats-errors-warnings.js
function _resolveLineColNumInFile(file, message, options={}){
    if (!message){
        return {line: 0, col: 0}
    }

    let fileContent = fs.readFileSync(file, 'utf8')

    let beyondPos = 0

    switch (typeof options.after){
        case 'string':
            beyondPos = fileContent.indexOf(options.after)
            break
        case 'number':
            beyondPos = options.after
            break
        default:
            break
    }

    let pos = fileContent.indexOf(message, beyondPos >= 0 ? beyondPos : 0)
    if (pos <= 0){
        return {line: 0, col: 0}
    }

    let lineNum = 1
    let linePos = 0
    for (let i = 0; i < pos; i++){
        if (fileContent.charCodeAt(i) === 10){ // 10: "\n"
            lineNum++
            linePos = i
        }
    }
    
    return {line: lineNum, col: pos - linePos, endCol: pos - linePos + message.length}
}
function _resolveLineColNumInFile(file, message, options={}){
    if (!message){
        return {line: 0, col: 0}
    }

    let fileContent = fs.readFileSync(file, 'utf8')

    let beyondPos = 0

    switch (typeof options.after){
        case 'string':
            beyondPos = fileContent.indexOf(options.after)
            break
        case 'number':
            beyondPos = options.after
            break
        default:
            break
    }

    let pos = fileContent.indexOf(message, beyondPos >= 0 ? beyondPos : 0)
    if (pos <= 0){
        return {line: 0, col: 0}
    }

    let lineNum = 1
    let linePos = 0
    for (let i = 0; i < pos; i++){
        if (fileContent.charCodeAt(i) === 10){ // 10: "\n"
            lineNum++
            linePos = i
        }
    }
    
    return {line: lineNum, col: pos - linePos, endCol: pos - linePos + message.length}
}
function _resolveLineColNumInFile ( file , message , options = { } ) { if ( ! message ) { return { line : 0 , col : 0 } } let fileContent = fs . readFileSync ( file , 'utf8' ) let beyondPos = 0 switch ( typeof options . after ) { case 'string' : beyondPos = fileContent . indexOf ( options . after ) break case 'number' : beyondPos = options . after break default : break } let pos = fileContent . indexOf ( message , beyondPos >= 0 ? beyondPos : 0 ) if ( pos <= 0 ) { return { line : 0 , col : 0 } } let lineNum = 1 let linePos = 0 for ( let i = 0 ; i < pos ; i ++ ) { if ( fileContent . charCodeAt ( i ) === 10 ) { // 10: "\n" lineNum ++ linePos = i } } return { line : lineNum , col : pos - linePos , endCol : pos - linePos + message . length } }
Resolve the line num of a message in a file
Resolve the line num of a message in a file