<commit_before>'use babel'

import Path from 'path'
import Browserify from 'browserify'
import {Readable} from 'streams'

const PrivateOptions = ['external', 'transforms', 'require', 'exclude', 'ignore', 'plugins']

export const compiler = false
export const minifier = false

export function process(contents, {root, relativePath, absolutePath, fileName}, {state, config}) {
  const fileDir = Path.dirname(absolutePath)
  const stream = new Readable()
  stream._read = function() {
    stream.push(contents)
    stream.push(null)
  }

  const options = Object.assign({
    fullPaths: true
  }, config.browserify, {
    basedir: fileDir,
    debug: true,
    filename: fileName,
    paths: [fileDir, root]
  })
  const optionsPrivate = {}

  PrivateOptions.forEach(function(name) {
    if (typeof options[name] !== 'undefined') {
      optionsPrivate[name] = options[name]
      delete options[name]
    } else {
      optionsPrivate[name] = []
    }
  })

  const browserified = new Browserify(options)

  PrivateOptions.forEach(function(name) {
    const options = optionsPrivate[name]
    browserified[name](...options)
  })

  return new Promise(function(resolve, reject) {
    browserified.bundle(function(error, buffer) {
      if (error) {
        reject(error)
      } else resolve(buffer.toString())
    })
    browserified.pipeline.on('file', function(file){
      state.imports.push(file)
    })
  })
}<commit_msg>:art: Cleanup BrowserifyOptions implementation<commit_after>'use babel'

import Path from 'path'
import Browserify from 'browserify'
import {Readable} from 'streams'

const BrowserifyOptions = ['external', 'transforms', 'require', 'exclude', 'ignore', 'plugins']

export const compiler = false
export const minifier = false

export function process(contents, {rootDirectory, filePath, config, state}) {
  const stream = new Readable()
  stream._read = function() {
    stream.push(contents)
    stream.push(null)
  }

  const options = Object.assign(config.browserify, {
    basedir: rootDirectory,
    debug: true,
    filename: Path.basename(filePath),
    paths: [rootDirectory],
    fullPaths: true
  })

  const browserified = new Browserify(options)

  return new Promise(function(resolve, reject) {
    browserified.bundle(function(error, buffer) {
      if (error) {
        reject(error)
      } else resolve(buffer.toString())
    })
    BrowserifyOptions.forEach(function(name) {
      if (typeof options[name] !== 'undefined') {
        options[name].forEach(function(options) {
          browserified[name](...options)
        })
      }
    })
    browserified.pipeline.on('file', function(file){
      state.imports.push(file)
    })
  })
}
{'fraction_non_alphanumeric': 0.12985074626865672, 'fraction_numerical': 0.0, 'mean_word_length': 3.7035087719298247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3651683', 'n_tokens_mistral': 795, 'n_tokens_neox': 780, 'n_words': 187}