Skip to content
Merged
Prev Previous commit
Next Next commit
Configure to fail CI on error or warning
  • Loading branch information
tharakawj committed Oct 3, 2017
commit fd248f7e4c795c0209741186d187d3b48366f7cd
26 changes: 17 additions & 9 deletions packages/react-error-overlay/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

const webpack = require('webpack');
const chalk = require('chalk');
const webpackConfig = require('./webpack.config.js');
Expand All @@ -18,27 +16,40 @@ const chokidar = require('chokidar');
const args = process.argv.slice(2);
const watchMode = args[0] === '--watch' || args[0] === '-w';

const isCI =
process.env.CI &&
(typeof process.env.CI !== 'string' ||
process.env.CI.toLowerCase() !== 'false');

function build(config, name, callback) {
console.log(chalk.cyan('Compiling ' + name));
webpack(config).run((error, stats) => {
if (error) {
console.log(chalk.red('Failed to compile.'));
console.log(error.message || error);
console.log();
return;
}

if (stats.compilation.errors.length) {
console.log(chalk.red('Failed to compile.'));
console.log(stats.toString({ all: false, errors: true }));
return;
}

if (stats.compilation.warnings.length) {
console.log(chalk.yellow('Compiled with warnings.'));
console.log(stats.toString({ all: false, warnings: true }));
}

// Fail the build if running in a CI server
if (
error ||
stats.compilation.errors.length ||
stats.compilation.warnings.length
) {
isCI && process.exit(1);
return;
}

console.log(
stats.toString({ colors: true, modules: false, version: false })
);
Expand All @@ -51,9 +62,7 @@ function build(config, name, callback) {
function runBuildSteps() {
build(iframeWebpackConfig, 'iframeScript.js', () => {
build(webpackConfig, 'index.js', () => {
console.log(chalk.bold.green('Compiled successfully!'));
console.log();
console.log();
console.log(chalk.bold.green('Compiled successfully!\n\n'));
});
});
}
Expand Down Expand Up @@ -83,7 +92,6 @@ function setupWatch() {

// Clean up lib folder
rimraf('lib/', () => {
console.log('Cleaned up the lib folder.');
console.log();
console.log('Cleaned up the lib folder.\n');
watchMode ? setupWatch() : runBuildSteps();
});
2 changes: 1 addition & 1 deletion packages/react-error-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"anser": "1.4.1",
"babel-code-frame": "6.22.0",
"babel-loader": "^7.1.2",
"babel-runtime": "6.26.0",
"html-entities": "1.2.1",
"object-assign": "^4.1.1",
Expand All @@ -47,6 +46,7 @@
"devDependencies": {
"babel-eslint": "7.2.3",
"babel-preset-react-app": "^3.0.3",
"babel-loader": "^7.1.2",
"chalk": "^2.1.0",
"chokidar": "^1.7.0",
"cross-env": "5.0.5",
Expand Down
2 changes: 0 additions & 2 deletions packages/react-error-overlay/src/utils/pollyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

if (typeof Promise === 'undefined') {
// Rejection tracking prevents a common issue where React gets into an
// inconsistent state due to an error, but it gets swallowed by a Promise,
Expand Down