rsnext/packages/next/build/webpack/plugins/wellknown-errors-plugin/parseCss.ts
hiro a00268e70f
Fix typos (#35683)
* fix(typo): wolrd -> world

* fix(typo): _lineNumer -> _lineNumber

* fix(typo): Dyanmic -> Dynamic

* fix(typo): mutliple -> multiple

* fix(typo): dyanmic -> dynamic

* fix(typo): speical -> special

* fix(typo): acceptible -> acceptable

* fix(typo): dyanmic -> dynamic

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): accesible -> accessible

* fix(typo): explicitely -> explicitly
2022-03-28 22:53:51 -05:00

39 lines
1.1 KiB
TypeScript

import Chalk from 'next/dist/compiled/chalk'
import { SimpleWebpackError } from './simpleWebpackError'
const chalk = new Chalk.constructor({ enabled: true })
const regexCssError =
/^(?:CssSyntaxError|SyntaxError)\n\n\((\d+):(\d*)\) (.*)$/s
export function getCssError(
fileName: string,
err: Error
): SimpleWebpackError | false {
if (
!(
(err.name === 'CssSyntaxError' || err.name === 'SyntaxError') &&
(err as any).stack === false &&
!(err instanceof SyntaxError)
)
) {
return false
}
// https://github.com/postcss/postcss-loader/blob/d6931da177ac79707bd758436e476036a55e4f59/src/Error.js
const res = regexCssError.exec(err.message)
if (res) {
const [, _lineNumber, _column, reason] = res
const lineNumber = Math.max(1, parseInt(_lineNumber, 10))
const column = Math.max(1, parseInt(_column, 10))
return new SimpleWebpackError(
`${chalk.cyan(fileName)}:${chalk.yellow(
lineNumber.toString()
)}:${chalk.yellow(column.toString())}`,
chalk.red.bold('Syntax error').concat(`: ${reason}`)
)
}
return false
}