<commit_before>import path from 'path'
import fs from 'fs'
import semver from 'semver'

const baseRequire = module.constructor.prototype.require

const satisfies = (versionPath, soughtModule, soughtVersion) => {
  const pack = fs.readFileSync(path.join(versionPath, soughtModule, 'package.json'))
  const {version} = JSON.parse(pack)
  return semver.satisfies(version, soughtVersion) ? version : null
}

// Modify global require
module.constructor.prototype.require = function (request) {
  let newRequest = request
  const [name, version] = request.split('@')

  if (name && version) {
    const nodeModules = path.join(path.dirname(this.filename), 'node_modules')
    const match = satisfies(nodeModules, name, version)

    if (match) {
      if (match !== version) {
        console.warning(`${name} was required as ${version} but will be using ${match}.`)
      }
      newRequest = name
    } else {
      throw new Error(`Tried to require ${name} but could not find a version that satisfied semver for ${version}.`)
    }
  }

  return baseRequire.apply(this, [newRequest])
}
<commit_msg>add adapted notice to require-version<commit_after>import path from 'path'
import fs from 'fs'
import semver from 'semver'

const baseRequire = module.constructor.prototype.require

const satisfies = (versionPath, soughtModule, soughtVersion) => {
  const pack = fs.readFileSync(path.join(versionPath, soughtModule, 'package.json'))
  const {version} = JSON.parse(pack)
  return semver.satisfies(version, soughtVersion) ? version : null
}

// Modify global require
// Adapted from https://github.com/brumfb/require-version
module.constructor.prototype.require = function (request) {
  let newRequest = request
  const [name, version] = request.split('@')

  if (name && version) {
    const nodeModules = path.join(path.dirname(this.filename), 'node_modules')
    const match = satisfies(nodeModules, name, version)

    if (match) {
      if (match !== version) {
        console.warning(`${name} was required as ${version} but will be using ${match}.`)
      }
      newRequest = name
    } else {
      throw new Error(`Tried to require ${name} but could not find a version that satisfied semver for ${version}.`)
    }
  }

  return baseRequire.apply(this, [newRequest])
}

{'fraction_non_alphanumeric': 0.12323943661971831, 'fraction_numerical': 0.0, 'mean_word_length': 3.9846491228070176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '3705431', 'n_tokens_mistral': 658, 'n_tokens_neox': 654, 'n_words': 199}