<commit_before>function ensureConfigHasEntry (webpackConfig, entry, entryOptions, options = {}) {
  if (Array.isArray(webpackConfig)) {
    return webpackConfig.forEach((wconfig) => ensureConfigHasEntry(wconfig, entry, entryOptions, options))
  }

  if (Array.isArray(entry)) {
    return entry.forEach((e) => ensureConfigHasEntry(webpackConfig, e, entryOptions, options))
  }

  if (Array.isArray(options)) {
    options = {topModuleEntries: options}
  }

  if (webpackConfig.entry) {
    if (typeof webpackConfig.entry === 'string') {
      webpackConfig.entry = [webpackConfig.entry]
    }

    let append = false

    if (entry[0] === '+') {
      entry = entry.substring(1)
      append = true
    }

    const hasEntry = webpackConfig.entry.find((e) => {
      return !!e && e.startsWith(entry)
    })

    if (!hasEntry) {
      if (typeof entryOptions === 'object') {
        entryOptions = Object.keys(entryOptions)
          .map((key) => `${key}=${entryOptions[key]}`)
          .join('&')
      }

      if (entryOptions) {
        entry = `${entry}?${entryOptions}`
      }

      const topModuleEntries = webpackConfig.entry.filter((e) => {
        return (options.topModuleEntries || []).find((topModuleEntry) => {
          if (e) {
            if (typeof topModuleEntry === 'string') {
              return e.startsWith(topModuleEntry)
            }

            if (topModuleEntry && typeof topModuleEntry.test === 'function') {
              return topModuleEntry.test(e)
            }
          }

          return false
        })
      })

      const entries = webpackConfig.entry.filter((e) => {
        return topModuleEntries.indexOf(e) === -1
      })

      entries[append ? 'push' : 'unshift'].call(entries, entry)

      if (topModuleEntries.length) {
        entries.unshift.apply(entries, topModuleEntries)
      }

      webpackConfig.entry.length = 0
      webpackConfig.entry.push.apply(webpackConfig.entry, entries)
    }
  }

  return webpackConfig
}

module.exports = ensureConfigHasEntry<commit_msg>Upgrade ensureConfigHasEntry: supports multi-entry object<commit_after>function ensureConfigHasEntry (webpackConfig, entry, entryQuery, options = {}) {
  if (Array.isArray(webpackConfig)) {
    return webpackConfig.map((value) => ensureConfigHasEntry(value, entry, entryQuery, options))
  }

  if (Array.isArray(entry)) {
    entry.forEach((e) => ensureConfigHasEntry(webpackConfig, e, entryQuery, options))

    return webpackConfig
  }

  return insertEntry(webpackConfig, 'entry', entry, entryQuery, options)
}

function formatPathWithQuery (path, query) {
  if (query && typeof query === 'object') {
    query = Object.keys(query)
      .map((key) => `${key}=${query[key]}`)
      .join('&')
  }

  if (query) {
    path = `${path}?${query}`
  }

  return path
}

function inModule (moduleName, entry) {
  if (typeof entry !== 'string') {
    return false
  }

  while (entry.endsWith('/') || entry.endsWith('\\')) {
    entry = entry.substring(0, entry.length - 1)
  }

  return entry === moduleName
    || entry.startsWith(moduleName + '/')
    || entry.startsWith(moduleName + '\\')
    || entry.startsWith(moduleName + '?')
    || (moduleName.test && moduleName.test(entry))
}

function insertEntry (obj, key, entry, entryQuery, options = {}) {
  if (!obj[key]) {
    obj[key] = []
  }

  if (typeof obj[key] === 'string') {
    obj[key] = [obj[key]]
  }

  if (!Array.isArray(obj[key])) {
    Object.keys(obj[key]).forEach((entryName) => {
      insertEntry(obj[key], entryName, entry, entryQuery, options)
    })

    return obj
  }

  const entries = obj[key]
  let {
    append,
    topModuleEntries
  } = options

  if (entry[0] === '+') {
    entry = entry.substring(1)
    append = true
  }

  const hasEntry = entries.find((e) => inModule(entry, e))

  if (!hasEntry) {
    entry = formatPathWithQuery(entry, entryQuery)
    topModuleEntries = [].concat(topModuleEntries || [])

    const topEntries = entries.filter((e) => {
      return topModuleEntries.find((topEntry) => inModule(topEntry, e))
    })

    const nextEntries = entries.filter((e) => {
      return topEntries.indexOf(e) === -1
    })

    nextEntries[append ? 'push' : 'unshift'].call(nextEntries, entry)

    if (topEntries.length) {
      nextEntries.unshift.apply(nextEntries, topEntries)
    }

    entries.length = 0
    entries.push.apply(entries, nextEntries)
  }

  return obj
}

module.exports = Object.assign(ensureConfigHasEntry.bind(), {
  ensureConfigHasEntry,
  formatPathWithQuery,
  inModule,
  insertEntry
})
{'fraction_non_alphanumeric': 0.1519349164467898, 'fraction_numerical': 0.0021987686895338612, 'mean_word_length': 3.0256637168141594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '5302789', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1400, 'n_words': 271}