<commit_before>import webpack from 'webpack';
import promiseWrap from '../util/promiseWrap';
import generateWebpackConfig from '../generateWebpackConfig';

function runWebpack(environment) {
  const config = generateWebpackConfig(environment);
  const compiler = webpack(config);

  return promiseWrap(compiler.run.bind(compiler))();
}

export default async function build(options={}) {
  const environment = options.optimize ? 'production' : 'development';

  const stats = await runWebpack(environment);

  const jsonStats = stats.toJson();

  if (jsonStats.errors.length > 0) {
    console.log('*** Webpack errors:');

    jsonStats.errors.map((err) => {
      console.log(err);
      console.log('');
    });
  }

  if (jsonStats.warnings.length > 0) {
    console.log('*** Webpack warnings:');

    jsonStats.warnings.map((err) => {
      console.log(err);
      console.log('');
    });
  }
}<commit_msg>build cmd: Exit with non-zero code on webpack build failure<commit_after>import webpack from 'webpack';
import promiseWrap from '../util/promiseWrap';
import generateWebpackConfig from '../generateWebpackConfig';

function runWebpack(environment) {
  const config = generateWebpackConfig(environment);
  const compiler = webpack(config);

  return promiseWrap(compiler.run.bind(compiler))();
}

export default async function build(options={}) {
  const environment = options.optimize ? 'production' : 'development';

  const stats = await runWebpack(environment);

  const jsonStats = stats.toJson();

  if (jsonStats.errors.length > 0) {
    console.log('*** Webpack errors:');

    jsonStats.errors.map((err) => {
      console.log(err);
      console.log('');
    });
  }

  if (jsonStats.warnings.length > 0) {
    console.log('*** Webpack warnings:');

    jsonStats.warnings.map((err) => {
      console.log(err);
      console.log('');
    });
  }

  if (jsonStats.errors.length > 0) {
    process.exit(1);
  }
}
{'fraction_non_alphanumeric': 0.15292897874546396, 'fraction_numerical': 0.003110419906687403, 'mean_word_length': 3.923469387755102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '474437', 'n_tokens_mistral': 592, 'n_tokens_neox': 567, 'n_words': 127}