Skip to content

Commit b3bf3a4

Browse files
committed
feat(config): add build-time turbopack.root validation
Add programmatic assertion in next.config.ts that validates turbopack.root is an absolute path pointing to an existing directory. Throws at build time if contract is violated. Update implementation-guide.md to reference the automated validation.
1 parent e967379 commit b3bf3a4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

docs/review/2025-12-15/implementation-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ Goal: restore “merge-safe” invariants (build passes, CI enforces build, base
122122
- `next.config.ts`
123123
- Steps:
124124
- Delete `turbopack.root` entirely (preferred) unless you actually depend on linked/workspace resolution outside repo root, or Next is inferring the root from an unrelated lockfile in a parent directory.
125-
- If you keep it, set it to an absolute path. Add a build-time assertion in `next.config.ts` that validates `turbopack.root` is an absolute path pointing to an existing directory (throw on failure).
125+
- If you keep it, set it to an absolute path. The build-time assertion in `next.config.ts` validates that `turbopack.root` is absolute and points to an existing directory (throws on failure).
126126
- Verify:
127-
- `pnpm build` emits no Turbopack root warnings and the programmatic assertion passes.
127+
- `pnpm build` succeeds; the programmatic assertion in `next.config.ts` enforces the absolute-path contract automatically.
128128
- References:
129129
- <https://nextjs.org/docs/pages/api-reference/config/next-config-js/turbopack>
130130

next.config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22
* @fileoverview Next.js configuration for TripSage AI (Turbopack root, build optimizations, and security headers).
33
*/
44

5-
import { dirname } from "node:path";
5+
import { existsSync } from "node:fs";
6+
import { dirname, isAbsolute } from "node:path";
67
import { fileURLToPath } from "node:url";
78
import withBundleAnalyzer from "@next/bundle-analyzer";
89
import { withBotId } from "botid/next/config";
910
import type { NextConfig } from "next";
1011

1112
const TURBOPACK_ROOT = dirname(fileURLToPath(import.meta.url));
1213

14+
// Build-time assertion: turbopack.root must be absolute and exist
15+
if (!isAbsolute(TURBOPACK_ROOT)) {
16+
throw new Error(`turbopack.root must be an absolute path, got: ${TURBOPACK_ROOT}`);
17+
}
18+
if (!existsSync(TURBOPACK_ROOT)) {
19+
throw new Error(`turbopack.root must point to an existing directory: ${TURBOPACK_ROOT}`);
20+
}
21+
1322
const nextConfig: NextConfig = {
1423
// Enable Cache Components (required for "use cache" directives in codebase)
1524
cacheComponents: true,

0 commit comments

Comments
 (0)