resolver.d.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. export interface Resolver {
  2. requestToFile?(publicPath: string, root: string): string | undefined;
  3. fileToRequest?(filePath: string, root: string): string | undefined;
  4. alias?: ((id: string) => string | undefined) | Record<string, string>;
  5. }
  6. export interface InternalResolver {
  7. requestToFile(publicPath: string): string;
  8. fileToRequest(filePath: string): string;
  9. normalizePublicPath(publicPath: string): string;
  10. alias(id: string): string | undefined;
  11. resolveRelativeRequest(publicPath: string, relativePublicPath: string): {
  12. pathname: string;
  13. query: string;
  14. };
  15. isPublicRequest(publicPath: string): boolean;
  16. isAssetRequest(filePath: string): boolean;
  17. }
  18. export declare const supportedExts: string[];
  19. export declare const mainFields: string[];
  20. export declare function createResolver(root: string, resolvers?: Resolver[], userAlias?: Record<string, string>, assetsInclude?: (file: string) => boolean): InternalResolver;
  21. export declare const jsSrcRE: RegExp;
  22. /**
  23. * Redirects a bare module request to a full path under /@modules/
  24. * It resolves a bare node module id to its full entry path so that relative
  25. * imports from the entry can be correctly resolved.
  26. * e.g.:
  27. * - `import 'foo'` -> `import '/@modules/foo/dist/index.js'`
  28. * - `import 'foo/bar/baz'` -> `import '/@modules/foo/bar/baz.js'`
  29. */
  30. export declare function resolveBareModuleRequest(root: string, id: string, importer: string, resolver: InternalResolver): string;
  31. export declare function resolveOptimizedModule(root: string, id: string): string | undefined;
  32. interface NodeModuleInfo {
  33. entry: string | undefined;
  34. entryFilePath: string | undefined;
  35. pkg: any;
  36. }
  37. export declare function resolveNodeModule(root: string, id: string, resolver: InternalResolver): NodeModuleInfo | undefined;
  38. export declare function resolveNodeModuleFile(root: string, id: string): string | undefined;
  39. export {};