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')
55const nextOnNetlify = require ( 'next-on-netlify' )
66const { PHASE_PRODUCTION_BUILD } = require ( 'next/constants' )
77const { default : loadConfig } = require ( 'next/dist/next-server/server/config' )
8+ const findUp = require ( 'find-up' )
89const makeDir = require ( 'make-dir' )
910const pathExists = require ( 'path-exists' )
1011const 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 ( '.' ) )
Original file line number Diff line number Diff line change 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" ,
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()', () => {
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
133136describe ( 'onBuild()' , ( ) => {
You can’t perform that action at this time.
0 commit comments