File tree 5 files changed +30
-6
lines changed
5 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ test/sample/netlify-automatic-functions
7
7
test /sample /my-publish-dir
8
8
test /sample /.next
9
9
test /sample /.netlify
10
+ next.config.js
10
11
11
12
# Logs
12
13
logs
Original file line number Diff line number Diff line change @@ -20,3 +20,4 @@ node_modules
20
20
__mocks__
21
21
test /fixtures
22
22
test /sample
23
+ next.config.js
Original file line number Diff line number Diff line change 4
4
5
5
const isStaticExportProject = ( { build, scripts } ) => {
6
6
const NEXT_EXPORT_COMMAND = 'next export'
7
- const isSetInNetlifyConfig = build && build . command && build . command . includes ( NEXT_EXPORT_COMMAND )
7
+
8
+ if ( ! build || ! build . command ) return
9
+
10
+ const isSetInNetlifyConfig = build . command . includes ( NEXT_EXPORT_COMMAND )
11
+
8
12
const isSetInNpmScript = Object . keys ( scripts ) . find ( ( script ) => {
9
- return scripts [ script ] . includes ( NEXT_EXPORT_COMMAND )
13
+ const scriptValue = scripts [ script ]
14
+ return build . command . includes ( script ) && scriptValue . includes ( NEXT_EXPORT_COMMAND )
10
15
} )
11
16
return isSetInNetlifyConfig || isSetInNpmScript
12
17
}
Original file line number Diff line number Diff line change @@ -29,7 +29,9 @@ module.exports = {
29
29
const { name, scripts = { } , dependencies = { } } = packageJson
30
30
31
31
if ( isStaticExportProject ( { build, scripts } ) ) {
32
- return failBuild ( `** Static HTML export next.js projects do not require this plugin **` )
32
+ return failBuild (
33
+ `Static HTML export Next.js projects do not require this plugin. Check your project's build command for 'next export'.` ,
34
+ )
33
35
}
34
36
35
37
const hasNextOnNetlifyInstalled = dependencies [ 'next-on-netlify' ] !== undefined
Original file line number Diff line number Diff line change @@ -63,12 +63,25 @@ describe('preBuild()', () => {
63
63
test ( 'fail build if the app has static html export in npm script' , async ( ) => {
64
64
await expect (
65
65
plugin . onPreBuild ( {
66
- netlifyConfig : { } ,
66
+ netlifyConfig : { build : { command : 'npm run build' } } ,
67
67
packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { build : 'next export' } } ,
68
68
utils,
69
69
constants : { FUNCTIONS_SRC : 'out_functions' } ,
70
70
} ) ,
71
- ) . rejects . toThrow ( '** Static HTML export next.js projects do not require this plugin **' )
71
+ ) . rejects . toThrow (
72
+ `Static HTML export Next.js projects do not require this plugin. Check your project's build command for 'next export'.` ,
73
+ )
74
+ } )
75
+
76
+ test ( 'do not fail build if the app has next export in an unused script' , async ( ) => {
77
+ await expect (
78
+ plugin . onPreBuild ( {
79
+ netlifyConfig : { } ,
80
+ packageJson : { ...DUMMY_PACKAGE_JSON , scripts : { export : 'next export' } } ,
81
+ utils,
82
+ constants : { } ,
83
+ } ) ,
84
+ ) . resolves
72
85
} )
73
86
74
87
test ( 'fail build if the app has static html export in toml/ntl config' , async ( ) => {
@@ -79,7 +92,9 @@ describe('preBuild()', () => {
79
92
utils,
80
93
constants : { FUNCTIONS_SRC : 'out_functions' } ,
81
94
} ) ,
82
- ) . rejects . toThrow ( '** Static HTML export next.js projects do not require this plugin **' )
95
+ ) . rejects . toThrow (
96
+ `Static HTML export Next.js projects do not require this plugin. Check your project's build command for 'next export'.` ,
97
+ )
83
98
} )
84
99
85
100
test ( 'fail build if app has next-on-netlify installed' , async ( ) => {
You can’t perform that action at this time.
0 commit comments