Skip to content

Commit 1f90614

Browse files
authored
Merge pull request #35 from netlify/bug/find-config
2 parents ed8152f + 1d07505 commit 1f90614

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const util = require('util')
55
const nextOnNetlify = require('next-on-netlify')
66
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
77
const { default: loadConfig } = require('next/dist/next-server/server/config')
8+
const findUp = require('find-up')
89
const makeDir = require('make-dir')
910
const pathExists = require('path-exists')
1011
const cpx = require('cpx')
@@ -52,8 +53,8 @@ module.exports = {
5253
)
5354
}
5455

55-
const hasNextConfig = await pathExists('next.config.js')
56-
if (hasNextConfig) {
56+
const nextConfigPath = await findUp('next.config.js')
57+
if (nextConfigPath !== undefined) {
5758
// If the next config exists, fail build if target isnt in acceptableTargets
5859
const acceptableTargets = ['serverless', 'experimental-serverless-trace']
5960
const nextConfig = loadConfig(PHASE_PRODUCTION_BUILD, path.resolve('.'))

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
2626
"dependencies": {
2727
"cpx": "^1.5.0",
28+
"find-up": "^4.1.0",
2829
"make-dir": "^3.1.0",
2930
"next": "^9.5.3",
3031
"next-on-netlify": "^2.6.0",

test/fixtures/deep_invalid_next_config/base/.gitkeep

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
target: 'server',
3+
}

test/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,20 @@ describe('preBuild()', () => {
117117
expect(await pathExists('next.config.js')).toBeTruthy()
118118
})
119119

120-
test(`fail build if the app's next config has an invalid target`, async () => {
121-
await useFixture('invalid_next_config')
122-
await expect(
123-
plugin.onPreBuild({
124-
netlifyConfig: {},
125-
packageJson: DUMMY_PACKAGE_JSON,
126-
utils,
127-
constants: { FUNCTIONS_SRC: 'out_functions' },
128-
}),
129-
).rejects.toThrow(`next.config.js must be one of: serverless, experimental-serverless-trace`)
130-
})
120+
test.each(['invalid_next_config', 'deep_invalid_next_config'])(
121+
`fail build if the app's next config has an invalid target`,
122+
async (fixtureName) => {
123+
await useFixture(fixtureName)
124+
await expect(
125+
plugin.onPreBuild({
126+
netlifyConfig: {},
127+
packageJson: DUMMY_PACKAGE_JSON,
128+
utils,
129+
constants: { FUNCTIONS_SRC: 'out_functions' },
130+
}),
131+
).rejects.toThrow(`next.config.js must be one of: serverless, experimental-serverless-trace`)
132+
},
133+
)
131134
})
132135

133136
describe('onBuild()', () => {

0 commit comments

Comments
 (0)