1
1
const getNextConfig = require ( './getNextConfig' )
2
-
3
2
// Checks if site has the correct next.config.js
4
3
const hasCorrectNextConfig = async ( { nextConfigPath, failBuild } ) => {
5
4
// In the plugin's case, no config is valid because we'll make it ourselves
@@ -12,9 +11,27 @@ const hasCorrectNextConfig = async ({ nextConfigPath, failBuild }) => {
12
11
const isValidTarget = acceptableTargets . includes ( target )
13
12
if ( ! isValidTarget ) {
14
13
console . log (
15
- `Your next.config.js must set the "target" property to one of: ${ acceptableTargets . join ( ', ' ) } . Update the
16
- target property to allow this plugin to run.` ,
14
+ `The "target" config property must be one of "${ acceptableTargets . join ( '", "' ) } ". Setting it to "serverless".` ,
17
15
)
16
+
17
+ /* eslint-disable fp/no-delete, node/no-unpublished-require */
18
+
19
+ // We emulate Vercel so that we can set target to serverless if needed
20
+ process . env . NOW_BUILDER = true
21
+ // If no valid target is set, we use an internal Next env var to force it
22
+ process . env . NEXT_PRIVATE_TARGET = 'serverless'
23
+
24
+ // 🐉 We need Next to recalculate "isZeitNow" var so we can set the target, but it's
25
+ // set as an import side effect so we need to clear the require cache first. 🐲
26
+ // https://github.com/vercel/next.js/blob/canary/packages/next/telemetry/ci-info.ts
27
+
28
+ delete require . cache [ require . resolve ( 'next/dist/telemetry/ci-info' ) ]
29
+ delete require . cache [ require . resolve ( 'next/dist/next-server/server/config' ) ]
30
+
31
+ // Clear memoized cache
32
+ getNextConfig . clear ( )
33
+
34
+ /* eslint-enable fp/no-delete, node/no-unpublished-require */
18
35
}
19
36
20
37
return isValidTarget
0 commit comments