mirror of
https://github.com/FormidableLabs/webpack-dashboard.git
synced 2025-12-08 18:22:10 +00:00
79 lines
2.1 KiB
JavaScript
79 lines
2.1 KiB
JavaScript
/* eslint-disable */
|
|
"use strict";
|
|
|
|
var friendlySyntaxErrorLabel = 'Syntax error:';
|
|
|
|
function isLikelyASyntaxError(message) {
|
|
return message.indexOf(friendlySyntaxErrorLabel) !== -1;
|
|
}
|
|
|
|
function formatMessage(message) {
|
|
return message
|
|
.replace(
|
|
'Module build failed: SyntaxError:',
|
|
friendlySyntaxErrorLabel
|
|
)
|
|
.replace(
|
|
/Module not found: Error: Cannot resolve 'file' or 'directory'/,
|
|
'Module not found:'
|
|
)
|
|
.replace(/^\s*at\s.*:\d+:\d+[\s\)]*\n/gm, '')
|
|
.replace('./~/css-loader!./~/postcss-loader!', '');
|
|
}
|
|
|
|
function lineJoin(arr) {
|
|
var joined = arr.join('\n');
|
|
return joined;
|
|
};
|
|
|
|
function formatOutput(stats) {
|
|
var output = [];
|
|
var hasErrors = stats.hasErrors();
|
|
var hasWarnings = stats.hasWarnings();
|
|
if (!hasErrors && !hasWarnings) {
|
|
output.push('{green-fg}Compiled successfully!{/}');
|
|
output.push('');
|
|
|
|
return lineJoin(output);
|
|
}
|
|
|
|
var json = stats.toJson();
|
|
var formattedErrors = json.errors.map(function(message) {
|
|
return 'Error in ' + formatMessage(message);
|
|
});
|
|
var formattedWarnings = json.warnings.map(function(message) {
|
|
return 'Warning in ' + formatMessage(message);
|
|
});
|
|
|
|
if (hasErrors) {
|
|
output.push('{red-fg}Failed to compile.{/}');
|
|
output.push('');
|
|
if (formattedErrors.some(isLikelyASyntaxError)) {
|
|
formattedErrors = formattedErrors.filter(isLikelyASyntaxError);
|
|
}
|
|
formattedErrors.forEach(function(message) {
|
|
output.push(message);
|
|
output.push('');
|
|
});
|
|
return lineJoin(output);
|
|
}
|
|
|
|
if (hasWarnings) {
|
|
output.push('{yellow-fg}Compiled with warnings.{/yellow-fg}');
|
|
output.push('');
|
|
formattedWarnings.forEach(function(message) {
|
|
output.push(message);
|
|
output.push('');
|
|
});
|
|
|
|
output.push('You may use special comments to disable some warnings.');
|
|
output.push('Use {yellow-fg}// eslint-disable-next-line {/yellow-fg} to ignore the next line.');
|
|
output.push('Use {yellow-fg}/* eslint-disable */{/yellow-fg} to ignore all warnings in a file.');
|
|
|
|
return lineJoin(output);
|
|
}
|
|
};
|
|
|
|
module.exports = formatOutput;
|
|
|