Skip to content

fail build if app is using NoN already #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ module.exports = {
return failBuild(`** Static HTML export next.js projects do not require this plugin **`)
}

// TO-DO: check scripts to make sure the app isn't manually running NoN
// For now, we'll make it clear in the README
// const isAlreadyUsingNextOnNetlify = Object.keys(dependencies).find((dep) => dep === 'next-on-netlify');
// if (isAlreadyUsingNextOnNetlify) {
// return failBuild(`This plugin cannot support apps that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.`);
// }
const hasNextOnNetlifyInstalled = dependencies['next-on-netlify'] !== undefined
const hasNextOnNetlifyPostbuildScript =
typeof scripts.postbuild === 'string' && scripts.postbuild.includes('next-on-netlify')
const isAlreadyUsingNextOnNetlify = hasNextOnNetlifyInstalled || hasNextOnNetlifyPostbuildScript
if (isAlreadyUsingNextOnNetlify) {
return failBuild(
`This plugin does not support sites that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.`,
)
}

const nextConfigPath = await findUp('next.config.js')
if (nextConfigPath !== undefined) {
Expand Down
30 changes: 30 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ describe('preBuild()', () => {
).rejects.toThrow('** Static HTML export next.js projects do not require this plugin **')
})

test('fail build if app has next-on-netlify installed', async () => {
const packageJson = {
dependencies: { 'next-on-netlify': '123' },
}
await expect(
plugin.onPreBuild({
netlifyConfig: {},
packageJson,
utils,
}),
).rejects.toThrow(
`This plugin does not support sites that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.`,
)
})

test('fail build if app has next-on-netlify postbuild script', async () => {
const packageJson = {
scripts: { postbuild: 'next-on-netlify' },
}
await expect(
plugin.onPreBuild({
netlifyConfig: {},
packageJson,
utils,
}),
).rejects.toThrow(
`This plugin does not support sites that manually use next-on-netlify. Uninstall next-on-netlify as a dependency to resolve.`,
)
})

test('fail build if the app has no package.json', async () => {
await expect(
plugin.onPreBuild({
Expand Down