Skip to content

feat: root dir resolver helper#77

Open
Kinfe123 wants to merge 3 commits intomainfrom
feat/root-dir-resolver-helper
Open

feat: root dir resolver helper#77
Kinfe123 wants to merge 3 commits intomainfrom
feat/root-dir-resolver-helper

Conversation

@Kinfe123
Copy link
Copy Markdown
Contributor

@Kinfe123 Kinfe123 commented Apr 9, 2026

  • feat: root dir resolver helper
  • chore: fmt

Summary by cubic

Add auto project-root detection to @farming-labs/next/api and support contentDir so docs APIs work in monorepos and production builds. Default to simple search when no provider is set, and improve build tracing and Turbopack setup.

  • New Features

    • Export resolveNextProjectRoot(metaUrl) and auto-infer the project root inside createDocsAPI/createDocsMCPAPI from @farming-labs/next/api (generated routes no longer pass rootDir).
    • @farming-labs/theme/api createDocsAPI accepts rootDir and contentDir; GET search uses contentDir and scans multiple candidates (app/, configured contentDir, .next/server, custom dist dirs) with fallback to traced server files.
    • Default to built-in simple search when no search config is set; Typesense/Algolia/MCP remain opt-in via DOCS_SEARCH_PROVIDER.
  • Refactors

    • Generated API routes now pass contentDir; examples and website updated; env/README simplified for default simple search.
    • withDocs adds outputFileTracingIncludes for docs content and auto-configures Turbopack root/aliases when inside the workspace; removed manual aliases from app configs.
    • Docs note @farming-labs/theme/api remains for compatibility but prefer @farming-labs/next/api; minor Next.js type path tweak.
    • Added tests for project-root resolution, default simple search, contentDir routing, traced .next fallback, and Turbopack/tracing behavior.

Written for commit 4e7cc93. Summary will update on new commits.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs-website Ready Ready Preview, Comment Apr 9, 2026 8:46am

@Kinfe123 Kinfe123 changed the title feat/root dir resolver helper feat: root dir resolver helper Apr 9, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 9, 2026

Open in StackBlitz

@farming-labs/astro

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/astro@77

@farming-labs/astro-theme

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/astro-theme@77

@farming-labs/docs

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/docs@77

@farming-labs/theme

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/theme@77

@farming-labs/next

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/next@77

@farming-labs/nuxt

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/nuxt@77

@farming-labs/nuxt-theme

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/nuxt-theme@77

@farming-labs/svelte

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/svelte@77

@farming-labs/svelte-theme

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/svelte-theme@77

@farming-labs/tanstack-start

pnpm add https://pkg.pr.new/farming-labs/docs/@farming-labs/tanstack-start@77

commit: 4e7cc93

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 16 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="examples/next/docs.config.tsx">

<violation number="1" location="examples/next/docs.config.tsx:78">
P1: `searchConfig` is never applied, so `DOCS_SEARCH_PROVIDER` and external search provider selection no longer work.</violation>

<violation number="2" location="examples/next/docs.config.tsx:197">
P1: MCP is never enabled because the conditional `mcp` block is commented out, so `DOCS_SEARCH_PROVIDER=mcp` cannot work as documented.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

mcp: {
enabled: true,
},
// ...(docsSearchProvider === "mcp" ? { mcp: { enabled: true } } : {}),
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: MCP is never enabled because the conditional mcp block is commented out, so DOCS_SEARCH_PROVIDER=mcp cannot work as documented.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At examples/next/docs.config.tsx, line 197:

<comment>MCP is never enabled because the conditional `mcp` block is commented out, so `DOCS_SEARCH_PROVIDER=mcp` cannot work as documented.</comment>

<file context>
@@ -192,9 +194,7 @@ export default defineDocs({
-  mcp: {
-    enabled: true,
-  },
+  // ...(docsSearchProvider === "mcp" ? { mcp: { enabled: true } } : {}),
   ordering: "numeric",
   metadata: {
</file context>
Suggested change
// ...(docsSearchProvider === "mcp" ? { mcp: { enabled: true } } : {}),
...(docsSearchProvider === "mcp" ? { mcp: { enabled: true } } : {}),
Fix with Cubic

export default defineDocs({
entry: "docs",
search: searchConfig,
// ...(searchConfig ? { search: searchConfig } : {}),
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: searchConfig is never applied, so DOCS_SEARCH_PROVIDER and external search provider selection no longer work.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At examples/next/docs.config.tsx, line 78:

<comment>`searchConfig` is never applied, so `DOCS_SEARCH_PROVIDER` and external search provider selection no longer work.</comment>

<file context>
@@ -58,22 +55,27 @@ const searchConfig =
 export default defineDocs({
   entry: "docs",
-  search: searchConfig,
+  // ...(searchConfig ? { search: searchConfig } : {}),
   github: {
     url: "https://github.com/farming-labs/docs",
</file context>
Suggested change
// ...(searchConfig ? { search: searchConfig } : {}),
...(searchConfig ? { search: searchConfig } : {}),
Fix with Cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 19 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/next/src/config.test.ts">

<violation number="1" location="packages/next/src/config.test.ts:242">
P1: The `resolveAlias` paths in `turbopack` configuration are incorrectly hardcoded as relative to the monorepo root, which fails when the Next.js project is in a subdirectory (e.g., `examples/next`).</violation>
</file>

<file name="packages/next/src/api.ts">

<violation number="1" location="packages/next/src/api.ts:46">
P2: The regex requires at least one segment between `api/` and `/route`, so root-level routes like `app/api/route.ts` won’t be detected and `rootDir` inference will fail for those handlers. Allow the segment to be optional.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@@ -1,5 +1,13 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The resolveAlias paths in turbopack configuration are incorrectly hardcoded as relative to the monorepo root, which fails when the Next.js project is in a subdirectory (e.g., examples/next).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/src/config.test.ts, line 242:

<comment>The `resolveAlias` paths in `turbopack` configuration are incorrectly hardcoded as relative to the monorepo root, which fails when the Next.js project is in a subdirectory (e.g., `examples/next`).</comment>

<file context>
@@ -193,12 +199,50 @@ describe("withDocs (app dir: src/app vs app)", () => {
+      | undefined;
+
+    expect(turbopack?.root).toBe(realpathSync(workspaceRoot));
+    expect(turbopack?.resolveAlias?.["@farming-labs/docs"]).toBe("./packages/docs/src/index.ts");
+    expect(turbopack?.resolveAlias?.["@farming-labs/next/api"]).toBe("./packages/next/src/api.ts");
+    expect(turbopack?.resolveAlias?.["@farming-labs/theme/search"]).toBe(
</file context>
Fix with Cubic


function isNextRouteFile(filePath: string): boolean {
const normalized = filePath.replaceAll("\\", "/");
return /\/(?:src\/)?app\/api\/.+\/route\.[cm]?[jt]sx?$/.test(normalized);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The regex requires at least one segment between api/ and /route, so root-level routes like app/api/route.ts won’t be detected and rootDir inference will fail for those handlers. Allow the segment to be optional.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/src/api.ts, line 46:

<comment>The regex requires at least one segment between `api/` and `/route`, so root-level routes like `app/api/route.ts` won’t be detected and `rootDir` inference will fail for those handlers. Allow the segment to be optional.</comment>

<file context>
@@ -34,3 +40,44 @@ export function resolveNextProjectRoot(metaUrl: string): string {
+
+function isNextRouteFile(filePath: string): boolean {
+  const normalized = filePath.replaceAll("\\", "/");
+  return /\/(?:src\/)?app\/api\/.+\/route\.[cm]?[jt]sx?$/.test(normalized);
+}
+
</file context>
Suggested change
return /\/(?:src\/)?app\/api\/.+\/route\.[cm]?[jt]sx?$/.test(normalized);
return /\/(?:src\/)?app\/api(?:\/.+)?\/route\.[cm]?[jt]sx?$/.test(normalized);
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant