{"size": 1143, "ext": "js", "max_stars_repo_path": "packages/react-scripts/scripts/utils/callUserConfig.js", "max_stars_repo_name": "onnovisser/create-react-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/react-scripts/scripts/utils/callUserConfig.js", "max_issues_repo_name": "onnovisser/create-react-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/react-scripts/scripts/utils/callUserConfig.js", "max_forks_repo_name": "onnovisser/create-react-app", "max_forks_repo_forks_event_min_datetime": "2018-11-16T11:00:37.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-16T11:00:37.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.847826087, "max_line_length": 135, "alphanum_fraction": 0.5721784777}
'use strict';

const paths = require('../../config/paths');
const fs = require('fs');
const webpack = require('webpack');

module.exports = async (config, env) => {
  if (!fs.existsSync(paths.configFile)) {
    if (process.env.CONFIG_FILE) {
      throw new Error(
        `react-scripts config could not be loaded!\nFile ${
          process.env.CONFIG_FILE
        } not found.`
      );
    }
    return;
  }

  const m = require(paths.configFile);
  const transformer = (m && m.default) || m;
  try {
    await transformer(config, env, getWebpackHelpers(config)); //, Object.assign({}, env, { ssr }), new WebpackConfigHelpers(env.cwd));
  } catch (err) {
    throw new Error(`Error at ${paths.configFile}: \n` + err);
  }
};

function getWebpackHelpers(config) {
  return {
    webpack,
    getWebpackPluginsByName(name) {
      return config.plugins
        .map((p, i) => ({ index: i, plugin: p }))
        .filter(
          w =>
            w.plugin &&
            w.plugin.constructor &&
            w.plugin.constructor.name === name
        );
    },
    getBabelLoader() {
      return config.module.rules[2].oneOf[1]
    }
  };
}
