-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: postinstall warning when user has prisma deps #731
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
const chalk = require('chalk') | ||
const jetpack = require('fs-jetpack') | ||
const fs = require('fs-jetpack') | ||
const path = require('path') | ||
|
||
if (process.env.INIT_CWD) { | ||
|
@@ -9,23 +8,14 @@ if (process.env.INIT_CWD) { | |
|
||
const pwd = process.cwd() | ||
const nodeModulesFolder = path.join(pwd, 'node_modules') | ||
const from = path.resolve(nodeModulesFolder, 'nexus-plugin-prisma', 'global-type.d.ts') | ||
const from = path.resolve(nodeModulesFolder, 'nexus-plugin-prisma/global-type.d.ts') | ||
|
||
// Prevent from crashing if the typings can't be found for whatever reason | ||
if (jetpack.exists(from)) { | ||
const destDir = path.resolve(nodeModulesFolder, '@types', 'nexus-plugin-prisma') | ||
if (fs.exists(from)) { | ||
const destDir = path.resolve(nodeModulesFolder, '@types/nexus-plugin-prisma') | ||
|
||
jetpack.dir(destDir) | ||
jetpack.copy(from, path.join(destDir, 'index.d.ts'), { overwrite: true }) | ||
fs.dir(destDir) | ||
fs.copy(from, path.join(destDir, 'index.d.ts'), { overwrite: true }) | ||
} | ||
|
||
console.log(chalk.bold.yellowBright('----------------------------------')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think this is very helpful anymore and even if we wanted to keep it, would need rethinking now that the packages are merged. No? |
||
console.log( | ||
chalk.bold.yellowBright( | ||
`If you want to learn more about the ${chalk.reset.greenBright(`\`nexus-plugin-prisma\``)}` | ||
) | ||
) | ||
console.log( | ||
chalk.bold.yellowBright(`Follow this link: ${chalk.reset.greenBright(`http://nxs.li/nexus-plugin-prisma`)}`) | ||
) | ||
console.log(chalk.bold.yellowBright('----------------------------------')) | ||
require('./prisma-deps-check') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const boldWhite = '\u001b[37;1m' | ||
const reset = '\u001b[0m' | ||
const green = '\u001b[32;1m' | ||
const purple = '\u001b[35;1m' | ||
const CR = '\u001b[31;1m' | ||
const blue = '\u001b[36;1m' | ||
const red = '\u001b[1;31m' | ||
const yellow = '\u001b[33;1m' | ||
const gray = '\u001b[30;1m' | ||
|
||
const path = require('path') | ||
|
||
let foundPrismaDeps = [] | ||
|
||
const pj = getPackageJson() | ||
|
||
const deps = pj.dependencies || [] | ||
foundPrismaDeps.push(...Object.keys(deps).filter(isPrismaDep)) | ||
|
||
const devDeps = pj.devDependencies || [] | ||
foundPrismaDeps.push( | ||
...Object.keys(devDeps) | ||
.filter(isPrismaDep) | ||
// dedupe | ||
.filter((name) => !foundPrismaDeps.includes(name)) | ||
) | ||
|
||
const message = ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't go with the box design because of variable width content. |
||
${red}│${reset} ${red}WARNING${reset} from ${boldWhite}nexus-plugin-prisma${reset} | ||
${red}│${reset} ${red}WARNING${reset} from ${boldWhite}nexus-plugin-prisma${reset} | ||
${red}│${reset} ${red}WARNING${reset} from ${boldWhite}nexus-plugin-prisma${reset} | ||
${red}│${reset} | ||
${red}│${reset} ${yellow}nexus-plugin-prisma${reset} bundles ${yellow}@prisma${reset} dependencies. So | ||
${red}│${reset} please uninstall the ones you have installed or you may | ||
${red}│${reset} encounter problems. | ||
${red}│${reset} | ||
${red}│${reset} Run the following command to fix this issue: | ||
${red}│${reset} | ||
${red}│${reset} ${green}${getPackageManagerBinName()} remove ${foundPrismaDeps.join(' ')}${reset} | ||
${red}│${reset} | ||
${red}│${reset} If you absolutely need to control the versions of your | ||
${red}│${reset} ${yellow}@prisma${reset} dependencies then use yarn and its ${yellow}resolutions${reset} | ||
${red}│${reset} feature: | ||
${red}│${reset} | ||
${red}│${reset} ${boldWhite}https://classic.yarnpkg.com/en/docs/selective-version-resolutions${reset} | ||
${red}│${reset} | ||
${red}│${reset} If you are curious why ${yellow}nexus-plugin-prisma${reset} bundles | ||
${red}│${reset} the ${yellow}@prisma${reset} dependencies then take a look at the Nexus | ||
${red}│${reset} doc explaining this strategy. | ||
${red}│${reset} | ||
${red}│${reset} ${boldWhite}https://nxs.li/why/bundle-dependencies${reset} | ||
` | ||
|
||
if (foundPrismaDeps.length > 0) console.log(message) | ||
|
||
/** | ||
* Helpers | ||
*/ | ||
|
||
function isPrismaDep(name) { | ||
return name.startsWith('@prisma/') | ||
} | ||
|
||
function getPackageManagerBinName() { | ||
const userAgent = process.env.npm_config_user_agent || '' | ||
|
||
const packageManagerBinName = userAgent.includes('yarn') ? 'yarn' : 'npm' | ||
return packageManagerBinName | ||
} | ||
|
||
function getPackageJson() { | ||
let data = {} | ||
try { | ||
data = require(path.join(process.cwd(), 'package.json')) | ||
} catch (error) { | ||
// ignore | ||
} | ||
|
||
if (typeof data !== 'object') { | ||
// invalid package json like null | ||
// force object for downstream property access | ||
data = {} | ||
} | ||
|
||
return data | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OT
Started to get a bit worried about this being fragile. If not hoisted, we're going to get a runtime error.