-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathhasCorrectNextConfig.js
27 lines (22 loc) · 1.08 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
const path = require('path')
// Checks if site has the correct next.cofig.js
const hasCorrectNextConfig = (nextConfigPath) => {
// 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']
const nextConfig = loadConfig(PHASE_PRODUCTION_BUILD, path.resolve('.'))
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