Skip to content

Commit 698fe18

Browse files
committed
feat: skip run if @netlify/plugin-nextjs installed
disable in order to avoid conflicts should the old package be installed in the project.
1 parent 5a6b021 commit 698fe18

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

packages/runtime/src/helpers/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ export const isNextAuthInstalled = (): boolean => {
188188
}
189189
}
190190

191+
export const isOldPluginInstalled = (): boolean => {
192+
try {
193+
// eslint-disable-next-line import/no-unassigned-import, import/no-extraneous-dependencies, n/no-extraneous-require
194+
require('@netlify/plugin-nextjs')
195+
return true
196+
} catch {
197+
// Ignore the MODULE_NOT_FOUND error
198+
return false
199+
}
200+
}
201+
191202
export const getCustomImageResponseHeaders = (headers: Header[]): Record<string, string> | null => {
192203
const customImageResponseHeaders = headers.find((header) => header.for?.startsWith('/_next/image/'))
193204

packages/runtime/src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { updateConfig, writeEdgeFunctions, loadMiddlewareManifest } from './help
1919
import { moveStaticPages, movePublicFiles, patchNextFiles, unpatchNextFiles } from './helpers/files'
2020
import { generateFunctions, setupImageFunction, generatePagesResolver } from './helpers/functions'
2121
import { generateRedirects, generateStaticRedirects } from './helpers/redirects'
22-
import { shouldSkip, isNextAuthInstalled, getCustomImageResponseHeaders } from './helpers/utils'
22+
import { shouldSkip, isNextAuthInstalled, isOldPluginInstalled, getCustomImageResponseHeaders } from './helpers/utils'
2323
import {
2424
verifyNetlifyBuildVersion,
2525
checkNextSiteHasBuilt,
@@ -39,6 +39,10 @@ const plugin: NetlifyPlugin = {
3939
cache,
4040
},
4141
}) {
42+
if (isOldPluginInstalled()) {
43+
return
44+
}
45+
4246
const { publish } = netlifyConfig.build
4347
if (shouldSkip()) {
4448
await restoreCache({ cache, publish })
@@ -65,7 +69,7 @@ const plugin: NetlifyPlugin = {
6569
build: { failBuild },
6670
},
6771
}) {
68-
if (shouldSkip()) {
72+
if (isOldPluginInstalled() || shouldSkip()) {
6973
return
7074
}
7175
const { publish } = netlifyConfig.build
@@ -178,6 +182,14 @@ const plugin: NetlifyPlugin = {
178182
}) {
179183
await saveCache({ cache, publish })
180184

185+
if (isOldPluginInstalled()) {
186+
status.show({
187+
summary:
188+
'Please remove @netlify/plugin-nextjs from your site. It is no longer required and will prevent you using new features.',
189+
})
190+
return
191+
}
192+
181193
if (shouldSkip()) {
182194
status.show({
183195
title: 'Essential Next.js plugin did not run',

test/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ jest.mock('../packages/runtime/src/helpers/utils', () => {
22
return {
33
...jest.requireActual('../packages/runtime/src/helpers/utils'),
44
isNextAuthInstalled: jest.fn(),
5+
isOldPluginInstalled: jest.fn(),
56
}
67
})
78

@@ -33,8 +34,6 @@ const {
3334
} = require('../packages/runtime/src/helpers/config')
3435
const { dirname } = require('path')
3536
const { getProblematicUserRewrites } = require('../packages/runtime/src/helpers/verification')
36-
const { onPostBuild } = require('../packages/runtime/lib')
37-
const { basePath } = require('../demos/next-i18next/next.config')
3837

3938
const chance = new Chance()
4039
const FIXTURES_DIR = `${__dirname}/fixtures`

0 commit comments

Comments
 (0)