UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

87 lines 4.38 kB
/** * Default file extensions for JavaScript/TypeScript modules that can be resolved */ export declare const JAVASCRIPT_MODULE_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx", ".d.ts"]; /** * Extension priority for type-only imports - prioritize .d.ts first */ export declare const TYPE_IMPORT_EXTENSIONS: readonly [".d.ts", ".ts", ".tsx", ".js", ".jsx"]; /** * Extension priority for value imports - standard priority with .d.ts last */ export declare const VALUE_IMPORT_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx", ".d.ts"]; /** * Checks if a file path or import path represents a JavaScript/TypeScript module * @param path - The file path or import path to check * @returns true if it's a JS/TS module, false otherwise */ export declare function isJavaScriptModule(path: string): boolean; export interface DirectoryEntry { name: string; isFile: boolean; isDirectory: boolean; } export type DirectoryReader = (path: string) => Promise<DirectoryEntry[]>; export interface ResolveModulePathOptions { /** * Array of file extensions to try when resolving modules. * Default: ['.ts', '.tsx', '.js', '.jsx'] */ extensions?: string[]; } export interface TypeAwareResolveResult { import: string; typeImport?: string; } /** * Resolves a module path by reading directory contents to find matching files. * This is more efficient than checking each file individually with stat calls. * * Given a path like `/Code/mui-public/packages/docs-infra/docs/app/components/code-highlighter/demos/code/BasicCode`, * this function will try to find the actual file by checking for: * - `BasicCode.ts`, `BasicCode.tsx`, `BasicCode.js`, `BasicCode.jsx` * - `BasicCode/index.ts`, `BasicCode/index.tsx`, `BasicCode/index.js`, `BasicCode/index.jsx` * * @param modulePath - The module path to resolve (without file extension) * @param readDirectory - Function to read directory contents * @param options - Configuration options * @param includeTypeDefs - If true, returns both import and typeImport paths with different extension priorities * @returns Promise<string | TypeAwareResolveResult> - The resolved file path(s) */ export declare function resolveModulePath(modulePath: string, readDirectory: DirectoryReader, options?: ResolveModulePathOptions, includeTypeDefs?: boolean): Promise<string | TypeAwareResolveResult>; /** * Resolves multiple module paths efficiently by grouping them by directory * and performing batch directory lookups. * * @param modulePaths - Array of module paths to resolve (without file extensions) * @param readDirectory - Function to read directory contents * @param options - Configuration options * @returns Promise<Map<string, string>> - Map from input path to resolved file path */ export declare function resolveModulePaths(modulePaths: string[], readDirectory: DirectoryReader, options?: ResolveModulePathOptions): Promise<Map<string, string>>; /** * Resolves import result by separating JavaScript modules from static assets, * only resolving JavaScript modules and returning a combined map. * This function uses the new type-aware resolveModulePath function internally. * * @param importResult - The result from parseImports containing all imports * @param readDirectory - Function to read directory contents * @param options - Configuration options for module resolution * @returns Promise<Map<string, string>> - Map from import path to resolved file path */ export declare function resolveImportResult(importResult: Record<string, { path: string; names: string[]; includeTypeDefs?: true; }>, readDirectory: DirectoryReader, options?: ResolveModulePathOptions): Promise<Map<string, string>>; /** * Resolves variant paths from a variants object mapping variant names to their file paths. * This function extracts the paths, resolves them using resolveModulePaths, and returns * a map from variant name to resolved file URL. * * @param variants - Object mapping variant names to their file paths * @param readDirectory - Function to read directory contents * @param options - Configuration options for module resolution * @returns Promise<Map<string, string>> - Map from variant name to resolved file URL */ export declare function resolveVariantPaths(variants: Record<string, string>, readDirectory: DirectoryReader, options?: ResolveModulePathOptions): Promise<Map<string, string>>;