<commit_before>const Debug = require('debug')
const path = require('path')
const globalDirs = require('global-dirs')
const { drawBox } = require('@prisma/sdk/dist/drawBox')
const isInstalledGlobally = require('is-installed-globally')
const debug = Debug('preinstall')

const BOLD = '\u001b[1m'
const WHITE_BRIGHT = '\u001b[37;1m'
const RESET = '\u001b[0m'

// returns { pkgManager: 'yarn' | 'npm', pkgPath: string } | null
function prisma2IsInstalledGlobally() {
  try {
    const pkgPath = require.resolve(path.join(globalDirs.yarn.packages, 'prisma2/package.json'))
    return { pkgManager: 'yarn', pkgPath }
  } catch (_) {
    try {
      const pkgPath = require.resolve(path.join(globalDirs.npm.packages, 'prisma2/package.json'))
      return { pkgManager: 'npm', pkgPath }
    } catch (_) {
      //
    }
  }
  return null
}

const b = str => BOLD + str + RESET
const white = str => WHITE_BRIGHT + str + RESET

if (!isInstalledGlobally) {
  process.exit(0)
}

const installedGlobally = prisma2IsInstalledGlobally()
debug({ installedGlobally })
if (!installedGlobally) {
  process.exit(0)
}

const pkg = require(installedGlobally.pkgPath)
const parts = pkg.version.split('-')
const isAlpha = parts[1].split('.') === 'alpha'

const message = `
The package ${white('prisma2')} has been renamed to ${white('@prisma/cli')}.

Please uninstall ${white('prisma2')} globally first.
Then install ${white('@prisma/cli')} to continue using ${b('Prisma 2.0')}:

   # Uninstall old CLI
   ${white(prisma2IsInstalledGlobally.pkgManager === 'yarn' ? 'yarn remove -g prisma2' : 'npm uninstall -g prisma2')}

   # Install new CLI
   ${white(`npm install @prisma/cli${isAlpha ? '@alpha' : ''} --save-dev`)}

   # Invoke via npx
   ${white('npx prisma --help')}

Learn more here: https://pris.ly/preview025
`

console.error(drawBox({ str: message, verticalPadding: 1, horizontalPadding: 3 }))
process.exit(1)<commit_msg>fix preinstall<commit_after>const Debug = require('debug')
const path = require('path')
const globalDirs = require('global-dirs')
const { drawBox } = require('@prisma/sdk/dist/drawBox')
const isInstalledGlobally = require('is-installed-globally')
const debug = Debug('preinstall')

const BOLD = '\u001b[1m'
const WHITE_BRIGHT = '\u001b[37;1m'
const RESET = '\u001b[0m'

// returns { pkgManager: 'yarn' | 'npm', pkgPath: string } | null
function prisma2IsInstalledGlobally() {
  try {
    const pkgPath = require.resolve(path.join(globalDirs.yarn.packages, 'prisma2/package.json'))
    return { pkgManager: 'yarn', pkgPath }
  } catch (_) {
    try {
      const pkgPath = require.resolve(path.join(globalDirs.npm.packages, 'prisma2/package.json'))
      return { pkgManager: 'npm', pkgPath }
    } catch (_) {
      //
    }
  }
  return null
}

const b = str => BOLD + str + RESET
const white = str => WHITE_BRIGHT + str + RESET

// When running in npx, npm puts this package into a /_npx/ folder. Tested on Win, Mac, Linux
if (__dirname.includes('_npx')) {
  process.exit(0)
}

if (!isInstalledGlobally) {
  process.exit(0)
}

const installedGlobally = prisma2IsInstalledGlobally()
debug({ installedGlobally })
if (!installedGlobally) {
  process.exit(0)
}

const pkg = require(installedGlobally.pkgPath)
const parts = pkg.version.split('-')
const isAlpha = parts[1].split('.') === 'alpha'

const message = `
The package ${white('prisma2')} has been renamed to ${white('@prisma/cli')}.

Please uninstall ${white('prisma2')} globally first.
Then install ${white('@prisma/cli')} to continue using ${b('Prisma 2.0')}:

   # Uninstall old CLI
   ${white(installedGlobally.pkgManager === 'yarn' ? 'yarn remove -g prisma2' : 'npm uninstall -g prisma2')}

   # Install new CLI
   ${white(`npm install @prisma/cli${isAlpha ? '@alpha' : ''} --save-dev`)}

   # Invoke via npx
   ${white('npx prisma --help')}

Learn more here: https://pris.ly/preview025
`

console.error(drawBox({ str: message, verticalPadding: 1, horizontalPadding: 3 }))
process.exit(1)
{'fraction_non_alphanumeric': 0.16080910240202276, 'fraction_numerical': 0.017193426042983566, 'mean_word_length': 4.353179972936401, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2993732', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1374, 'n_words': 326}