Skip to content

chore: revert skipping runtime, revert package name to plugin-nextjs #1548

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 3 commits into from
Aug 17, 2022
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
45 changes: 44 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@netlify/next-runtime",
"name": "@netlify/plugin-nextjs",
"version": "4.17.0",
"description": "Run Next.js seamlessly on Netlify",
"main": "lib/index.js",
Expand Down
13 changes: 1 addition & 12 deletions packages/runtime/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const findModuleFromBase = ({ paths, candidates }): string | null => {

export const isNextAuthInstalled = (): boolean => {
try {
// eslint-disable-next-line import/no-unassigned-import, n/no-extraneous-require, import/no-extraneous-dependencies
// eslint-disable-next-line import/no-unassigned-import, import/no-extraneous-dependencies, n/no-extraneous-require
require('next-auth')
return true
} catch {
Expand All @@ -188,17 +188,6 @@ export const isNextAuthInstalled = (): boolean => {
}
}

export const isOldPluginInstalled = (): boolean => {
try {
// eslint-disable-next-line import/no-unassigned-import, n/no-missing-require, import/no-unresolved
require('@netlify/plugin-nextjs')
return true
} catch {
// Ignore the MODULE_NOT_FOUND error
return false
}
}

export const getCustomImageResponseHeaders = (headers: Header[]): Record<string, string> | null => {
const customImageResponseHeaders = headers.find((header) => header.for?.startsWith('/_next/image/'))

Expand Down
16 changes: 2 additions & 14 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { updateConfig, writeEdgeFunctions, loadMiddlewareManifest } from './help
import { moveStaticPages, movePublicFiles, patchNextFiles } from './helpers/files'
import { generateFunctions, setupImageFunction, generatePagesResolver } from './helpers/functions'
import { generateRedirects, generateStaticRedirects } from './helpers/redirects'
import { shouldSkip, isNextAuthInstalled, isOldPluginInstalled, getCustomImageResponseHeaders } from './helpers/utils'
import { shouldSkip, isNextAuthInstalled, getCustomImageResponseHeaders } from './helpers/utils'
import {
verifyNetlifyBuildVersion,
checkNextSiteHasBuilt,
Expand All @@ -39,10 +39,6 @@ const plugin: NetlifyPlugin = {
cache,
},
}) {
if (isOldPluginInstalled()) {
return
}

const { publish } = netlifyConfig.build
if (shouldSkip()) {
await restoreCache({ cache, publish })
Expand All @@ -69,7 +65,7 @@ const plugin: NetlifyPlugin = {
build: { failBuild },
},
}) {
if (isOldPluginInstalled() || shouldSkip()) {
if (shouldSkip()) {
return
}
const { publish } = netlifyConfig.build
Expand Down Expand Up @@ -182,14 +178,6 @@ const plugin: NetlifyPlugin = {
}) {
await saveCache({ cache, publish })

if (isOldPluginInstalled()) {
status.show({
summary:
'Please remove @netlify/plugin-nextjs from your site. It is no longer required and will prevent you using new features. Learn more: https://ntl.fyi/3w85e2E',
})
return
}

if (shouldSkip()) {
status.show({
title: 'Next Runtime did not run',
Expand Down
44 changes: 2 additions & 42 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ jest.mock('../packages/runtime/src/helpers/utils', () => {
return {
...jest.requireActual('../packages/runtime/src/helpers/utils'),
isNextAuthInstalled: jest.fn(),
isOldPluginInstalled: jest.fn(),
}
})

Expand Down Expand Up @@ -34,6 +33,8 @@ const {
} = require('../packages/runtime/src/helpers/config')
const { dirname } = require('path')
const { getProblematicUserRewrites } = require('../packages/runtime/src/helpers/verification')
const { onPostBuild } = require('../packages/runtime/lib')
const { basePath } = require('../demos/next-i18next/next.config')

const chance = new Chance()
const FIXTURES_DIR = `${__dirname}/fixtures`
Expand Down Expand Up @@ -561,47 +562,6 @@ describe('onBuild()', () => {
})

describe('onPostBuild', () => {
const { isOldPluginInstalled } = require('../packages/runtime/src/helpers/utils')

test('show warning message to remove old plugin', async () => {
isOldPluginInstalled.mockImplementation(() => {
return true
})
const mockStatusFunc = jest.fn()

await nextRuntime.onPostBuild({
...defaultArgs,
utils: { ...utils, status: { show: mockStatusFunc } },
})

expect(mockStatusFunc).toHaveBeenCalledWith({
summary:
'Please remove @netlify/plugin-nextjs from your site. It is no longer required and will prevent you using new features. Learn more: https://ntl.fyi/3w85e2E',
})
})

test('does not show warning message to remove old plugin', async () => {
isOldPluginInstalled.mockImplementation(() => {
return false
})
const mockStatusFunc = jest.fn()
await moveNextDist()

await nextRuntime.onPostBuild({
...defaultArgs,
utils: {
...utils,
status: { show: mockStatusFunc },
functions: { list: jest.fn().mockResolvedValue([]) },
},
})

expect(mockStatusFunc).not.toHaveBeenCalledWith({
summary:
'Please remove @netlify/plugin-nextjs from your site. It is no longer required and will prevent you using new features.',
})
})

test('saves cache with right paths', async () => {
await moveNextDist()

Expand Down