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