Skip to content

Commit 26cc544

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 6ee7091 commit 26cc544

File tree

9 files changed

+1076
-1241
lines changed

9 files changed

+1076
-1241
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: 41 additions & 56 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,
@@ -45,7 +60,6 @@
4560
"dependsOn": ["check-links"]
4661
},
4762
"sitemap": {
48-
"dependsOn": ["build-base"],
4963
"executor": "nx:run-commands",
5064
"inputs": [
5165
"{workspaceRoot}/docs/**/*",
@@ -54,7 +68,7 @@
5468
{ "env": "NX_DEV_URL" },
5569
{ "env": "NEXT_PUBLIC_NO_INDEX" }
5670
],
57-
"outputs": ["{workspaceRoot}/dist/nx-dev/nx-dev/public"],
71+
"outputs": ["{workspaceRoot}/nx-dev/nx-dev/public"],
5872
"options": {
5973
"command": "pnpm next-sitemap --config ./nx-dev/nx-dev/next-sitemap.config.js && node ./nx-dev/nx-dev/scripts/patch-sitemap-index.mjs"
6074
}
@@ -71,26 +85,6 @@
7185
}
7286
}
7387
},
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-
},
9488
"copy-docs": {
9589
"inputs": ["{workspaceRoot}/docs/**/*"],
9690
"outputs": ["{projectRoot}/public/documentation"],
@@ -99,6 +93,13 @@
9993
"cwd": "nx-dev/nx-dev"
10094
}
10195
},
96+
"serve": {
97+
"dependsOn": ["copy-docs", "prebuild-banner"],
98+
"command": "next dev",
99+
"options": {
100+
"cwd": "nx-dev/nx-dev"
101+
}
102+
},
102103
"serve-docs": {
103104
"executor": "nx:run-commands",
104105
"options": {
@@ -110,27 +111,11 @@
110111
}
111112
},
112113
"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"],
114+
"dependsOn": ["build"],
115+
"command": "next start",
119116
"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"
117+
"cwd": "nx-dev/nx-dev"
118+
}
134119
},
135120
"deploy-build": {
136121
"executor": "nx:run-commands",
@@ -152,7 +137,7 @@
152137
"netlify": {
153138
"commands": [
154139
{
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",
140+
"command": "nx run nx-dev:build && cp nx-dev/nx-dev/_redirects nx-dev/nx-dev/.next/_redirects",
156141
"description": "NextJs build for Netlify"
157142
}
158143
]

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
@@ -171,7 +171,6 @@
171171
"@xstate/inspect": "0.7.0",
172172
"@xstate/react": "3.0.1",
173173
"@zkochan/js-yaml": "catalog:",
174-
"ai": "3.0.19",
175174
"ajv": "^8.12.0",
176175
"angular-eslint": "catalog:eslint",
177176
"autoprefixer": "10.4.13",

0 commit comments

Comments
 (0)