Skip to content

Commit 6d1c55c

Browse files
committed
Show "The app is running at..." even if there are warnings (facebook#440)
1 parent 318c803 commit 6d1c55c

File tree

1 file changed

+45
-42
lines changed

1 file changed

+45
-42
lines changed

scripts/start.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,51 @@ function setupCompiler(port) {
9494
var hasWarnings = stats.hasWarnings();
9595
if (!hasErrors && !hasWarnings) {
9696
console.log(chalk.green('Compiled successfully!'));
97+
}
98+
else {
99+
// We have switched off the default Webpack output in WebpackDevServer
100+
// options so we are going to "massage" the warnings and errors and present
101+
// them in a readable focused way.
102+
// We use stats.toJson({}, true) to make output more compact and readable:
103+
// https://github.com/facebookincubator/create-react-app/issues/401#issuecomment-238291901
104+
var json = stats.toJson({}, true);
105+
var formattedErrors = json.errors.map(message =>
106+
'Error in ' + formatMessage(message)
107+
);
108+
var formattedWarnings = json.warnings.map(message =>
109+
'Warning in ' + formatMessage(message)
110+
);
111+
if (hasErrors) {
112+
console.log(chalk.red('Failed to compile.'));
113+
console.log();
114+
if (formattedErrors.some(isLikelyASyntaxError)) {
115+
// If there are any syntax errors, show just them.
116+
// This prevents a confusing ESLint parsing error
117+
// preceding a much more useful Babel syntax error.
118+
formattedErrors = formattedErrors.filter(isLikelyASyntaxError);
119+
}
120+
formattedErrors.forEach(message => {
121+
console.log(message);
122+
console.log();
123+
});
124+
// If errors exist, ignore warnings.
125+
return;
126+
}
127+
if (hasWarnings) {
128+
console.log(chalk.yellow('Compiled with warnings.'));
129+
console.log();
130+
formattedWarnings.forEach(message => {
131+
console.log(message);
132+
console.log();
133+
});
134+
// Teach some ESLint tricks.
135+
console.log('You may use special comments to disable some warnings.');
136+
console.log('Use ' + chalk.yellow('// eslint-disable-next-line') + ' to ignore the next line.');
137+
console.log('Use ' + chalk.yellow('/* eslint-disable */') + ' to ignore all warnings in a file.');
138+
}
139+
}
140+
141+
if (!hasErrors) {
97142
console.log();
98143
console.log('The app is running at:');
99144
console.log();
@@ -102,48 +147,6 @@ function setupCompiler(port) {
102147
console.log('Note that the development build is not optimized.');
103148
console.log('To create a production build, use ' + chalk.cyan('npm run build') + '.');
104149
console.log();
105-
return;
106-
}
107-
108-
// We have switched off the default Webpack output in WebpackDevServer
109-
// options so we are going to "massage" the warnings and errors and present
110-
// them in a readable focused way.
111-
// We use stats.toJson({}, true) to make output more compact and readable:
112-
// https://github.com/facebookincubator/create-react-app/issues/401#issuecomment-238291901
113-
var json = stats.toJson({}, true);
114-
var formattedErrors = json.errors.map(message =>
115-
'Error in ' + formatMessage(message)
116-
);
117-
var formattedWarnings = json.warnings.map(message =>
118-
'Warning in ' + formatMessage(message)
119-
);
120-
if (hasErrors) {
121-
console.log(chalk.red('Failed to compile.'));
122-
console.log();
123-
if (formattedErrors.some(isLikelyASyntaxError)) {
124-
// If there are any syntax errors, show just them.
125-
// This prevents a confusing ESLint parsing error
126-
// preceding a much more useful Babel syntax error.
127-
formattedErrors = formattedErrors.filter(isLikelyASyntaxError);
128-
}
129-
formattedErrors.forEach(message => {
130-
console.log(message);
131-
console.log();
132-
});
133-
// If errors exist, ignore warnings.
134-
return;
135-
}
136-
if (hasWarnings) {
137-
console.log(chalk.yellow('Compiled with warnings.'));
138-
console.log();
139-
formattedWarnings.forEach(message => {
140-
console.log(message);
141-
console.log();
142-
});
143-
// Teach some ESLint tricks.
144-
console.log('You may use special comments to disable some warnings.');
145-
console.log('Use ' + chalk.yellow('// eslint-disable-next-line') + ' to ignore the next line.');
146-
console.log('Use ' + chalk.yellow('/* eslint-disable */') + ' to ignore all warnings in a file.');
147150
}
148151
});
149152
}

0 commit comments

Comments
 (0)