From 3d463e1f388df69a092d8170bceb69c99326be0a Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Wed, 17 Aug 2022 16:21:11 -0400 Subject: [PATCH 1/3] feat: revert "feat: skip run if @netlify/plugin-nextjs installed (#1536)" This reverts commit 0b4cf8c6df7745fed91a59b90ab0e9f7f909b033. --- packages/runtime/src/helpers/utils.ts | 13 +------- packages/runtime/src/index.ts | 16 ++-------- test/index.js | 44 ++------------------------- 3 files changed, 5 insertions(+), 68 deletions(-) diff --git a/packages/runtime/src/helpers/utils.ts b/packages/runtime/src/helpers/utils.ts index 595d3a900a..ce7ad946db 100644 --- a/packages/runtime/src/helpers/utils.ts +++ b/packages/runtime/src/helpers/utils.ts @@ -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 require('next-auth') return true } catch { @@ -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 | null => { const customImageResponseHeaders = headers.find((header) => header.for?.startsWith('/_next/image/')) diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index 2915ba2763..071d31297a 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -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, @@ -39,10 +39,6 @@ const plugin: NetlifyPlugin = { cache, }, }) { - if (isOldPluginInstalled()) { - return - } - const { publish } = netlifyConfig.build if (shouldSkip()) { await restoreCache({ cache, publish }) @@ -69,7 +65,7 @@ const plugin: NetlifyPlugin = { build: { failBuild }, }, }) { - if (isOldPluginInstalled() || shouldSkip()) { + if (shouldSkip()) { return } const { publish } = netlifyConfig.build @@ -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', diff --git a/test/index.js b/test/index.js index 83b2215a2d..e071c23b10 100644 --- a/test/index.js +++ b/test/index.js @@ -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(), } }) @@ -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` @@ -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() From 02b74e468cedcee72b56d0a6d711f6c6d6fa8d87 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Wed, 17 Aug 2022 16:25:47 -0400 Subject: [PATCH 2/3] feat: changing back package.json to plugin-nextjs --- package-lock.json | 45 ++++++++++++++++++++++++++++++++++- packages/runtime/package.json | 2 +- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index b8a1604bbb..cfbb711a97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4266,6 +4266,10 @@ "integrity": "sha512-ni6R1xdR8EtH0iB8ixGt9ocuboW+Q8eN4ilTX8lfNHS6Y6Q2S+O/aB2n1BnAgv39wopeQsQ2meL9vfEePURl7w==", "dev": true }, + "node_modules/@netlify/plugin-nextjs": { + "resolved": "packages/runtime", + "link": true + }, "node_modules/@netlify/plugins-list": { "version": "6.36.0", "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.36.0.tgz", @@ -22954,7 +22958,7 @@ } }, "packages/runtime": { - "name": "@netlify/next-runtime", + "name": "@netlify/plugin-nextjs", "version": "4.17.0", "license": "MIT", "dependencies": { @@ -25851,6 +25855,45 @@ "integrity": "sha512-ni6R1xdR8EtH0iB8ixGt9ocuboW+Q8eN4ilTX8lfNHS6Y6Q2S+O/aB2n1BnAgv39wopeQsQ2meL9vfEePURl7w==", "dev": true }, + "@netlify/plugin-nextjs": { + "version": "file:packages/runtime", + "requires": { + "@delucis/if-env": "^1.1.2", + "@netlify/build": "^27.14.0", + "@netlify/functions": "^1.2.0", + "@netlify/ipx": "^1.2.2", + "@types/fs-extra": "^9.0.13", + "@types/jest": "^27.4.1", + "@types/node": "^17.0.25", + "@vercel/node-bridge": "^2.1.0", + "chalk": "^4.1.2", + "fs-extra": "^10.0.0", + "globby": "^11.0.4", + "moize": "^6.1.0", + "next": "^12.2.0", + "node-fetch": "^2.6.6", + "node-stream-zip": "^1.15.0", + "npm-run-all": "^4.1.5", + "outdent": "^0.8.0", + "p-limit": "^3.1.0", + "pathe": "^0.2.0", + "pretty-bytes": "^5.6.0", + "semver": "^7.3.5", + "slash": "^3.0.0", + "tiny-glob": "^0.2.9", + "typescript": "^4.6.3" + }, + "dependencies": { + "semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "@netlify/plugins-list": { "version": "6.36.0", "resolved": "https://registry.npmjs.org/@netlify/plugins-list/-/plugins-list-6.36.0.tgz", diff --git a/packages/runtime/package.json b/packages/runtime/package.json index a8b5b0bbc4..f5ef17a6ce 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -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", From 6176ca69b8a11f064bedd8296802dcc010bddb46 Mon Sep 17 00:00:00 2001 From: Sarah Etter Date: Wed, 17 Aug 2022 16:27:54 -0400 Subject: [PATCH 3/3] chore: lint fix --- packages/runtime/src/helpers/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/helpers/utils.ts b/packages/runtime/src/helpers/utils.ts index ce7ad946db..1aa185b686 100644 --- a/packages/runtime/src/helpers/utils.ts +++ b/packages/runtime/src/helpers/utils.ts @@ -179,7 +179,7 @@ export const findModuleFromBase = ({ paths, candidates }): string | null => { export const isNextAuthInstalled = (): boolean => { try { - // eslint-disable-next-line import/no-unassigned-import + // eslint-disable-next-line import/no-unassigned-import, import/no-extraneous-dependencies, n/no-extraneous-require require('next-auth') return true } catch {