File tree Expand file tree Collapse file tree 5 files changed +21
-13
lines changed
fixtures/deep_invalid_next_config Expand file tree Collapse file tree 5 files changed +21
-13
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const util = require('util')
5
5
const nextOnNetlify = require ( 'next-on-netlify' )
6
6
const { PHASE_PRODUCTION_BUILD } = require ( 'next/constants' )
7
7
const { default : loadConfig } = require ( 'next/dist/next-server/server/config' )
8
+ const findUp = require ( 'find-up' )
8
9
const makeDir = require ( 'make-dir' )
9
10
const pathExists = require ( 'path-exists' )
10
11
const cpx = require ( 'cpx' )
@@ -52,8 +53,8 @@ module.exports = {
52
53
)
53
54
}
54
55
55
- const hasNextConfig = await pathExists ( 'next.config.js' )
56
- if ( hasNextConfig ) {
56
+ const nextConfigPath = await findUp ( 'next.config.js' )
57
+ if ( nextConfigPath !== undefined ) {
57
58
// If the next config exists, fail build if target isnt in acceptableTargets
58
59
const acceptableTargets = [ 'serverless' , 'experimental-serverless-trace' ]
59
60
const nextConfig = loadConfig ( PHASE_PRODUCTION_BUILD , path . resolve ( '.' ) )
Original file line number Diff line number Diff line change 25
25
"homepage" : " https://github.com/netlify/netlify-plugin-nextjs#readme" ,
26
26
"dependencies" : {
27
27
"cpx" : " ^1.5.0" ,
28
+ "find-up" : " ^4.1.0" ,
28
29
"make-dir" : " ^3.1.0" ,
29
30
"next" : " ^9.5.3" ,
30
31
"next-on-netlify" : " ^2.6.0" ,
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ target : 'server' ,
3
+ }
Original file line number Diff line number Diff line change @@ -117,17 +117,20 @@ describe('preBuild()', () => {
117
117
expect ( await pathExists ( 'next.config.js' ) ) . toBeTruthy ( )
118
118
} )
119
119
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
+ )
131
134
} )
132
135
133
136
describe ( 'onBuild()' , ( ) => {
You can’t perform that action at this time.
0 commit comments