File tree 2 files changed +39
-6
lines changed
2 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -31,12 +31,15 @@ module.exports = {
31
31
return failBuild ( `** Static HTML export next.js projects do not require this plugin **` )
32
32
}
33
33
34
- // TO-DO: check scripts to make sure the app isn't manually running NoN
35
- // For now, we'll make it clear in the README
36
- // const isAlreadyUsingNextOnNetlify = Object.keys(dependencies).find((dep) => dep === 'next-on-netlify');
37
- // if (isAlreadyUsingNextOnNetlify) {
38
- // return failBuild(`This plugin cannot support apps that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.`);
39
- // }
34
+ const hasNextOnNetlifyInstalled = dependencies [ 'next-on-netlify' ] !== undefined
35
+ const hasNextOnNetlifyPostbuildScript =
36
+ typeof scripts . postbuild === 'string' && scripts . postbuild . includes ( 'next-on-netlify' )
37
+ const isAlreadyUsingNextOnNetlify = hasNextOnNetlifyInstalled || hasNextOnNetlifyPostbuildScript
38
+ if ( isAlreadyUsingNextOnNetlify ) {
39
+ return failBuild (
40
+ `This plugin does not support sites that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.` ,
41
+ )
42
+ }
40
43
41
44
const nextConfigPath = await findUp ( 'next.config.js' )
42
45
if ( nextConfigPath !== undefined ) {
Original file line number Diff line number Diff line change @@ -83,6 +83,36 @@ describe('preBuild()', () => {
83
83
) . rejects . toThrow ( '** Static HTML export next.js projects do not require this plugin **' )
84
84
} )
85
85
86
+ test ( 'fail build if app has next-on-netlify installed' , async ( ) => {
87
+ const packageJson = {
88
+ dependencies : { 'next-on-netlify' : '123' } ,
89
+ }
90
+ await expect (
91
+ plugin . onPreBuild ( {
92
+ netlifyConfig : { } ,
93
+ packageJson,
94
+ utils,
95
+ } ) ,
96
+ ) . rejects . toThrow (
97
+ `This plugin does not support sites that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.` ,
98
+ )
99
+ } )
100
+
101
+ test ( 'fail build if app has next-on-netlify postbuild script' , async ( ) => {
102
+ const packageJson = {
103
+ scripts : { postbuild : 'next-on-netlify' } ,
104
+ }
105
+ await expect (
106
+ plugin . onPreBuild ( {
107
+ netlifyConfig : { } ,
108
+ packageJson,
109
+ utils,
110
+ } ) ,
111
+ ) . rejects . toThrow (
112
+ `This plugin does not support sites that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.` ,
113
+ )
114
+ } )
115
+
86
116
test ( 'fail build if the app has no package.json' , async ( ) => {
87
117
await expect (
88
118
plugin . onPreBuild ( {
You can’t perform that action at this time.
0 commit comments