index.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Custom resolver function for dynamic alias resolution
  3. * @param fromPath - Full path of the file from which import/require was called
  4. * @param request - The full import path (e.g. '@src/utils.js')
  5. * @param alias - The alias being matched (e.g. '@src')
  6. * @returns The resolved absolute path
  7. */
  8. type AliasResolver = (fromPath: string, request: string, alias: string) => string;
  9. /**
  10. * Register a single alias
  11. * @param alias - The alias to register (e.g. '@utils')
  12. * @param target - The target path or a resolver function
  13. */
  14. export function addAlias(alias: string, target: string | AliasResolver): void;
  15. /**
  16. * Register multiple aliases at once
  17. * @param aliases - Object mapping aliases to target paths or resolver functions
  18. */
  19. export function addAliases(aliases: Record<string, string | AliasResolver>): void;
  20. /**
  21. * Register a custom module directory (like node_modules)
  22. * @param path - The directory path to add
  23. */
  24. export function addPath(path: string): void;
  25. /**
  26. * Reset all registered aliases and paths
  27. */
  28. export function reset(): void;
  29. /**
  30. * Initialize module-alias from a package.json file
  31. * @param options - Path to package.json or options object
  32. */
  33. declare function moduleAlias(options?: string | { base?: string }): void;
  34. export default moduleAlias;