-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
37 lines (34 loc) · 958 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module.exports = () => {
return {
postcssPlugin: 'postcss-fail-on-warn',
OnceExit(css, { result, CssSyntaxError }) {
let [first, ...rest] = result.warnings()
if (!first) return
function format(warning) {
if (warning.line) {
let input = (warning.node && warning.node.input) || {}
let formatter = new CssSyntaxError(
warning.text,
warning.line,
warning.column,
input.css,
input.file,
warning.plugin
)
return formatter.toString().replace(/^CssSyntaxError: /, '')
} else if (warning.plugin) {
return warning.plugin + ': ' + warning.text
} else {
return warning.text
}
}
if (rest) {
for (let warning of rest) {
console.warn(format(warning))
}
}
throw new Error(format(first))
}
}
}
module.exports.postcss = true