-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathcheckNxConfig.js
50 lines (44 loc) · 1.65 KB
/
checkNxConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { existsSync } = require('fs')
const { EOL } = require('os')
const path = require('path')
const checkNxConfig = ({ netlifyConfig, nextConfig, failBuild, constants: { PUBLISH_DIR } }) => {
const errors = []
if (nextConfig.distDir === '.next') {
errors.push(
"- When using Nx you must set a value for 'distDir' in your next.config.js, and the value cannot be '.next'",
)
}
if (!PUBLISH_DIR.startsWith('apps')) {
errors.push(
"Please set the 'publish' value in your Netlify build config to a folder inside your app directory. e.g. 'apps/myapp/out'",
)
}
const expectedConfigFile = path.resolve(netlifyConfig.build.publish, '..', 'next.config.js')
if (expectedConfigFile !== nextConfig.configFile) {
const confName = path.relative(process.cwd(), nextConfig.configFile)
errors.push(
`- Using incorrect config file '${confName}'. Expected to use '${path.relative(
process.cwd(),
expectedConfigFile,
)}'`,
)
if (existsSync(expectedConfigFile)) {
errors.push(
`Please move or delete '${confName}'${confName === 'next.config.js' ? ' from the root of your site' : ''}.`,
)
} else {
errors.push(
`Please move or delete '${confName}'${
confName === 'next.config.js' ? ' from the root of your site' : ''
}, and create '${path.relative(process.cwd(), expectedConfigFile)}' instead.`,
)
}
}
if (errors.length !== 0) {
failBuild(
// TODO: Add ntl.fyi link to docs
['Invalid configuration', ...errors, 'See the docs on using Nx with Netlify for more information'].join(EOL),
)
}
}
module.exports = checkNxConfig