From b45c1e1580449bad7f32d943c7e223605a125c51 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Wed, 26 Feb 2025 10:01:30 +0200 Subject: [PATCH] docs: prepare projects configurations for user guide (#11610) * docs: prepare projects configurations for user guide * fix build error --- www/apps/api-reference/next.config.mjs | 5 ++- www/apps/book/next.config.mjs | 24 ++++++----- www/apps/resources/next.config.mjs | 3 ++ .../app/md-content/[...slug]/route.ts | 2 +- www/apps/user-guide/next.config.mjs | 42 +++++++++++++++++-- 5 files changed, 59 insertions(+), 17 deletions(-) diff --git a/www/apps/api-reference/next.config.mjs b/www/apps/api-reference/next.config.mjs index cb554cdf5e..feb425b200 100644 --- a/www/apps/api-reference/next.config.mjs +++ b/www/apps/api-reference/next.config.mjs @@ -48,6 +48,9 @@ const withMDX = createMDX({ projectPath: path.resolve("..", "ui"), contentPath: "src/content/docs", }, + "user-guide": { + projectPath: path.resolve("..", "user-guide"), + }, }, }, ], @@ -91,4 +94,4 @@ const withBundleAnalyzer = bundleAnalyzer({ enabled: process.env.ANALYZE_BUNDLE === "true", }) -export default withMDX(nextConfig) +export default withMDX(withBundleAnalyzer(nextConfig)) diff --git a/www/apps/book/next.config.mjs b/www/apps/book/next.config.mjs index 92ad17f5ab..6b699f1c5c 100644 --- a/www/apps/book/next.config.mjs +++ b/www/apps/book/next.config.mjs @@ -28,6 +28,9 @@ const withMDX = mdx({ projectPath: path.resolve("..", "ui"), contentPath: "src/content/docs", }, + "user-guide": { + projectPath: path.resolve("..", "user-guide"), + }, }, }, ], @@ -152,17 +155,16 @@ const nextConfig = { }/v1/:path*`, basePath: false, }, - // TODO comment out once we have the user guide published - // { - // source: "/user-guide", - // destination: `${process.env.NEXT_PUBLIC_USER_GUIDE_URL}/user-guide`, - // basePath: false, - // }, - // { - // source: "/user-guide/:path*", - // destination: `${process.env.NEXT_PUBLIC_USER_GUIDE_URL}/user-guide/:path*`, - // basePath: false, - // }, + { + source: "/user-guide", + destination: `${process.env.NEXT_PUBLIC_USER_GUIDE_URL || "https://localhost:3001"}/user-guide`, + basePath: false, + }, + { + source: "/user-guide/:path*", + destination: `${process.env.NEXT_PUBLIC_USER_GUIDE_URL || "https://localhost:3001"}/user-guide/:path*`, + basePath: false, + }, ], } }, diff --git a/www/apps/resources/next.config.mjs b/www/apps/resources/next.config.mjs index 6b286b814e..f0a288b2c8 100644 --- a/www/apps/resources/next.config.mjs +++ b/www/apps/resources/next.config.mjs @@ -26,6 +26,9 @@ const withMDX = mdx({ projectPath: path.resolve("..", "ui"), contentPath: "src/content/docs", }, + "user-guide": { + projectPath: path.resolve("..", "user-guide"), + }, }, }, ], diff --git a/www/apps/user-guide/app/md-content/[...slug]/route.ts b/www/apps/user-guide/app/md-content/[...slug]/route.ts index 764f616126..01ad596d28 100644 --- a/www/apps/user-guide/app/md-content/[...slug]/route.ts +++ b/www/apps/user-guide/app/md-content/[...slug]/route.ts @@ -16,7 +16,7 @@ type Params = { } export async function GET(req: NextRequest, { params }: Params) { - const { slug } = await params + const { slug = ["/"] } = await params // keep this so that Vercel keeps the files in deployment const basePath = path.join(process.cwd(), "app") diff --git a/www/apps/user-guide/next.config.mjs b/www/apps/user-guide/next.config.mjs index a015d360cb..b22b15fbcb 100644 --- a/www/apps/user-guide/next.config.mjs +++ b/www/apps/user-guide/next.config.mjs @@ -1,4 +1,5 @@ import mdx from "@next/mdx" +import path from "path" import rehypeMdxCodeProps from "rehype-mdx-code-props" import rehypeSlug from "rehype-slug" import remarkDirective from "remark-directive" @@ -9,13 +10,32 @@ import { cloudinaryImgRehypePlugin, resolveAdmonitionsPlugin, crossProjectLinksPlugin, + prerequisitesLinkFixerPlugin, } from "remark-rehype-plugins" +import bundleAnalyzer from "@next/bundle-analyzer" const withMDX = mdx({ extension: /\.mdx?$/, options: { rehypePlugins: [ - // TODO add V2 to path if necessary + [ + brokenLinkCheckerPlugin, + { + crossProjects: { + docs: { + projectPath: path.resolve("..", "book"), + }, + ui: { + projectPath: path.resolve("..", "ui"), + contentPath: "src/content/docs", + }, + resources: { + projectPath: path.resolve("..", "resources"), + hasGeneratedSlugs: true, + }, + }, + }, + ], [ crossProjectLinksPlugin, { @@ -40,7 +60,6 @@ const withMDX = mdx({ process.env.VERCEL_ENV === "production", }, ], - [brokenLinkCheckerPlugin], [localLinksRehypePlugin], [ rehypeMdxCodeProps, @@ -63,6 +82,12 @@ const withMDX = mdx({ }, }, ], + [ + prerequisitesLinkFixerPlugin, + { + checkLinksType: "value", + }, + ], ], remarkPlugins: [ [remarkFrontmatter], @@ -79,8 +104,17 @@ const nextConfig = { pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"], transpilePackages: ["docs-ui"], - // TODO uncomment if we decide on baes path basePath: process.env.NEXT_PUBLIC_BASE_PATH || "/user-guide", + outputFileTracingExcludes: { + "*": ["node_modules/@medusajs/icons"], + }, + experimental: { + optimizePackageImports: ["@medusajs/icons", "@medusajs/ui"], + }, } -export default withMDX(nextConfig) +const withBundleAnalyzer = bundleAnalyzer({ + enabled: process.env.ANALYZE === "true", +}) + +export default withMDX(withBundleAnalyzer(nextConfig))