Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/llms-txt-hub / apps/web/lib/server-utils.ts |
| Date | Not specified in source |
| Repository | Janady13/llms-txt-hub |
| Revision | e0f4bf978d4df168369c7601d9c5f5ea89e84377 |
| Branch | main |
| Path or archive member | apps/web/lib/server-utils.ts |
| Original SHA-256 | fafc4cad4073bfb66326bc785e998d26f339abb5935bb02ea9108b3e0e298b1a |
| Git blob SHA | f0cde8ddfa04a586e6b180305a47ff42f9b31694 |
| Reading-copy SHA-256 | fafc4cad4073bfb66326bc785e998d26f339abb5935bb02ea9108b3e0e298b1a |
Recovered source transcript
Download complete source text ↓62 lines · 1.8 KB
import 'server-only'
import fs from 'node:fs'
import path from 'node:path'
/**
* Resolves a path relative to the monorepo root
* Server-side only utility function
*
* @param relativePath - Path relative to the monorepo root
* @returns Absolute path from the monorepo root
*/
export function resolveFromRoot(relativePath: string): string {
// Special case for data directory which might be at project root
if (relativePath === 'data' || relativePath.startsWith('data/')) {
// Check multiple possible locations for the data directory
const possibleDataPaths = [
// For Vercel environments
path.join(process.cwd(), relativePath),
// For monorepo root
path.join(process.cwd(), '..', '..', relativePath),
path.join(process.cwd(), '..', relativePath),
// For app-specific locations
path.join(process.cwd(), 'apps', 'web', relativePath)
]
for (const p of possibleDataPaths) {
if (fs.existsSync(p)) {
// Development debug: Found file at path
return p
}
}
}
// Standard path resolution logic
if (process.env.VERCEL) {
// Try the direct path first (content at root level)
const directPath = path.join(process.cwd(), relativePath)
if (fs.existsSync(directPath)) {
return directPath
}
// Try the app-relative path next (content inside apps/web)
const appPath = path.join(process.cwd(), 'apps', 'web', relativePath)
if (fs.existsSync(appPath)) {
return appPath
}
// Default to direct path even if it doesn't exist
return directPath
}
// Local development path
return path.join(process.cwd(), '..', '..', relativePath)
}
/**
* Resolve paths from project root (server-only)
*/
export function resolveFromProjectRoot(...paths: string[]): string {
return path.resolve(process.cwd(), ...paths)
}