Skip to content

Commit f50efb3

Browse files
fail build if app is using NoN already (#52)
1 parent 487bb22 commit f50efb3

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

index.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ module.exports = {
3131
return failBuild(`** Static HTML export next.js projects do not require this plugin **`)
3232
}
3333

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

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

test/index.js

+30
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,36 @@ describe('preBuild()', () => {
8383
).rejects.toThrow('** Static HTML export next.js projects do not require this plugin **')
8484
})
8585

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

0 commit comments

Comments
 (0)