resolve.d.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { BaseException } from '../src';
  2. /**
  3. * Exception thrown when a module could not be resolved.
  4. * @deprecated since version 8. Use `MODULE_NOT_FOUND` Node error code instead.
  5. */
  6. export declare class ModuleNotFoundException extends BaseException {
  7. readonly moduleName: string;
  8. readonly basePath: string;
  9. readonly code: string;
  10. constructor(moduleName: string, basePath: string);
  11. }
  12. /** @deprecated since version 8. Use `require.resolve` instead. */
  13. export interface ResolveOptions {
  14. /**
  15. * The basedir to use from which to resolve.
  16. */
  17. basedir: string;
  18. /**
  19. * The list of extensions to resolve. By default uses Object.keys(require.extensions).
  20. */
  21. extensions?: string[];
  22. /**
  23. * An additional list of paths to look into.
  24. */
  25. paths?: string[];
  26. /**
  27. * Whether or not to preserve symbolic links. If false, the actual paths pointed by
  28. * the symbolic links will be used. This defaults to true.
  29. */
  30. preserveSymlinks?: boolean;
  31. /**
  32. * Whether to fallback to a global lookup if the basedir one failed.
  33. */
  34. checkGlobal?: boolean;
  35. /**
  36. * Whether to fallback to using the local caller's directory if the basedir failed.
  37. */
  38. checkLocal?: boolean;
  39. /**
  40. * Whether to only resolve and return the first package.json file found. By default,
  41. * resolves the main field or the index of the package.
  42. */
  43. resolvePackageJson?: boolean;
  44. }
  45. /** @deprecated since version 8. Use `require.resolve` instead. */
  46. export declare function setResolveHook(hook: ((x: string, options: ResolveOptions) => string | null) | null): void;
  47. /**
  48. * Resolve a package using a logic similar to npm require.resolve, but with more options.
  49. * @param packageName The package name to resolve.
  50. * @param options A list of options. See documentation of those options.
  51. * @returns {string} Path to the index to include, or if `resolvePackageJson` option was
  52. * passed, a path to that file.
  53. * @throws {ModuleNotFoundException} If no module with that name was found anywhere.
  54. * @deprecated since version 8. Use `require.resolve` instead.
  55. */
  56. export declare function resolve(packageName: string, options: ResolveOptions): string;