Skip to content

Commit 30818fc

Browse files
committed
fix(nx-dev): build nx-dev in-place to fix ai package resolution
The `@nx/next:build` executor generates a standalone `package.json` at `outputPath`, which clobbers source files when building in-place and breaks package resolution when building to a separate directory. Switch to using the inferred `next:build` target from `@nx/next/plugin` which runs `next build` directly in the project directory. The `build` target now runs `next build` + sitemap generation as sequential commands in a single target to avoid Nx output management cleaning `.next/` between dependent tasks. Also fixes missing `@nx/nx-dev-ui-icons` dependency in `ui-video-courses` introduced by #34669. Fixes DOC-418
1 parent cb6452c commit 30818fc

File tree

9 files changed

+108
-278
lines changed

9 files changed

+108
-278
lines changed

nx-dev/nx-dev/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Build output from next build
2+
.next/
3+
4+
# Generated by next-sitemap during build
5+
public/robots.txt
6+
public/sitemap*.xml

nx-dev/nx-dev/next-sitemap.config.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@ const path = require('path');
33
const siteUrl = process.env.NX_DEV_URL || 'https://nx.dev';
44
const noIndex = process.env.NEXT_PUBLIC_NO_INDEX === 'true';
55

6-
// On Netlify, the build output is in nx-dev/nx-dev/.next instead of dist/nx-dev/nx-dev/.next
7-
const isNetlify = process.env.NETLIFY === 'true';
8-
const buildOutputDir = isNetlify
9-
? path.resolve(__dirname, '.next')
10-
: path.resolve(__dirname, '../../dist/nx-dev/nx-dev/.next');
11-
const publicOutputDir = isNetlify
12-
? path.resolve(__dirname, 'public')
13-
: path.resolve(__dirname, '../../dist/nx-dev/nx-dev/public');
6+
const buildOutputDir = path.resolve(__dirname, '.next');
7+
const publicOutputDir = path.resolve(__dirname, 'public');
148

159
/**
1610
* @type {import('next-sitemap').IConfig}

nx-dev/nx-dev/project.json

Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,43 @@
44
"sourceRoot": "nx-dev/nx-dev",
55
"projectType": "application",
66
"targets": {
7+
"next:build": {
8+
"dependsOn": ["copy-docs", "prebuild-banner"],
9+
"inputs": [
10+
"production",
11+
"^production",
12+
"{projectRoot}/lib/banner.json",
13+
{ "env": "NEXT_PUBLIC_ASTRO_URL" }
14+
]
15+
},
716
"build": {
8-
"dependsOn": [
9-
{
10-
"target": "build-base"
11-
}
12-
],
17+
"dependsOn": ["copy-docs", "prebuild-banner"],
1318
"executor": "nx:run-commands",
1419
"options": {
15-
"commands": ["nx run nx-dev:sitemap"],
20+
"commands": [
21+
{ "command": "next build", "description": "Build Next.js app" },
22+
{
23+
"command": "pnpm next-sitemap --config ./next-sitemap.config.js && node ./scripts/patch-sitemap-index.mjs",
24+
"description": "Generate sitemap"
25+
}
26+
],
27+
"cwd": "nx-dev/nx-dev",
1628
"parallel": false
1729
},
1830
"inputs": [
1931
"production",
2032
"^production",
21-
{ "env": "NEXT_PUBLIC_ASTRO_URL" }
33+
"{projectRoot}/lib/banner.json",
34+
"{projectRoot}/next-sitemap.config.js",
35+
{ "env": "NEXT_PUBLIC_ASTRO_URL" },
36+
{ "env": "NX_DEV_URL" },
37+
{ "env": "NEXT_PUBLIC_NO_INDEX" }
2238
],
23-
"outputs": ["{workspaceRoot}/dist/nx-dev/nx-dev"],
24-
"configurations": {
25-
"netlify": {
26-
"outputs": ["{workspaceRoot}/nx-dev/nx-dev/.next"]
27-
}
28-
}
39+
"outputs": [
40+
"{workspaceRoot}/nx-dev/nx-dev/.next",
41+
"{workspaceRoot}/nx-dev/nx-dev/public/sitemap*.xml",
42+
"{workspaceRoot}/nx-dev/nx-dev/public/robots.txt"
43+
]
2944
},
3045
"check-links": {
3146
"cache": true,
@@ -36,7 +51,7 @@
3651
},
3752
"inputs": [
3853
"{workspaceRoot}/docs/**/*",
39-
"{workspaceRoot}/dist/nx-dev/nx-dev/public/sitemap*.xml",
54+
"{workspaceRoot}/nx-dev/nx-dev/public/sitemap*.xml",
4055
"{workspaceRoot}/astro-docs/dist/sitemap*.xml",
4156
"{workspaceRoot}/scripts/tsconfig.scripts.json",
4257
"{workspaceRoot}/scripts/documentation/internal-link-checker.ts"
@@ -54,7 +69,7 @@
5469
{ "env": "NX_DEV_URL" },
5570
{ "env": "NEXT_PUBLIC_NO_INDEX" }
5671
],
57-
"outputs": ["{workspaceRoot}/dist/nx-dev/nx-dev/public"],
72+
"outputs": ["{workspaceRoot}/nx-dev/nx-dev/public"],
5873
"options": {
5974
"command": "pnpm next-sitemap --config ./nx-dev/nx-dev/next-sitemap.config.js && node ./nx-dev/nx-dev/scripts/patch-sitemap-index.mjs"
6075
}
@@ -71,26 +86,6 @@
7186
}
7287
}
7388
},
74-
"build-base": {
75-
"parallelism": false,
76-
"executor": "@nx/next:build",
77-
"dependsOn": ["copy-docs", "prebuild-banner"],
78-
"inputs": ["production", "^production", "{projectRoot}/lib/banner.json"],
79-
"outputs": ["{options.outputPath}"],
80-
"options": {
81-
"root": "nx-dev/nx-dev",
82-
"outputPath": "dist/nx-dev/nx-dev"
83-
},
84-
"configurations": {
85-
"development": {
86-
"outputPath": "nx-dev/nx-dev"
87-
},
88-
"production": {},
89-
"netlify": {
90-
"outputPath": "nx-dev/nx-dev"
91-
}
92-
}
93-
},
9489
"copy-docs": {
9590
"inputs": ["{workspaceRoot}/docs/**/*"],
9691
"outputs": ["{projectRoot}/public/documentation"],
@@ -99,6 +94,13 @@
9994
"cwd": "nx-dev/nx-dev"
10095
}
10196
},
97+
"serve": {
98+
"dependsOn": ["copy-docs", "prebuild-banner"],
99+
"command": "next dev",
100+
"options": {
101+
"cwd": "nx-dev/nx-dev"
102+
}
103+
},
102104
"serve-docs": {
103105
"executor": "nx:run-commands",
104106
"options": {
@@ -110,36 +112,20 @@
110112
}
111113
},
112114
"start": {
113-
"dependsOn": ["build-base"],
114-
"command": "nx run nx-dev:serve:production"
115-
},
116-
"serve": {
117-
"executor": "@nx/next:server",
118-
"dependsOn": ["copy-docs", "prebuild-banner"],
115+
"dependsOn": ["build"],
116+
"command": "next start",
119117
"options": {
120-
"buildTarget": "nx-dev:build-base",
121-
"dev": true
122-
},
123-
"configurations": {
124-
"production": {
125-
"buildTarget": "nx-dev:build-base:production",
126-
"dev": false
127-
},
128-
"development": {
129-
"buildTarget": "nx-dev:build-base:development",
130-
"dev": true
131-
}
132-
},
133-
"defaultConfiguration": "development"
118+
"cwd": "nx-dev/nx-dev"
119+
}
134120
},
135121
"deploy-build": {
136122
"executor": "nx:run-commands",
137123
"outputs": ["{projectRoot}/public/documentation"],
138124
"options": {
139125
"commands": [
140126
{
141-
"command": "nx run nx-dev:build",
142-
"description": "NextJs build step"
127+
"command": "nx run nx-dev:build && mkdir -p dist/nx-dev/nx-dev && cp -r nx-dev/nx-dev/.next dist/nx-dev/nx-dev/.next",
128+
"description": "NextJs build step (copy to dist for Vercel)"
143129
}
144130
],
145131
"color": true,
@@ -152,7 +138,7 @@
152138
"netlify": {
153139
"commands": [
154140
{
155-
"command": "nx run nx-dev:build-base:netlify && cp nx-dev/nx-dev/_redirects nx-dev/nx-dev/.next/_redirects && nx run nx-dev:sitemap",
141+
"command": "nx run nx-dev:build && cp nx-dev/nx-dev/_redirects nx-dev/nx-dev/.next/_redirects",
156142
"description": "NextJs build for Netlify"
157143
}
158144
]

nx-dev/nx-dev/scripts/patch-sitemap-index.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import { readFileSync, writeFileSync } from 'fs';
66
import { resolve } from 'path';
77

88
const siteUrl = process.env.NX_DEV_URL || 'https://nx.dev';
9-
const isNetlify = process.env.NETLIFY === 'true';
10-
const outDir = isNetlify
11-
? resolve(import.meta.dirname, '../public')
12-
: resolve(import.meta.dirname, '../../../dist/nx-dev/nx-dev/public');
9+
const outDir = resolve(import.meta.dirname, '../public');
1310

1411
const sitemapPath = resolve(outDir, 'sitemap.xml');
1512

nx-dev/nx-dev/tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"lib": ["dom", "dom.iterable", "es2021", "esnext"],
5-
"outDir": "../../dist/nx-dev/nx-dev",
6-
"tsBuildInfoFile": "../../dist/nx-dev/nx-dev/tsconfig.tsbuildinfo",
5+
"tsBuildInfoFile": "./tsconfig.tsbuildinfo",
76
"jsx": "preserve",
87
"allowJs": true,
98
"esModuleInterop": true,
@@ -34,9 +33,8 @@
3433
"**/*.tsx",
3534
"next-env.d.ts",
3635
".next/types/**/*.ts",
37-
"../../dist/nx-dev/nx-dev/.next/types/**/*.ts",
3836
"public/documentation/**/*.json",
39-
"dist/nx-dev/nx-dev/.next/types/**/*.ts"
37+
"../../nx-dev/nx-dev/.next/types/**/*.ts"
4038
],
4139
"references": [
4240
{

nx-dev/ui-video-courses/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"types": "./src/index.ts",
88
"dependencies": {
99
"@nx/nx-dev-data-access-courses": "workspace:*",
10+
"@nx/nx-dev-ui-icons": "workspace:*",
1011
"@nx/nx-dev-ui-primitives": "workspace:*",
1112
"@nx/nx-dev-ui-common": "workspace:*"
1213
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@
172172
"@xstate/inspect": "0.7.0",
173173
"@xstate/react": "3.0.1",
174174
"@zkochan/js-yaml": "catalog:",
175-
"ai": "3.0.19",
176175
"ajv": "^8.12.0",
177176
"angular-eslint": "catalog:eslint",
178177
"autoprefixer": "10.4.13",

0 commit comments

Comments
 (0)