Skip to main content
Glama
aliases.ts2.01 kB
import { fileURLToPath } from 'node:url'; import { dirname, resolve } from 'node:path'; // Constants for magic numbers and patterns const RELATIVE_PATH_CAPTURE_GROUP = '$1'; const JS_EXTENSION_REGEX = '^(\\.{1,2}/.*)\\.js$'; const currentDir = dirname(fileURLToPath(import.meta.url)); const projectRoot = resolve(currentDir, '..', '..'); const aliasDirectories: Record<string, string> = { '@': 'src', '@src': 'src', '@api': 'src/api', '@config': 'src/config', '@constants': 'src/constants', '@handlers': 'src/handlers', '@services': 'src/services', '@errors': 'src/errors', '@shared-types': 'src/types', '@utils': 'src/utils', '@test-support': 'src/test-support', '@test': 'test', }; // Performance optimization: Cache regex compilation and use more efficient escape const escapeForRegex = (value: string): string => value.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); // Pre-compile regex patterns for better performance const regexCache = new Map<string, RegExp>(); const getOrCreateRegex = (pattern: string): RegExp => { if (!regexCache.has(pattern)) { regexCache.set(pattern, new RegExp(pattern)); } return regexCache.get(pattern)!; }; // Pre-compute alias entries for better startup performance const aliasEntries: Array<{ find: string | RegExp; replacement: string }> = []; // Add string aliases and their corresponding .js mappings for (const [alias, relativePath] of Object.entries(aliasDirectories)) { const absolutePath = resolve(projectRoot, relativePath); // String alias mapping aliasEntries.push({ find: alias, replacement: absolutePath, }); // Cached regex for .js extension mapping const regexPattern = `^${escapeForRegex(alias)}/(.+)\\.js$`; aliasEntries.push({ find: getOrCreateRegex(regexPattern), replacement: `${absolutePath}/$1.ts`, }); } // Relative path .js mapping (cached) aliasEntries.push({ find: getOrCreateRegex(JS_EXTENSION_REGEX), replacement: RELATIVE_PATH_CAPTURE_GROUP, }); export { aliasEntries };

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/kesslerio/attio-mcp-server'

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