Skip to content

Commit

Permalink
feat(nextjs): update createNodes to createNodesV2 and add deprecation…
Browse files Browse the repository at this point in the history
… message (#28527)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
Currently, we are using `createNodes` API which should be deprecated in
favour of `createNodesV2`.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
We should be using `createNodesV2` instead of `createNodes`.
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
ndcunningham authored Oct 18, 2024
1 parent 8b5ee36 commit 19e765f
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 154 deletions.
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

0 comments on commit 19e765f

Please sign in to comment.