-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (58 loc) · 1.62 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var checkCSS = require('airtight-css-lint');
var loaderUtils = require('loader-utils');
var assign = require("object-assign");
var sourceMap = require('source-map');
function checkCSSLoader(source, options, webpack, map, callback) {
var results = [];
checkCSS(source, function (line, col, msg) {
var message = 'Line ' + line + ':' + col + ' - ' + msg;
if (map) {
var smc = new sourceMap.SourceMapConsumer(map);
var originalPos = smc.originalPositionFor({
line: line,
column: col
});
message = originalPos.source + ':' + originalPos.line + ':' + originalPos.column + ' - ' + msg;
}
results.push([message]);
});
if (results.length) {
for (var i = 0; i < results.length; i++){
if (options.failTypeError) {
webpack.emitError(results[i]);
} else {
webpack.emitWarning(results[i]);
}
}
if (options.failTypeError && options.failOnError) {
throw new Error("Airtight CSS Lint Error");
}
}
if (callback) {
callback(null, source, map);
}
}
module.exports = function(source, map) {
var options = assign(
{
failTypeError: true, // Use warning if false
failOnError: true // Only applies to errors
},
loaderUtils.parseQuery(this.query)
);
if (map !== null && typeof map !== "string") {
map = JSON.stringify(map);
}
this.cacheable();
var callback = this.async();
if (!callback) {
checkCSSLoader(source, options, this, map);
return source;
} else {
try {
checkCSSLoader(source, options, this, map, callback);
} catch(e) {
callback(e);
}
}
}