Skip to content

Commit a3ad6bf

Browse files
committed
fix(nx-dev): build nx-dev in-place and clean up targets
The default @nx/next:build for nx-dev outputs to dist/nx-dev/nx-dev. At runtime, Node.js can't resolve the ai package from that path because node_modules is at the workspace root, causing ERR_MODULE_NOT_FOUND on /ai-chat. Additionally, ui-video-courses is missing @nx/nx-dev-ui-icons as a dependency. Build in-place so .next stays close to node_modules and package resolution works. Clean up and simplify nx-dev targets. Fix missing dependency in ui-video-courses. Fixes DOC-418
1 parent 68fbfae commit a3ad6bf

File tree

13 files changed

+981
-1142
lines changed

13 files changed

+981
-1142
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jest.debug.config.js
2525
/nx-dev/nx-dev/public/documentation
2626
/nx-dev/nx-dev/public/tutorials
2727
/nx-dev/nx-dev/public/images/open-graph
28+
/nx-dev/nx-dev/public/robots.txt
29+
/nx-dev/nx-dev/public/sitemap-0.xml
30+
/nx-dev/nx-dev/public/sitemap.xml
2831

2932
# Banner JSON files are generated during static builds
3033
/nx-dev/nx-dev/lib/banner.json

astro-docs/validate-links.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const sitemapIndexPath = path.join(distDir, 'sitemap-index.xml');
1919
const sitemapFallbackPath = path.join(distDir, 'sitemap-0.xml');
2020
const nxDevSitemapPath = path.join(
2121
workspaceRoot,
22-
'dist',
2322
'nx-dev',
2423
'nx-dev',
2524
'public',

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/next.config.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ module.exports = withNx({
7373
],
7474
},
7575
},
76+
async redirects() {
77+
return [
78+
{
79+
source: '/',
80+
destination: '/blog',
81+
permanent: false,
82+
},
83+
];
84+
},
7685
async rewrites() {
7786
// Only configure rewrites if NEXT_PUBLIC_ASTRO_URL is set
7887
// Remove trailing slash to prevent double slashes in rewrite destinations
@@ -146,10 +155,6 @@ module.exports = withNx({
146155
'@nx/nx-dev-ui-video-courses',
147156
'@nx/nx-dev-util-ai',
148157
],
149-
// For both client and server
150-
env: {
151-
VERCEL: process.env.VERCEL,
152-
},
153158
async headers() {
154159
return [
155160
{

nx-dev/nx-dev/package.json

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,60 @@
44
"type": "commonjs",
55
"private": true,
66
"dependencies": {
7-
"ai": "3.0.19",
8-
"@nx/nx-dev-data-access-documents": "workspace:*",
7+
"@docsearch/react": "3.9.0",
8+
"@grafana/faro-web-sdk": "1.19.0",
9+
"@headlessui/react": "2.2.4",
10+
"@heroicons/react": "2.2.0",
11+
"@markdoc/markdoc": "0.2.2",
12+
"@nx/graph": "1.0.5",
13+
"@nx/nx-darwin-arm64": "21.6.2",
914
"@nx/nx-dev-data-access-courses": "workspace:*",
15+
"@nx/nx-dev-data-access-documents": "workspace:*",
16+
"@nx/nx-dev-feature-ai": "workspace:*",
17+
"@nx/nx-dev-feature-analytics": "workspace:*",
18+
"@nx/nx-dev-feature-feedback": "workspace:*",
19+
"@nx/nx-dev-feature-search": "workspace:*",
20+
"@nx/nx-dev-ui-animations": "workspace:*",
21+
"@nx/nx-dev-ui-blog": "workspace:*",
1022
"@nx/nx-dev-ui-common": "workspace:*",
1123
"@nx/nx-dev-ui-courses": "workspace:*",
24+
"@nx/nx-dev-ui-fence": "workspace:*",
1225
"@nx/nx-dev-ui-icons": "workspace:*",
13-
"@nx/nx-dev-util-ai": "workspace:*",
1426
"@nx/nx-dev-ui-markdoc": "workspace:*",
15-
"@nx/nx-dev-feature-analytics": "workspace:*",
27+
"@nx/nx-dev-ui-podcast": "workspace:*",
28+
"@nx/nx-dev-ui-pricing": "workspace:*",
1629
"@nx/nx-dev-ui-primitives": "workspace:*",
17-
"@nx/nx-dev-feature-feedback": "workspace:*",
18-
"@nx/nx-dev-ui-theme": "workspace:*",
19-
"@nx/nx-dev-feature-ai": "workspace:*",
20-
"@nx/nx-dev-ui-animations": "workspace:*",
21-
"@nx/nx-dev-feature-search": "workspace:*",
2230
"@nx/nx-dev-ui-references": "workspace:*",
23-
"@nx/nx-dev-ui-fence": "workspace:*",
24-
"@nx/nx-dev-ui-blog": "workspace:*",
2531
"@nx/nx-dev-ui-resources": "workspace:*",
26-
"@nx/nx-dev-ui-podcast": "workspace:*",
27-
"@nx/nx-dev-ui-pricing": "workspace:*",
28-
"@nx/nx-dev-ui-video-courses": "workspace:*"
32+
"@nx/nx-dev-ui-theme": "workspace:*",
33+
"@nx/nx-dev-ui-video-courses": "workspace:*",
34+
"@nx/nx-dev-util-ai": "workspace:*",
35+
"@tailwindcss/aspect-ratio": "0.4.2",
36+
"@tailwindcss/forms": "0.5.10",
37+
"@tailwindcss/typography": "0.5.13",
38+
"@yarnpkg/lockfile": "1.1.0",
39+
"@yarnpkg/parsers": "3.0.2",
40+
"ai": "3.0.19",
41+
"axios": "1.12.0",
42+
"classnames": "2.5.1",
43+
"cliui": "8.0.1",
44+
"enquirer": "2.3.6",
45+
"framer-motion": "11.18.2",
46+
"front-matter": "4.0.2",
47+
"ignore": "7.0.5",
48+
"next": "14.2.35",
49+
"next-seo": "5.15.0",
50+
"node-machine-id": "1.1.12",
51+
"npm-run-path": "4.0.1",
52+
"react": "18.3.1",
53+
"react-copy-to-clipboard": "5.1.0",
54+
"react-dom": "18.3.1",
55+
"react-syntax-highlighter": "15.6.1",
56+
"sharp": "0.33.5",
57+
"string-width": "4.2.3",
58+
"tailwind-merge": "2.6.0",
59+
"tailwindcss": "3.4.4",
60+
"tslib": "2.8.1",
61+
"typescript": "5.9.2"
2962
}
3063
}

nx-dev/nx-dev/project.json

Lines changed: 45 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,48 @@
44
"sourceRoot": "nx-dev/nx-dev",
55
"projectType": "application",
66
"targets": {
7-
"build": {
8-
"dependsOn": [
9-
{
10-
"target": "build-base"
11-
}
12-
],
13-
"executor": "nx:run-commands",
14-
"options": {
15-
"commands": ["nx run nx-dev:sitemap"],
16-
"parallel": false
17-
},
7+
"next:build": {
8+
"dependsOn": ["copy-docs", "prebuild-banner"],
189
"inputs": [
1910
"production",
2011
"^production",
21-
{ "env": "NEXT_PUBLIC_ASTRO_URL" }
12+
"{projectRoot}/lib/banner.json",
13+
{ "env": "NEXT_PUBLIC_ASTRO_URL" },
14+
{ "env": "NX_DEV_URL" },
15+
{ "env": "NEXT_PUBLIC_NO_INDEX" }
2216
],
23-
"outputs": ["{workspaceRoot}/dist/nx-dev/nx-dev"],
24-
"configurations": {
25-
"netlify": {
26-
"outputs": ["{workspaceRoot}/nx-dev/nx-dev/.next"]
27-
}
28-
}
29-
},
30-
"check-links": {
31-
"cache": true,
32-
"dependsOn": ["nx-dev:build", "astro-docs:build"],
33-
"executor": "nx:run-commands",
34-
"options": {
35-
"command": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/documentation/internal-link-checker.ts"
36-
},
37-
"inputs": [
38-
"{workspaceRoot}/docs/**/*",
39-
{ "dependentTasksOutputFiles": "**/sitemap*.xml" },
40-
"{workspaceRoot}/scripts/tsconfig.scripts.json",
41-
"{workspaceRoot}/scripts/documentation/internal-link-checker.ts"
17+
"outputs": [
18+
"{workspaceRoot}/nx-dev/nx-dev/.next",
19+
"{workspaceRoot}/nx-dev/nx-dev/public/sitemap*.xml",
20+
"{workspaceRoot}/nx-dev/nx-dev/public/robots.txt"
4221
]
4322
},
44-
"test": {
45-
"dependsOn": ["check-links"]
46-
},
4723
"sitemap": {
48-
"dependsOn": ["build-base"],
49-
"executor": "nx:run-commands",
24+
"dependsOn": ["nx-dev:next:build"],
5025
"inputs": [
5126
"{workspaceRoot}/docs/**/*",
5227
"production",
5328
"{projectRoot}/next-sitemap.config.js",
5429
{ "env": "NX_DEV_URL" },
5530
{ "env": "NEXT_PUBLIC_NO_INDEX" }
5631
],
57-
"outputs": ["{workspaceRoot}/dist/nx-dev/nx-dev/public"],
32+
"outputs": ["{workspaceRoot}/nx-dev/nx-dev/public/sitemap*.xml"],
33+
"command": "pnpm next-sitemap --config ./next-sitemap.config.js && node ./scripts/patch-sitemap-index.mjs",
5834
"options": {
59-
"command": "pnpm next-sitemap --config ./nx-dev/nx-dev/next-sitemap.config.js && node ./nx-dev/nx-dev/scripts/patch-sitemap-index.mjs"
35+
"cwd": "nx-dev/nx-dev"
6036
}
6137
},
6238
"prebuild-banner": {
63-
"executor": "nx:run-commands",
6439
"cache": false,
6540
"outputs": ["{projectRoot}/lib/banner.json"],
41+
"command": "node ../../scripts/documentation/prebuild-banner.mjs",
6642
"options": {
67-
"command": "node ../../scripts/documentation/prebuild-banner.mjs",
6843
"cwd": "nx-dev/nx-dev",
6944
"env": {
7045
"BANNER_OUTPUT_PATH": "lib/banner.json"
7146
}
7247
}
7348
},
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-
},
9449
"copy-docs": {
9550
"inputs": ["{workspaceRoot}/docs/**/*"],
9651
"outputs": ["{projectRoot}/public/documentation"],
@@ -99,65 +54,47 @@
9954
"cwd": "nx-dev/nx-dev"
10055
}
10156
},
102-
"serve-docs": {
57+
"copy-redirects": {
58+
"dependsOn": ["nx-dev:next:build"],
59+
"inputs": ["{projectRoot}/_redirects"],
60+
"outputs": ["{projectRoot}/.next/_redirects"],
61+
"command": "cp nx-dev/nx-dev/_redirects nx-dev/nx-dev/.next/_redirects"
62+
},
63+
"build": {
64+
"dependsOn": ["sitemap", "copy-redirects"],
65+
"outputs": ["{projectRoot}/.next"]
66+
},
67+
"deploy-build": {
68+
"dependsOn": ["build"],
69+
"outputs": ["{projectRoot}/.next"]
70+
},
71+
"serve": {
10372
"executor": "nx:run-commands",
73+
"dependsOn": ["copy-docs", "prebuild-banner"],
10474
"options": {
10575
"commands": [
10676
"nx watch --projects=docs -- nx run-many -t=copy-docs -p nx-dev",
107-
"nx run nx-dev:serve"
77+
"nx dev nx-dev"
10878
],
10979
"parallel": true
11080
}
11181
},
11282
"start": {
113-
"dependsOn": ["build-base"],
114-
"command": "nx run nx-dev:serve:production"
83+
"command": "nx next:start nx-dev"
11584
},
116-
"serve": {
117-
"executor": "@nx/next:server",
118-
"dependsOn": ["copy-docs", "prebuild-banner"],
119-
"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"
85+
"check-links": {
86+
"cache": true,
87+
"dependsOn": ["nx-dev:next:build", "astro-docs:build"],
88+
"command": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/documentation/internal-link-checker.ts",
89+
"inputs": [
90+
"{workspaceRoot}/docs/**/*",
91+
{ "dependentTasksOutputFiles": "**/sitemap*.xml" },
92+
"{workspaceRoot}/scripts/tsconfig.scripts.json",
93+
"{workspaceRoot}/scripts/documentation/internal-link-checker.ts"
94+
]
13495
},
135-
"deploy-build": {
136-
"executor": "nx:run-commands",
137-
"outputs": ["{projectRoot}/public/documentation"],
138-
"options": {
139-
"commands": [
140-
{
141-
"command": "nx run nx-dev:build",
142-
"description": "NextJs build step"
143-
}
144-
],
145-
"color": true,
146-
"parallel": false,
147-
"env": {
148-
"NODE_OPTIONS": "--max-old-space-size=4096"
149-
}
150-
},
151-
"configurations": {
152-
"netlify": {
153-
"commands": [
154-
{
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",
156-
"description": "NextJs build for Netlify"
157-
}
158-
]
159-
}
160-
}
96+
"test": {
97+
"dependsOn": ["check-links"]
16198
}
16299
},
163100
"tags": ["scope:nx-dev", "type:app"],

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
}

0 commit comments

Comments
 (0)