Skip to content

Commit f1462fb

Browse files
committed
fail build if app is using NoN already
1 parent 24b42fc commit f1462fb

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ module.exports = {
3737
return failBuild(`** Static HTML export next.js projects do not require this plugin **`)
3838
}
3939

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+
}
4650

4751
const nextConfigPath = await findUp('next.config.js')
4852
if (nextConfigPath !== undefined) {

test/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,36 @@ describe('preBuild()', () => {
8282
).rejects.toThrow('** Static HTML export next.js projects do not require this plugin **')
8383
})
8484

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+
85115
test('fail build if the app has no package.json', async () => {
86116
await expect(
87117
plugin.onPreBuild({

0 commit comments

Comments
 (0)