Skip to content

Commit 19e765f

Browse files
authored
feat(nextjs): update createNodes to createNodesV2 and add deprecation message (nrwl#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 #
1 parent 8b5ee36 commit 19e765f

File tree

6 files changed

+227
-154
lines changed

6 files changed

+227
-154
lines changed

packages/next/plugin.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export { createNodes, NextPluginOptions } from './src/plugins/plugin';
1+
export {
2+
createNodes,
3+
createNodesV2,
4+
NextPluginOptions,
5+
} from './src/plugins/plugin';

packages/next/src/generators/convert-to-inferred/convert-to-inferred.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createProjectGraphAsync, formatFiles, Tree } from '@nx/devkit';
22
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
33
import {
4-
migrateProjectExecutorsToPluginV1,
4+
migrateProjectExecutorsToPlugin,
55
NoTargetsToMigrateError,
66
} from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
7-
import { createNodes } from '../../plugins/plugin';
7+
import { createNodesV2 } from '../../plugins/plugin';
88
import { buildPostTargetTransformer } from './lib/build-post-target-transformer';
99
import { servePosTargetTransformer } from './lib/serve-post-target-tranformer';
1010

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

20-
const migratedProjects = await migrateProjectExecutorsToPluginV1(
20+
const migratedProjects = await migrateProjectExecutorsToPlugin(
2121
tree,
2222
projectGraph,
2323
'@nx/next/plugin',
24-
createNodes,
24+
createNodesV2,
2525
{
2626
buildTargetName: 'build',
2727
devTargetName: 'dev',

packages/next/src/generators/init/init.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
readNxJson,
88
createProjectGraphAsync,
99
} from '@nx/devkit';
10-
import { addPluginV1 } from '@nx/devkit/src/utils/add-plugin';
10+
import { addPlugin } from '@nx/devkit/src/utils/add-plugin';
1111
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1212
import { reactDomVersion, reactVersion } from '@nx/react/src/utils/versions';
1313
import { addGitIgnoreEntry } from '../../utils/add-gitignore-entry';
@@ -55,12 +55,12 @@ export async function nextInitGeneratorInternal(
5555

5656
schema.addPlugin ??= addPluginDefault;
5757
if (schema.addPlugin) {
58-
const { createNodes } = await import('../../plugins/plugin');
59-
await addPluginV1(
58+
const { createNodesV2 } = await import('../../plugins/plugin');
59+
await addPlugin(
6060
host,
6161
await createProjectGraphAsync(),
6262
'@nx/next/plugin',
63-
createNodes,
63+
createNodesV2,
6464
{
6565
startTargetName: ['start', 'next:start', 'next-start'],
6666
buildTargetName: ['build', 'next:build', 'next-build'],
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,131 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`@nx/next/plugin integrated projects should create nodes 1`] = `
4-
{
5-
"projects": {
6-
"my-app": {
7-
"root": "my-app",
8-
"targets": {
9-
"my-build": {
10-
"cache": true,
11-
"command": "next build",
12-
"dependsOn": [
13-
"^build",
14-
],
15-
"inputs": [
16-
"default",
17-
"^production",
18-
{
19-
"externalDependencies": [
20-
"next",
4+
[
5+
[
6+
"my-app/next.config.js",
7+
{
8+
"projects": {
9+
"my-app": {
10+
"root": "my-app",
11+
"targets": {
12+
"my-build": {
13+
"cache": true,
14+
"command": "next build",
15+
"dependsOn": [
16+
"^build",
17+
],
18+
"inputs": [
19+
"default",
20+
"^production",
21+
{
22+
"externalDependencies": [
23+
"next",
24+
],
25+
},
26+
],
27+
"options": {
28+
"cwd": "my-app",
29+
"tty": false,
30+
},
31+
"outputs": [
32+
"{workspaceRoot}/my-app/.next",
33+
"{workspaceRoot}/my-app/.next/!(cache)",
2134
],
2235
},
23-
],
24-
"options": {
25-
"cwd": "my-app",
26-
"tty": false,
27-
},
28-
"outputs": [
29-
"{workspaceRoot}/my-app/.next",
30-
"{workspaceRoot}/my-app/.next/!(cache)",
31-
],
32-
},
33-
"my-serve": {
34-
"command": "next dev",
35-
"options": {
36-
"cwd": "my-app",
37-
},
38-
},
39-
"my-serve-static": {
40-
"executor": "@nx/web:file-server",
41-
"options": {
42-
"buildTarget": "my-build",
43-
"port": 3000,
44-
"spa": false,
45-
"staticFilePath": "{projectRoot}/out",
46-
},
47-
},
48-
"my-start": {
49-
"command": "next start",
50-
"dependsOn": [
51-
"my-build",
52-
],
53-
"options": {
54-
"cwd": "my-app",
36+
"my-serve": {
37+
"command": "next dev",
38+
"options": {
39+
"cwd": "my-app",
40+
},
41+
},
42+
"my-serve-static": {
43+
"executor": "@nx/web:file-server",
44+
"options": {
45+
"buildTarget": "my-build",
46+
"port": 3000,
47+
"spa": false,
48+
"staticFilePath": "{projectRoot}/out",
49+
},
50+
},
51+
"my-start": {
52+
"command": "next start",
53+
"dependsOn": [
54+
"my-build",
55+
],
56+
"options": {
57+
"cwd": "my-app",
58+
},
59+
},
5560
},
5661
},
5762
},
5863
},
59-
},
60-
}
64+
],
65+
]
6166
`;
6267

6368
exports[`@nx/next/plugin root projects should create nodes 1`] = `
64-
{
65-
"projects": {
66-
".": {
67-
"root": ".",
68-
"targets": {
69-
"build": {
70-
"cache": true,
71-
"command": "next build",
72-
"dependsOn": [
73-
"^build",
74-
],
75-
"inputs": [
76-
"default",
77-
"^production",
78-
{
79-
"externalDependencies": [
80-
"next",
69+
[
70+
[
71+
"next.config.js",
72+
{
73+
"projects": {
74+
".": {
75+
"root": ".",
76+
"targets": {
77+
"build": {
78+
"cache": true,
79+
"command": "next build",
80+
"dependsOn": [
81+
"^build",
82+
],
83+
"inputs": [
84+
"default",
85+
"^production",
86+
{
87+
"externalDependencies": [
88+
"next",
89+
],
90+
},
91+
],
92+
"options": {
93+
"cwd": ".",
94+
"tty": false,
95+
},
96+
"outputs": [
97+
"{projectRoot}/.next",
98+
"{projectRoot}/.next/!(cache)",
8199
],
82100
},
83-
],
84-
"options": {
85-
"cwd": ".",
86-
"tty": false,
87-
},
88-
"outputs": [
89-
"{projectRoot}/.next",
90-
"{projectRoot}/.next/!(cache)",
91-
],
92-
},
93-
"dev": {
94-
"command": "next dev",
95-
"options": {
96-
"cwd": ".",
97-
},
98-
},
99-
"serve-static": {
100-
"executor": "@nx/web:file-server",
101-
"options": {
102-
"buildTarget": "build",
103-
"port": 3000,
104-
"spa": false,
105-
"staticFilePath": "{projectRoot}/out",
106-
},
107-
},
108-
"start": {
109-
"command": "next start",
110-
"dependsOn": [
111-
"build",
112-
],
113-
"options": {
114-
"cwd": ".",
101+
"dev": {
102+
"command": "next dev",
103+
"options": {
104+
"cwd": ".",
105+
},
106+
},
107+
"serve-static": {
108+
"executor": "@nx/web:file-server",
109+
"options": {
110+
"buildTarget": "build",
111+
"port": 3000,
112+
"spa": false,
113+
"staticFilePath": "{projectRoot}/out",
114+
},
115+
},
116+
"start": {
117+
"command": "next start",
118+
"dependsOn": [
119+
"build",
120+
],
121+
"options": {
122+
"cwd": ".",
123+
},
124+
},
115125
},
116126
},
117127
},
118128
},
119-
},
120-
}
129+
],
130+
]
121131
`;

packages/next/src/plugins/plugin.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { CreateNodesContext } from '@nx/devkit';
22
import type { NextConfig } from 'next';
33

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

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

1111
describe('root projects', () => {
@@ -30,7 +30,7 @@ describe('@nx/next/plugin', () => {
3030
const nextConfigPath = 'next.config.js';
3131
mockNextConfig(nextConfigPath, {});
3232
const nodes = await createNodesFunction(
33-
nextConfigPath,
33+
[nextConfigPath],
3434
{
3535
buildTargetName: 'build',
3636
devTargetName: 'dev',
@@ -71,7 +71,7 @@ describe('@nx/next/plugin', () => {
7171
it('should create nodes', async () => {
7272
mockNextConfig('my-app/next.config.js', {});
7373
const nodes = await createNodesFunction(
74-
'my-app/next.config.js',
74+
['my-app/next.config.js'],
7575
{
7676
buildTargetName: 'my-build',
7777
devTargetName: 'my-serve',

0 commit comments

Comments
 (0)