Skip to content

Commit

Permalink
fix preinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Apr 2, 2020
1 parent c06d2ef commit ce09b94
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions cli/prisma2/scripts/preinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,29 @@ function prismaIsInstalledGlobally() {
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)
}
function main() {
// 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)
}
if (!isInstalledGlobally) {
process.exit(0)
}

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

const pkg = require(installedGlobally.pkgPath)
const parts = pkg.version.split('-')
const isAlpha = parts.length > 1 ? parts[1].split('.') === 'alpha' : false
const pkg = require(installedGlobally.pkgPath)
const parts = pkg.version.split('-')
const isAlpha = parts.length > 1 ? parts[1].split('.') === 'alpha' : false

let message
if (installedGlobally.name === 'prisma2') {
message = `
let message
if (installedGlobally.name === 'prisma2') {
message = `
The package ${white('prisma2')} has been renamed to ${white('@prisma/cli')}.
Please uninstall ${white('prisma2')} globally first.
Expand All @@ -86,8 +87,8 @@ Then install ${white('@prisma/cli')} to continue using ${b('Prisma 2.0')}:
Learn more here: https://pris.ly/preview025
`
} else {
message = `
} else {
message = `
You seem to have a global installation of Prisma 1 package ${white('prisma')}.
As Prisma 2 uses the same executable ${white('prisma')}, this would lead to a conflict.
Expand All @@ -113,7 +114,14 @@ Then you can install Prisma 2:
Learn more here: https://pris.ly/prisma1
`
}

console.error(drawBox({ str: message, verticalPadding: 1, horizontalPadding: 3 }))
process.exit(1)
}

console.error(drawBox({ str: message, verticalPadding: 1, horizontalPadding: 3 }))
process.exit(1)
try {
main()
} catch (e) {
debug(e)
}

0 comments on commit ce09b94

Please sign in to comment.