<commit_before>import * as path from 'path'
import alias from 'rollup-plugin-alias'
import nodeResolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import uglify from 'rollup-plugin-uglify'
import { rollup as lernaAlias } from 'lerna-alias'
import pkg from './package.json'

const ensureArray = maybeArr => (Array.isArray(maybeArr) ? maybeArr : [maybeArr])

const makeExternalPredicate = externalArr => {
  if (!externalArr.length) {
    return () => false
  }
  const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`)
  return id => pattern.test(id)
}

const deps = Object.keys(pkg.dependencies || {})
const peerDeps = Object.keys(pkg.peerDependencies || {})

const helperPath = /^(@babel\/runtime\/helpers)\/(\w+)$/

const rewriteRuntimeHelpersImports = ({ types: t }) => ({
  name: 'rewrite-runtime-helpers-imports',
  visitor: {
    ImportDeclaration(path) {
      const source = path.get('source')
      if (!helperPath.test(source.node.value)) {
        return
      }
      const rewrittenPath = source.node.value.replace(helperPath, (m, p1, p2) => [p1, 'esm', p2].join('/'))
      source.replaceWith(t.stringLiteral(rewrittenPath))
    },
  },
})

const createConfig = ({ input, output, external, env, min = false, useESModules = true }) => ({
  input,
  experimentalCodeSplitting: typeof input !== 'string',
  output: ensureArray(output).map(format =>
    Object.assign({}, format, {
      name: 'ReduxSaga',
      exports: 'named',
    }),
  ),
  external: makeExternalPredicate(external === 'peers' ? peerDeps : deps.concat(peerDeps)),
  plugins: [
    alias(lernaAlias()),
    nodeResolve({
      jsnext: true,
    }),
    babel({
      exclude: 'node_modules/**',
      babelrcRoots: path.resolve(__dirname, '../*'),
      plugins: [
        useESModules && rewriteRuntimeHelpersImports,
        [
          '@babel/plugin-transform-runtime',
          {
            useESModules,
          },
        ],
      ].filter(Boolean),
      runtimeHelpers: true,
    }),
    env &&
      replace({
        'process.env.NODE_ENV': JSON.stringify(env),
      }),
    min &&
      uglify({
        compress: {
          pure_getters: true,
          unsafe: true,
          unsafe_comps: true,
          warnings: false,
        },
      }),
  ].filter(Boolean),
})

const multiInput = {
  core: 'src/index.js',
  effects: 'src/effects.js',
  utils: 'src/utils.js',
}

export default [
  createConfig({
    input: multiInput,
    output: {
      dir: 'dist',
      format: 'esm',
      entryFileNames: 'redux-saga-[name].[format].js',
    },
  }),
  createConfig({
    input: multiInput,
    output: {
      dir: 'dist',
      format: 'cjs',
      entryFileNames: 'redux-saga-[name].prod.[format].js',
    },
    useESModules: false,
    env: 'production',
  }),
  createConfig({
    input: multiInput,
    output: {
      dir: 'dist',
      format: 'cjs',
      entryFileNames: 'redux-saga-[name].dev.[format].js',
    },
    useESModules: false,
    env: 'development',
  }),
  createConfig({
    input: 'src/index.umd.js',
    output: {
      file: 'dist/redux-saga.umd.js',
      format: 'umd',
    },
    external: 'peers',
    env: 'development',
  }),
  createConfig({
    input: 'src/index.umd.js',
    output: {
      file: 'dist/redux-saga.min.umd.js',
      format: 'umd',
    },
    external: 'peers',
    env: 'production',
    min: true,
  }),
]
<commit_msg>Hide useESModules config inside createConfig<commit_after>import * as path from 'path'
import alias from 'rollup-plugin-alias'
import nodeResolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import uglify from 'rollup-plugin-uglify'
import { rollup as lernaAlias } from 'lerna-alias'
import pkg from './package.json'

const makeExternalPredicate = externalArr => {
  if (!externalArr.length) {
    return () => false
  }
  const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`)
  return id => pattern.test(id)
}

const deps = Object.keys(pkg.dependencies || {})
const peerDeps = Object.keys(pkg.peerDependencies || {})

const helperPath = /^(@babel\/runtime\/helpers)\/(\w+)$/

const rewriteRuntimeHelpersImports = ({ types: t }) => ({
  name: 'rewrite-runtime-helpers-imports',
  visitor: {
    ImportDeclaration(path) {
      const source = path.get('source')
      if (!helperPath.test(source.node.value)) {
        return
      }
      const rewrittenPath = source.node.value.replace(helperPath, (m, p1, p2) => [p1, 'esm', p2].join('/'))
      source.replaceWith(t.stringLiteral(rewrittenPath))
    },
  },
})

const createConfig = ({ input, output, external, env, min = false, useESModules = output.format !== 'cjs' }) => ({
  input,
  experimentalCodeSplitting: typeof input !== 'string',
  output: {
    ...output,
    name: 'ReduxSaga',
    exports: 'named',
  },
  external: makeExternalPredicate(external === 'peers' ? peerDeps : deps.concat(peerDeps)),
  plugins: [
    alias(lernaAlias()),
    nodeResolve({
      jsnext: true,
    }),
    babel({
      exclude: 'node_modules/**',
      babelrcRoots: path.resolve(__dirname, '../*'),
      plugins: [
        useESModules && rewriteRuntimeHelpersImports,
        [
          '@babel/plugin-transform-runtime',
          {
            useESModules,
          },
        ],
      ].filter(Boolean),
      runtimeHelpers: true,
    }),
    env &&
      replace({
        'process.env.NODE_ENV': JSON.stringify(env),
      }),
    min &&
      uglify({
        compress: {
          pure_getters: true,
          unsafe: true,
          unsafe_comps: true,
          warnings: false,
        },
      }),
  ].filter(Boolean),
})

const multiInput = {
  core: 'src/index.js',
  effects: 'src/effects.js',
  utils: 'src/utils.js',
}

export default [
  createConfig({
    input: multiInput,
    output: {
      dir: 'dist',
      format: 'esm',
      entryFileNames: 'redux-saga-[name].[format].js',
    },
  }),
  createConfig({
    input: multiInput,
    output: {
      dir: 'dist',
      format: 'cjs',
      entryFileNames: 'redux-saga-[name].prod.[format].js',
    },
    env: 'production',
  }),
  createConfig({
    input: multiInput,
    output: {
      dir: 'dist',
      format: 'cjs',
      entryFileNames: 'redux-saga-[name].dev.[format].js',
    },
    env: 'development',
  }),
  createConfig({
    input: 'src/index.umd.js',
    output: {
      file: 'dist/redux-saga.umd.js',
      format: 'umd',
    },
    external: 'peers',
    env: 'development',
  }),
  createConfig({
    input: 'src/index.umd.js',
    output: {
      file: 'dist/redux-saga.min.umd.js',
      format: 'umd',
    },
    external: 'peers',
    env: 'production',
    min: true,
  }),
]

{'fraction_non_alphanumeric': 0.16765140324963074, 'fraction_numerical': 0.0011816838995568684, 'mean_word_length': 2.6659447753113157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '496121', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2251, 'n_words': 441}