<commit_before>import { Compiler, Plugin } from 'webpack'
import { createHash } from 'crypto'
import path from 'path'

/**
 * From escape-string-regexp: https://github.com/sindresorhus/escape-string-regexp
 * brought here to reduce the bundle size
 * MIT License
 * Copyright (c) <NAME> <<EMAIL>> (sindresorhus.com)
 */
const matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
const escapeRegex = (str: string) => {
	if (typeof str !== 'string') {
		throw new TypeError('Expected a string');
	}
	return str.replace(matchOperatorsRe, '\\$&');
};

function getRawModuleIdentifier(m: any, dir: string) {
  // webpack impl:
  // new RawModule(
  //   "/* (ignored) */",
  //   `ignored ${context} ${request}`,
  //   `${request} (ignored)`
  // )

  let request = m.readableIdentifierStr.replace(/ \(ignored\)$/, '')
  let context = m.identifierStr
    .match(new RegExp(`^ignored (.*) ${escapeRegex(request)}$`))
    .pop()

  if (path.isAbsolute(request)) {
    request = path.relative(dir, request)
  }
  if (path.isAbsolute(context)) {
    context = path.relative(dir, context)
  }

  const identifier = `${context}::${request}`
  console.warn(
    `[module identifier] RawModule ${m.identifier()} => ${identifier}`
  )
  return identifier
}

function getMultiModuleIdentifier(m: any) {
  const mods = m.dependencies.map((d: any) => d.module)
  if (mods.some((d: any) => !Boolean(d))) {
    throw new Error('Cannot handle a MultiModule with moduleless dependencies')
  }

  const ids = mods.map((m: any) => m.id)
  if (ids.some((i: any) => !Boolean(i))) {
    throw new Error(
      'Cannot handle a MultiModule dependency without a module id'
    )
  }

  const identifier = ids.sort().join('::')
  console.warn(
    `[module identifier] MultiModule ${m.identifier()} => ${identifier}`
  )<commit_msg>Adjust all modules identified plugin output (#6995)<commit_after>import { createHash } from 'crypto'
import path from 'path'
import { Compiler, Plugin } from 'webpack'

/**
 * From escape-string-regexp: https://github.com/sindresorhus/escape-string-regexp
 * brought here to reduce the bundle size
 * MIT License
 * Copyright (c) <NAME> <<EMAIL>> (sindresorhus.com)
 */
const matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g
const escapeRegex = (str: string) => {
  if (typeof str !== 'string') {
    throw new TypeError('Expected a string')
  }
  return str.replace(matchOperatorsRe, '\\$&')
}

function getRawModuleIdentifier(m: any, dir: string) {
  // webpack impl:
  // new RawModule(
  //   "/* (ignored) */",
  //   `ignored ${context} ${request}`,
  //   `${request} (ignored)`
  // )

  let request = m.readableIdentifierStr.replace(/ \(ignored\)$/, '')
  let context = m.identifierStr
    .match(new RegExp(`^ignored (.*) ${escapeRegex(request)}$`))
    .pop()

  if (path.isAbsolute(request)) {
    request = path.relative(dir, request)
  }
  if (path.isAbsolute(context)) {
    context = path.relative(dir, context)
  }

  const identifier = `${context}::${request}`
  console.warn(
    `> module identifier: RawModule ${m.identifier()} => ${identifier}`
  )
  return identifier
}

function getMultiModuleIdentifier(m: any) {
  const mods = m.dependencies.map((d: any) => d.module)
  if (mods.some((d: any) => !Boolean(d))) {
    throw new Error('Cannot handle a MultiModule with moduleless dependencies')
  }

  const ids = mods.map((m: any) => m.id)
  if (ids.some((i: any) => !Boolean(i))) {
    throw new Error(
      'Cannot handle a MultiModule dependency without a module id'
    )
  }

  const identifier = ids.sort().join('::')
  console.warn(
    `> module identifier: MultiModule ${m.identifier()} => ${identifier}`
  )
{'fraction_non_alphanumeric': 0.18224427901847257, 'fraction_numerical': 0.0011028398125172319, 'mean_word_length': 3.6752577319587627, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '3523506', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1196, 'n_words': 300}