Skip to main content
Glama
modulePaths.ts1.64 kB
import { existsSync } from "fs"; import { dirname, join, resolve } from "path"; import { fileURLToPath } from "url"; export function moduleDirFromUrl(importMetaUrl?: string): string { if (importMetaUrl) { try { return dirname(fileURLToPath(importMetaUrl)); } catch (error) { // If the URL can't be converted, fall back to process-based heuristics } } if (typeof process !== "undefined" && Array.isArray(process.argv) && process.argv[1]) { return dirname(process.argv[1]); } return process.cwd(); } export function moduleFileFromUrl(importMetaUrl?: string): string | undefined { if (importMetaUrl) { try { return fileURLToPath(importMetaUrl); } catch (error) { // Ignore conversion errors and try other strategies below } } if (typeof process !== "undefined" && Array.isArray(process.argv) && process.argv[1]) { return process.argv[1]; } return undefined; } export function projectRootFrom(startDir: string): string { let currentDir = startDir; const visited = new Set<string>(); while (!visited.has(currentDir)) { visited.add(currentDir); if (existsSync(join(currentDir, "scraped_docs"))) { return currentDir; } const parentDir = dirname(currentDir); if (parentDir === currentDir) { break; } currentDir = parentDir; } return startDir; } export function docsDirFrom(startDir: string): string { return join(projectRootFrom(startDir), "scraped_docs"); } export function pathsAreEqual(a?: string, b?: string): boolean { if (!a || !b) { return false; } return resolve(a) === resolve(b); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/glassBead-tc/mcp-docs-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server