Skip to content

Commit

Permalink
use react-dev-utils to format errors
Browse files Browse the repository at this point in the history
  • Loading branch information
robmcguinness committed May 16, 2017
1 parent 2df9b9f commit d20bba0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
1 change: 1 addition & 0 deletions packages/availity-workflow/package.json
Expand Up @@ -49,6 +49,7 @@
"opn": "5.0.0",
"ora": "^1.2.0",
"pretty-ms": "^2.1.0",
"react-dev-utils": "0.5.2",
"require-relative": "^0.8.7",
"semver": "^5.3.0",
"shelljs": "^0.7.7",
Expand Down
36 changes: 4 additions & 32 deletions packages/availity-workflow/scripts/start.js
Expand Up @@ -10,6 +10,7 @@ const Promise = require('bluebird');
const settings = require('availity-workflow-settings');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const WebpackDevSever = require('webpack-dev-server');
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');

const proxy = require('./proxy');
const notifier = require('./notifier');
Expand All @@ -23,29 +24,6 @@ Promise.config({
longStackTraces: true
});

const 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:'
)
// Internal stacks are generally useless so we strip them
.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s\)]*(\n|$)/gm, '') // at ... ...:x:y
// Webpack loader names obscure CSS filenames
.replace('./~/css-loader!./~/postcss-loader!', '')
.replace(/\s@ multi .+/, '');
}

const startupMessage = once(() => {
const uri = `http://${settings.config().development.host}:${settings.config().development.port}/`;
Logger.box(`The app is running at ${chalk.green(uri)}`);
Expand Down Expand Up @@ -179,17 +157,11 @@ function web() {
chunks: false,
chunkModules: false,
errorDetails: false
});

let formattedErrors = json.errors.map(msg => {
return 'Error in ' + formatMessage(msg);
});
}, true);

if (formattedErrors.some(isLikelyASyntaxError)) {
formattedErrors = formattedErrors.filter(isLikelyASyntaxError);
}
const messages = formatWebpackMessages(json);

formattedErrors.forEach(error => {
messages.errors.forEach(error => {
Logger.empty();
Logger.simple(`${chalk.red(error)}`);
Logger.empty();
Expand Down

0 comments on commit d20bba0

Please sign in to comment.