Skip to content
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

feat(build): support new @opennextjs/netlify plugin name #5897

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion packages/build-info/src/build-systems/nx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('nx-integrated project.json based', () => {
frameworkPort: 4200,
name: `Nx + Next.js ${join('packages/website')}`,
packagePath: join('packages/website'),
plugins_recommended: ['@netlify/plugin-nextjs'],
plugins_recommended: ['@opennextjs/netlify'],
}),
]),
)
Expand Down
8 changes: 4 additions & 4 deletions packages/build-info/src/frameworks/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Next.js Plugin', () => {
const project = new Project(fs, cwd).setNodeVersion('v10.13.0')
const frameworks = await project.detectFrameworks()
expect(frameworks?.[0].id).toBe('next')
expect(frameworks?.[0].plugins).toEqual(['@netlify/plugin-nextjs'])
expect(frameworks?.[0].plugins).toEqual(['@opennextjs/netlify'])
})

test('Should not detect Next.js plugin for Next.js if when Node version < 10.13.0', async ({ fs, cwd }) => {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('simple Next.js project', async () => {
test('Should detect Next.js plugin for Next.js if when Node version >= 10.13.0', async ({ fs, cwd }) => {
const detected = await new Project(fs, cwd).setEnvironment({ NODE_VERSION: '18.x' }).detectFrameworks()
expect(detected?.[0].id).toBe('next')
expect(detected?.[0].plugins).toMatchObject(['@netlify/plugin-nextjs'])
expect(detected?.[0].plugins).toMatchObject(['@opennextjs/netlify'])
})
})

Expand Down Expand Up @@ -134,7 +134,7 @@ describe('Nx monorepo', () => {
devCommand: 'nx run website:serve',
dist: join('dist/packages/website/.next'),
frameworkPort: 4200,
plugins_recommended: ['@netlify/plugin-nextjs'],
plugins_recommended: ['@opennextjs/netlify'],
})
})
})
Expand All @@ -152,7 +152,7 @@ describe('Nx turborepo', () => {
devCommand: 'turbo run dev --filter web',
dist: join('apps/web/.next'),
frameworkPort: 3000,
plugins_recommended: ['@netlify/plugin-nextjs'],
plugins_recommended: ['@opennextjs/netlify'],
})
})
})
2 changes: 1 addition & 1 deletion packages/build-info/src/frameworks/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Next extends BaseFramework implements Framework {
if (this.detected) {
const nodeVersion = await this.project.getCurrentNodeVersion()
if (nodeVersion && gte(nodeVersion, '10.13.0')) {
this.plugins.push('@netlify/plugin-nextjs')
this.plugins.push('@opennextjs/netlify')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use new package name for next@>=13.5.1 only and otherwise use old version?

}
return this as DetectedFramework
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ exports[`should retrieve the build info for providing a rootDir 1`] = `
"packagePath": "packages/website",
"plugins_from_config_file": [],
"plugins_recommended": [
"@netlify/plugin-nextjs",
"@opennextjs/netlify",
],
"pollingStrategies": [
"TCP",
Expand Down Expand Up @@ -290,7 +290,7 @@ exports[`should retrieve the build info for providing a rootDir and the same pro
"packagePath": "packages/website",
"plugins_from_config_file": [],
"plugins_recommended": [
"@netlify/plugin-nextjs",
"@opennextjs/netlify",
],
"pollingStrategies": [
"TCP",
Expand Down
22 changes: 11 additions & 11 deletions packages/build/src/log/messages/compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import semver from 'semver'

import { isRuntime } from '../../utils/runtime.js'
import { isNextJsAdapter } from '../../utils/runtime.js'
import { isPreviousMajor } from '../../utils/semver.js'
import { getPluginOrigin } from '../description.js'
import { BufferedLogs, logArray, logSubHeader, logWarningArray, logWarningSubHeader } from '../logger.js'
import { THEME } from '../theme.js'

export const logRuntime = (logs, pluginOptions) => {
const runtimes = pluginOptions.filter(isRuntime)
export const logRuntime = (logs: BufferedLogs | undefined, pluginOptions) => {
const runtimes = pluginOptions.filter(isNextJsAdapter)

// Once we have more runtimes, this hardcoded check should be removed
if (runtimes.length !== 0) {
const [nextRuntime] = runtimes

logSubHeader(logs, `Using Next.js Runtime - v${nextRuntime.pluginPackageJson.version}`)
logSubHeader(logs, `Using Next.js adapter - v${nextRuntime.pluginPackageJson.version}`)
}
}

export const logLoadingIntegration = (logs, pluginOptions) => {
export const logLoadingIntegration = (logs: BufferedLogs | undefined, pluginOptions) => {
const loadingPlugins = pluginOptions
.filter((plugin) => plugin.isIntegration)
.map((pluginOptions) => pluginOptions.integration?.slug ?? 'no-slug')
Expand All @@ -30,11 +30,11 @@ export const logLoadingIntegration = (logs, pluginOptions) => {
logArray(logs, loadingPlugins)
}

export const logLoadingPlugins = function (logs, pluginsOptions, debug) {
export const logLoadingPlugins = function (logs: BufferedLogs | undefined, pluginsOptions, debug: boolean) {
const loadingPlugins = pluginsOptions
.filter(isNotCorePlugin)
// We don't want to show runtimes as plugins
.filter((plugin) => !isRuntime(plugin))
// We log these separately
.filter((plugin) => !isNextJsAdapter(plugin))
.filter((p) => !p.isIntegration)
.map((pluginOptions) => getPluginDescription(pluginOptions, debug))

Expand Down Expand Up @@ -62,7 +62,7 @@ const getPluginDescription = function (
expectedVersion,
compatibleVersion,
},
debug,
debug: boolean,
) {
const versionedPackage = getVersionedPackage(version)
const pluginOrigin = getPluginOrigin(loadedFrom, origin)
Expand Down Expand Up @@ -97,7 +97,7 @@ const getVersionField = function ([versionFieldName, version]) {

// Print a warning message when old versions plugins are used.
// This can only happen when they are installed to `package.json`.
export const logOutdatedPlugins = function (logs: BufferedLogs, pluginsOptions) {
export const logOutdatedPlugins = function (logs: BufferedLogs | undefined, pluginsOptions) {
const outdatedPlugins = pluginsOptions.filter(hasOutdatedVersion).map(getOutdatedPlugin)

if (outdatedPlugins.length === 0) {
Expand Down Expand Up @@ -149,7 +149,7 @@ const getUpgradeInstruction = function (loadedFrom, origin) {
// Print a warning message when plugins are using a version that is too recent
// and does not meet some `compatibility` expectations.
// This can only happen when they are installed to `package.json`.
export const logIncompatiblePlugins = function (logs, pluginsOptions) {
export const logIncompatiblePlugins = function (logs: BufferedLogs | undefined, pluginsOptions) {
const incompatiblePlugins = pluginsOptions.filter(hasIncompatibleVersion).map(getIncompatiblePlugin)

if (incompatiblePlugins.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/log/messages/install.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isRuntime } from '../../utils/runtime.js'
import { isNextJsAdapter } from '../../utils/runtime.js'
import { log, logArray, logSubHeader } from '../logger.js'

export const logInstallMissingPlugins = function (logs, missingPlugins, packages) {
const plugins = missingPlugins.filter((pkg) => !isRuntime(pkg))
const plugins = missingPlugins.filter((pkg) => !isNextJsAdapter(pkg))

if (plugins.length !== 0) {
logSubHeader(logs, 'Installing plugins')
Expand Down
12 changes: 12 additions & 0 deletions packages/build/src/plugins/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ const tStartPlugins = async function ({
systemLog,
systemLogFile,
featureFlags,
}: {
// TODO(serhalp) Add return type to `resolvePluginsPath` in `plugins/resolve.js`
// and `loadPluginFiles` in `plugins/options.ts`.
pluginsOptions: any[]
buildDir: string
childEnv: Record<string, string>
logs: BufferedLogs | undefined
debug: boolean
quiet: boolean
systemLog: SystemLogger
systemLogFile: number
featureFlags: FeatureFlags
}) {
if (!quiet) {
logRuntime(logs, pluginsOptions)
Expand Down
5 changes: 0 additions & 5 deletions packages/build/src/utils/runtime.js

This file was deleted.

12 changes: 12 additions & 0 deletions packages/build/src/utils/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const isNextJsAdapter = (pluginOption: { packageName: string }) => {
const { packageName } = pluginOption
// Make this a bit more robust in the future
return [
// Name used up until v5.8.1
'@netlify/plugin-nextjs',
// Name briefly used for v5 prereleases, but then backed out of before stable
'@netlify/next-runtime',
// Renamed starting at v5.9.0
'@opennextjs/netlify',
].includes(packageName)
}
2 changes: 1 addition & 1 deletion packages/framework-info/tests/detect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (nodeVersion !== 'v8.3.0') {
test('Should detect Next.js plugin for Next.js if when Node version >= 10.13.0', async () => {
const frameworks = await getFrameworks('next-plugin')
expect(frameworks[0].id).toBe('next')
expect(frameworks[0].plugins).toEqual(['@netlify/plugin-nextjs'])
expect(frameworks[0].plugins).toEqual(['@opennextjs/netlify'])
})
}

Expand Down
Loading