Skip to content
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Commit 4d66ccc

Browse files
Lyrkanchristophehurpeau
authored andcommitted
Retrieve errors/warnings from compilation.children if needed (#93)
1 parent 273ca3b commit 4d66ccc

File tree

11 files changed

+303
-4
lines changed

11 files changed

+303
-4
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"webpack": "^4.0.0"
3333
},
3434
"devDependencies": {
35+
"autoprefixer": "^9.6.0",
3536
"babel-core": "^6.23.1",
3637
"babel-eslint": "^10.0.1",
3738
"babel-loader": "^7.1.4",
@@ -46,6 +47,7 @@
4647
"memory-fs": "^0.4.1",
4748
"mini-css-extract-plugin": "^0.6.0",
4849
"node-sass": "^4.12.0",
50+
"postcss-loader": "^3.0.0",
4951
"sass": "^1.20.1",
5052
"sass-loader": "^7.1.0",
5153
"style-loader": "^0.23.1",

src/friendly-errors-plugin.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,19 @@ function extractErrorsFromStats(stats, type) {
142142
// compilers depend on the same module.
143143
return uniqueBy(errors, error => error.message);
144144
}
145-
return stats.compilation[type];
145+
146+
const findErrorsRecursive = (compilation) => {
147+
const errors = compilation[type];
148+
if (errors.length === 0 && compilation.children) {
149+
for (const child of compilation.children) {
150+
errors.push(...findErrorsRecursive(child));
151+
}
152+
}
153+
154+
return uniqueBy(errors, error => error.message);
155+
};
156+
157+
return findErrorsRecursive(stats.compilation);
146158
}
147159

148160
function isMultiStats(stats) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
display: grid;
3+
grid-gap: 1px;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
display: grid;
3+
grid-auto-flow: row;
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
plugins: {
3+
autoprefixer: {
4+
grid: true,
5+
}
6+
}
7+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// postcss-loader warnings test (multi-compiler version)
2+
const FriendlyErrorsWebpackPlugin = require('../../../index');
3+
4+
const COMMON_CONFIG = {
5+
mode: 'production',
6+
output: {
7+
path: __dirname + '/dist',
8+
},
9+
plugins: [
10+
new FriendlyErrorsWebpackPlugin(),
11+
],
12+
module: {
13+
rules: [
14+
{
15+
test: /\.css$/,
16+
exclude: /node_modules/,
17+
use: [
18+
{
19+
loader: 'css-loader',
20+
options: {
21+
importLoaders: 1,
22+
},
23+
},
24+
{
25+
loader: 'postcss-loader',
26+
options: {
27+
config: {
28+
path: __dirname + '/postcss.config.js'
29+
}
30+
},
31+
},
32+
],
33+
}
34+
]
35+
},
36+
};
37+
38+
module.exports = [
39+
Object.assign({}, { entry: __dirname + '/index.css' }, COMMON_CONFIG),
40+
Object.assign({}, { entry: __dirname + '/index2.css' }, COMMON_CONFIG),
41+
];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
display: grid;
3+
grid-gap: 1px;
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
plugins: {
3+
autoprefixer: {
4+
grid: true,
5+
}
6+
}
7+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// postcss-loader warnings test
2+
const FriendlyErrorsWebpackPlugin = require('../../../index');
3+
4+
module.exports = {
5+
mode: 'production',
6+
entry: __dirname + '/index.css',
7+
output: {
8+
path: __dirname + '/dist',
9+
},
10+
plugins: [
11+
new FriendlyErrorsWebpackPlugin(),
12+
],
13+
module: {
14+
rules: [
15+
{
16+
test: /\.css$/,
17+
exclude: /node_modules/,
18+
use: [
19+
{
20+
loader: 'css-loader',
21+
options: {
22+
importLoaders: 1,
23+
},
24+
},
25+
{
26+
loader: 'postcss-loader',
27+
options: {
28+
config: {
29+
path: __dirname + '/postcss.config.js'
30+
}
31+
},
32+
},
33+
],
34+
}
35+
]
36+
},
37+
};

test/integration.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,44 @@ it('integration : webpack multi compiler : module-errors', async() => {
161161
'* ./non-existing in ./test/fixtures/multi-compiler-module-errors/index.js',
162162
]);
163163
});
164+
165+
it('integration : postcss-loader : warnings', async() => {
166+
167+
const logs = await executeAndGetLogs('./fixtures/postcss-warnings/webpack.config');
168+
expect(logs).toEqual([
169+
'WARNING Compiled with 1 warnings',
170+
'',
171+
'warning in ./test/fixtures/postcss-warnings/index.css',
172+
'',
173+
`Module Warning (from ./node_modules/postcss-loader/src/index.js):
174+
Warning
175+
176+
(3:2) grid-gap only works if grid-template(-areas) is being used`,
177+
''
178+
]);
179+
});
180+
181+
it('integration : postcss-loader : warnings (multi-compiler version)', async() => {
182+
183+
const logs = await executeAndGetLogs('./fixtures/multi-postcss-warnings/webpack.config');
184+
expect(logs).toEqual([
185+
'WARNING Compiled with 1 warnings',
186+
'',
187+
'warning in ./test/fixtures/multi-postcss-warnings/index.css',
188+
'',
189+
`Module Warning (from ./node_modules/postcss-loader/src/index.js):
190+
Warning
191+
192+
(3:2) grid-gap only works if grid-template(-areas) is being used`,
193+
'',
194+
'WARNING Compiled with 1 warnings',
195+
'',
196+
'warning in ./test/fixtures/multi-postcss-warnings/index2.css',
197+
'',
198+
`Module Warning (from ./node_modules/postcss-loader/src/index.js):
199+
Warning
200+
201+
(3:2) grid-auto-flow works only if grid-template-rows and grid-template-columns are present in the same rule`,
202+
''
203+
]);
204+
});

0 commit comments

Comments
 (0)