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(nextjs): update createNodes to createNodesV2 and add deprecation message #28527

Merged
merged 1 commit into from
Oct 18, 2024
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
6 changes: 5 additions & 1 deletion packages/next/plugin.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { createNodes, NextPluginOptions } from './src/plugins/plugin';
export {
createNodes,
createNodesV2,
NextPluginOptions,
} from './src/plugins/plugin';
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createProjectGraphAsync, formatFiles, Tree } from '@nx/devkit';
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
import {
migrateProjectExecutorsToPluginV1,
migrateProjectExecutorsToPlugin,
NoTargetsToMigrateError,
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { createNodes } from '../../plugins/plugin';
import { createNodesV2 } from '../../plugins/plugin';
import { buildPostTargetTransformer } from './lib/build-post-target-transformer';
import { servePosTargetTransformer } from './lib/serve-post-target-tranformer';

Expand All @@ -17,11 +17,11 @@ export async function convertToInferred(tree: Tree, options: Schema) {
const projectGraph = await createProjectGraphAsync();
const migrationLogs = new AggregatedLog();

const migratedProjects = await migrateProjectExecutorsToPluginV1(
const migratedProjects = await migrateProjectExecutorsToPlugin(
tree,
projectGraph,
'@nx/next/plugin',
createNodes,
createNodesV2,
{
buildTargetName: 'build',
devTargetName: 'dev',
Expand Down
8 changes: 4 additions & 4 deletions packages/next/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
readNxJson,
createProjectGraphAsync,
} from '@nx/devkit';
import { addPluginV1 } from '@nx/devkit/src/utils/add-plugin';
import { addPlugin } from '@nx/devkit/src/utils/add-plugin';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { reactDomVersion, reactVersion } from '@nx/react/src/utils/versions';
import { addGitIgnoreEntry } from '../../utils/add-gitignore-entry';
Expand Down Expand Up @@ -55,12 +55,12 @@ export async function nextInitGeneratorInternal(

schema.addPlugin ??= addPluginDefault;
if (schema.addPlugin) {
const { createNodes } = await import('../../plugins/plugin');
await addPluginV1(
const { createNodesV2 } = await import('../../plugins/plugin');
await addPlugin(
host,
await createProjectGraphAsync(),
'@nx/next/plugin',
createNodes,
createNodesV2,
{
startTargetName: ['start', 'next:start', 'next-start'],
buildTargetName: ['build', 'next:build', 'next-build'],
Expand Down
214 changes: 112 additions & 102 deletions packages/next/src/plugins/__snapshots__/plugin.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,121 +1,131 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@nx/next/plugin integrated projects should create nodes 1`] = `
{
"projects": {
"my-app": {
"root": "my-app",
"targets": {
"my-build": {
"cache": true,
"command": "next build",
"dependsOn": [
"^build",
],
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"next",
[
[
"my-app/next.config.js",
{
"projects": {
"my-app": {
"root": "my-app",
"targets": {
"my-build": {
"cache": true,
"command": "next build",
"dependsOn": [
"^build",
],
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"next",
],
},
],
"options": {
"cwd": "my-app",
"tty": false,
},
"outputs": [
"{workspaceRoot}/my-app/.next",
"{workspaceRoot}/my-app/.next/!(cache)",
],
},
],
"options": {
"cwd": "my-app",
"tty": false,
},
"outputs": [
"{workspaceRoot}/my-app/.next",
"{workspaceRoot}/my-app/.next/!(cache)",
],
},
"my-serve": {
"command": "next dev",
"options": {
"cwd": "my-app",
},
},
"my-serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "my-build",
"port": 3000,
"spa": false,
"staticFilePath": "{projectRoot}/out",
},
},
"my-start": {
"command": "next start",
"dependsOn": [
"my-build",
],
"options": {
"cwd": "my-app",
"my-serve": {
"command": "next dev",
"options": {
"cwd": "my-app",
},
},
"my-serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "my-build",
"port": 3000,
"spa": false,
"staticFilePath": "{projectRoot}/out",
},
},
"my-start": {
"command": "next start",
"dependsOn": [
"my-build",
],
"options": {
"cwd": "my-app",
},
},
},
},
},
},
},
}
],
]
`;

exports[`@nx/next/plugin root projects should create nodes 1`] = `
{
"projects": {
".": {
"root": ".",
"targets": {
"build": {
"cache": true,
"command": "next build",
"dependsOn": [
"^build",
],
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"next",
[
[
"next.config.js",
{
"projects": {
".": {
"root": ".",
"targets": {
"build": {
"cache": true,
"command": "next build",
"dependsOn": [
"^build",
],
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"next",
],
},
],
"options": {
"cwd": ".",
"tty": false,
},
"outputs": [
"{projectRoot}/.next",
"{projectRoot}/.next/!(cache)",
],
},
],
"options": {
"cwd": ".",
"tty": false,
},
"outputs": [
"{projectRoot}/.next",
"{projectRoot}/.next/!(cache)",
],
},
"dev": {
"command": "next dev",
"options": {
"cwd": ".",
},
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build",
"port": 3000,
"spa": false,
"staticFilePath": "{projectRoot}/out",
},
},
"start": {
"command": "next start",
"dependsOn": [
"build",
],
"options": {
"cwd": ".",
"dev": {
"command": "next dev",
"options": {
"cwd": ".",
},
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build",
"port": 3000,
"spa": false,
"staticFilePath": "{projectRoot}/out",
},
},
"start": {
"command": "next start",
"dependsOn": [
"build",
],
"options": {
"cwd": ".",
},
},
},
},
},
},
},
}
],
]
`;
8 changes: 4 additions & 4 deletions packages/next/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CreateNodesContext } from '@nx/devkit';
import type { NextConfig } from 'next';

import { createNodes } from './plugin';
import { createNodesV2 } from './plugin';
import { TempFs } from '@nx/devkit/internal-testing-utils';

describe('@nx/next/plugin', () => {
let createNodesFunction = createNodes[1];
let createNodesFunction = createNodesV2[1];
let context: CreateNodesContext;

describe('root projects', () => {
Expand All @@ -30,7 +30,7 @@ describe('@nx/next/plugin', () => {
const nextConfigPath = 'next.config.js';
mockNextConfig(nextConfigPath, {});
const nodes = await createNodesFunction(
nextConfigPath,
[nextConfigPath],
{
buildTargetName: 'build',
devTargetName: 'dev',
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('@nx/next/plugin', () => {
it('should create nodes', async () => {
mockNextConfig('my-app/next.config.js', {});
const nodes = await createNodesFunction(
'my-app/next.config.js',
['my-app/next.config.js'],
{
buildTargetName: 'my-build',
devTargetName: 'my-serve',
Expand Down
Loading