Skip to content

Commit b31bd91

Browse files
author
Jason Kuhrt
authored
feat: warn when user has installed bundled deps (#1148)
1 parent 046a04e commit b31bd91

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

scripts/postinstall-deps-check.js

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,16 @@ const gray = '\u001b[30;1m'
1010

1111
const path = require('path')
1212

13-
let foundPrismaDeps = []
14-
15-
const pj = getPackageJson()
16-
17-
const deps = pj.dependencies || []
18-
foundPrismaDeps.push(...Object.keys(deps).filter(isPrismaDep))
19-
20-
const devDeps = pj.devDependencies || []
21-
foundPrismaDeps.push(
22-
...Object.keys(devDeps)
23-
.filter(isPrismaDep)
24-
// dedupe
25-
.filter((name) => !foundPrismaDeps.includes(name))
26-
)
27-
28-
const message = `
29-
${red}${reset} ${red}WARNING${reset} from ${boldWhite}nexus-plugin-prisma${reset}
30-
${red}${reset} ${red}WARNING${reset} from ${boldWhite}nexus-plugin-prisma${reset}
31-
${red}${reset} ${red}WARNING${reset} from ${boldWhite}nexus-plugin-prisma${reset}
32-
${red}${reset}
33-
${red}${reset} ${yellow}nexus-plugin-prisma${reset} bundles ${yellow}@prisma${reset} dependencies. So
34-
${red}${reset} please uninstall the ones you have installed or you may
35-
${red}${reset} encounter problems.
36-
${red}${reset}
37-
${red}${reset} Run the following command to fix this issue:
38-
${red}${reset}
39-
${red}${reset} ${green}${getPackageManagerBinName()} remove ${foundPrismaDeps.join(' ')}${reset}
40-
${red}${reset}
41-
${red}${reset} If you absolutely need to control the versions of your
42-
${red}${reset} ${yellow}@prisma${reset} dependencies then use yarn and its ${yellow}resolutions${reset}
43-
${red}${reset} feature:
44-
${red}${reset}
45-
${red}${reset} ${boldWhite}https://classic.yarnpkg.com/en/docs/selective-version-resolutions${reset}
46-
${red}${reset}
47-
${red}${reset} If you are curious why ${yellow}nexus-plugin-prisma${reset} bundles
48-
${red}${reset} the ${yellow}@prisma${reset} dependencies then take a look at the Nexus
49-
${red}${reset} doc explaining this strategy.
50-
${red}${reset}
51-
${red}${reset} ${boldWhite}https://nxs.li/why/bundle-dependencies${reset}
52-
`
13+
/**
14+
* data
15+
*/
5316

54-
if (foundPrismaDeps.length > 0) console.log(message)
17+
const bundledDeps = ['graphql', '@nexus/schema']
5518

5619
/**
5720
* Helpers
5821
*/
5922

60-
function isPrismaDep(name) {
61-
return name.startsWith('@prisma/')
62-
}
63-
6423
function getPackageManagerBinName() {
6524
const userAgent = process.env.npm_config_user_agent || ''
6625

@@ -84,3 +43,58 @@ function getPackageJson() {
8443

8544
return data
8645
}
46+
47+
function findDepsDeDuped(pj, bundledDeps) {
48+
const foundDeps = []
49+
50+
const deps = pj.dependencies || []
51+
foundDeps.push(...Object.keys(deps).filter(isBundledDep))
52+
53+
const devDeps = pj.devDependencies || []
54+
foundDeps.push(
55+
...Object.keys(devDeps)
56+
.filter(isBundledDep)
57+
// dedupe
58+
.filter((name) => !foundDeps.includes(name))
59+
)
60+
61+
return foundDeps
62+
63+
function isBundledDep(name) {
64+
return bundledDeps.includes(name)
65+
}
66+
}
67+
68+
/**
69+
* script
70+
*/
71+
72+
let foundDeps = findDepsDeDuped(getPackageJson(), bundledDeps)
73+
74+
const message = `
75+
${red}${reset} ${red}WARNING${reset} from ${boldWhite}nexus${reset}
76+
${red}${reset} ${red}WARNING${reset} from ${boldWhite}nexus${reset}
77+
${red}${reset} ${red}WARNING${reset} from ${boldWhite}nexus${reset}
78+
${red}${reset}
79+
${red}${reset} ${yellow}nexus${reset} bundles ${yellow}graphql${reset} and ${yellow}@nexus/schema${reset} dependencies.
80+
${red}${reset} So please uninstall the ones you have installed or you
81+
${red}${reset} may encounter problems.
82+
${red}${reset}
83+
${red}${reset} Run the following command to fix this issue:
84+
${red}${reset}
85+
${red}${reset} ${green}${getPackageManagerBinName()} remove ${foundDeps.join(' ')}${reset}
86+
${red}${reset}
87+
${red}${reset} If you absolutely need to control the versions of these
88+
${red}${reset} dependencies then use Yarn and its ${yellow}resolutions${reset} feature:
89+
${red}${reset}
90+
${red}${reset} ${boldWhite}https://classic.yarnpkg.com/en/docs/selective-version-resolutions${reset}
91+
${red}${reset}
92+
${red}${reset} If you are curious why ${yellow}nexus${reset} bundles these dependencies
93+
${red}${reset} then refer to the Nexus doc explaining this strategy.
94+
${red}${reset}
95+
${red}${reset} ${boldWhite}https://nxs.li/why/bundle-dependencies${reset}
96+
`
97+
98+
if (foundDeps.length > 0) {
99+
console.log(message)
100+
}

scripts/postinstall.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
require('./postinstall-message')
1+
require('./postinstall-transition-message')
2+
require('./postinstall-deps-check')
23
require('./postinstall-typegen')

0 commit comments

Comments
 (0)