Skip to content

Commit 0c67715

Browse files
committed
fix: create temporary config file
1 parent 0456d6c commit 0c67715

File tree

3 files changed

+20
-47
lines changed

3 files changed

+20
-47
lines changed

demo/next.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

helpers/hasCorrectNextConfig.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

helpers/verifyBuildTarget.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
const getNextConfig = require('./getNextConfig')
2+
const findUp = require('find-up')
3+
const { writeFile, unlink } = require('fs-extra')
4+
const path = require('path')
5+
26
// Checks if site has the correct next.config.js
37
const verifyBuildTarget = async ({ failBuild }) => {
48
const { target } = await getNextConfig(failBuild)
@@ -32,6 +36,22 @@ const verifyBuildTarget = async ({ failBuild }) => {
3236
// Clear memoized cache
3337
getNextConfig.clear()
3438

39+
// Temporarily creating a config file, because otherwise Next won't reload the config and pick up the new target
40+
const hasConfigFile = await Boolean(findUp('next.config.js'))
41+
const configFileName = path.resolve('next.config.js')
42+
43+
if (!hasConfigFile) {
44+
await writeFile(configFileName, `module.exports = {}`)
45+
}
46+
// Force the new config to be generated
47+
await getNextConfig(failBuild)
48+
49+
// If we created a config file then delete it
50+
if (!hasConfigFile) {
51+
await unlink(configFileName)
52+
}
53+
// Reset the value in case something else is looking for it
54+
process.env.NOW_BUILDER = false
3555
/* eslint-enable fp/no-delete, node/no-unpublished-require */
3656
}
3757

0 commit comments

Comments
 (0)