-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathhasCorrectNextConfig.js
32 lines (27 loc) · 1.22 KB
/
hasCorrectNextConfig.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
const path = require('path')
// Checks if site has the correct next.cofig.js
const hasCorrectNextConfig = async ({ nextConfigPath, failBuild }) => {
// In the plugin's case, no config is valid because we'll make it ourselves
if (nextConfigPath === undefined) return true
// We cannot load `next` at the top-level because we validate whether the
// site is using `next` inside `onPreBuild`.
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
const { default: loadConfig } = require('next/dist/next-server/server/config')
// If the next config exists, log warning if target isnt in acceptableTargets
const acceptableTargets = ['serverless', 'experimental-serverless-trace']
let nextConfig
try {
nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, path.resolve('.'))
} catch (error) {
return failBuild('Error loading your next.config.js.', { error })
}
const isValidTarget = acceptableTargets.includes(nextConfig.target)
if (!isValidTarget) {
console.log(
`Your next.config.js must set the "target" property to one of: ${acceptableTargets.join(', ')}. Update the
target property to allow this plugin to run.`,
)
}
return isValidTarget
}
module.exports = hasCorrectNextConfig