<commit_before>import nodeResolve from '@rollup/plugin-node-resolve';
import { terser as minify } from 'rollup-plugin-terser';
import path from 'path';

const packageJson = require('../package.json');
const entryPoints = require('./entryPoints');

const distDir = './dist';

const externalPackages = new Set([
  '@wry/context',
  '@wry/equality',
  'fast-json-stable-stringify',
  'graphql-tag',
  'graphql/execution/execute',
  'graphql/language/printer',
  'graphql/language/visitor',
  'hoist-non-react-statics',
  'optimism',
  'prop-types',
  'react',
  'subscriptions-transport-ws',
  'symbol-observable',
  'ts-invariant',
  'tslib',
  'zen-observable',
]);

function prepareCJS(input, output) {
  return {
    input,
    external(id) {
      return externalPackages.has(id);
    },
    output: {
      file: output,
      format: 'cjs',
      sourcemap: true,
      exports: 'named',
      externalLiveBindings: false,
    },
    plugins: [
      nodeResolve(),
      // When generating the `dist/core/core.cjs.js` entry point (in
      // `config/prepareDist.js`), we filter and re-export the exports we
      // need from the main Apollo Client CJS bundle (to exclude React related
      // code). This means that consumers of `core.cjs.js` attempt to load the
      // full AC CJS bundle first (before filtering exports), which then means
      // the React require in the AC CJS bundle is attempted and not found
      // (since people using `core.cjs.js` want to use Apollo Client without
      // React). To address this, we make React an optional require in the CJS
      // bundle.
      (() => {
        const cjsBundle = output.replace(`${distDir}/`, '');
        return {
          generateBundle(_option, bundle) {
            const parts = bundle[cjsBundle].code.split(
              /var React = require\('react'\);/);
            // The React import should appear only once in the CJS bundle,
            // since we build the CJS bundle using Rollup, which (hopefully!)
            // deduplicates all external imports.
            if (parts && parts.length === 2) {
              bundle[cjsBundle].code = [
                parts[0],
                "try { var React = require('react'); } catch (error) {}",
                parts[1],
              ].join("\n");
            } else {
              throw new Error(
                'The CJS bundle could not be prepared as a single React ' +
                'require could not be found.'
              );
            }
          }
        }
      })()
    ],
  };
}<commit_msg>Remove require('react') try-catch wrapping logic.<commit_after>import nodeResolve from '@rollup/plugin-node-resolve';
import { terser as minify } from 'rollup-plugin-terser';
import path from 'path';

const packageJson = require('../package.json');
const entryPoints = require('./entryPoints');

const distDir = './dist';

const externalPackages = new Set([
  '@wry/context',
  '@wry/equality',
  'fast-json-stable-stringify',
  'graphql-tag',
  'graphql/execution/execute',
  'graphql/language/printer',
  'graphql/language/visitor',
  'hoist-non-react-statics',
  'optimism',
  'prop-types',
  'react',
  'subscriptions-transport-ws',
  'symbol-observable',
  'ts-invariant',
  'tslib',
  'zen-observable',
]);

function prepareCJS(input, output) {
  return {
    input,
    external(id) {
      return externalPackages.has(id);
    },
    output: {
      file: output,
      format: 'cjs',
      sourcemap: true,
      exports: 'named',
      externalLiveBindings: false,
    },
    plugins: [
      nodeResolve(),
    ],
  };
}
{'fraction_non_alphanumeric': 0.1399441340782123, 'fraction_numerical': 0.0008379888268156424, 'mean_word_length': 2.4137273593898954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5359651', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1073, 'n_words': 289}