b28daf3e57b33fc3fb1791a07571929d9a2c3c5df751751e56131000612b6e2835f76b5019604ada0eb868b43cc155d166f3ea09783da2feef89c5b0b9987c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. export interface ImportGlobOptions<
  2. Eager extends boolean,
  3. AsType extends string,
  4. > {
  5. /**
  6. * Import type for the import url.
  7. */
  8. as?: AsType
  9. /**
  10. * Import as static or dynamic
  11. *
  12. * @default false
  13. */
  14. eager?: Eager
  15. /**
  16. * Import only the specific named export. Set to `default` to import the default export.
  17. */
  18. import?: string
  19. /**
  20. * Custom queries
  21. */
  22. query?: string | Record<string, string | number | boolean>
  23. /**
  24. * Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
  25. *
  26. * @default false
  27. */
  28. exhaustive?: boolean
  29. }
  30. export type GeneralImportGlobOptions = ImportGlobOptions<boolean, string>
  31. export interface KnownAsTypeMap {
  32. raw: string
  33. url: string
  34. worker: Worker
  35. }
  36. export interface ImportGlobFunction {
  37. /**
  38. * Import a list of files with a glob pattern.
  39. *
  40. * Overload 1: No generic provided, infer the type from `eager` and `as`
  41. */
  42. <
  43. Eager extends boolean,
  44. As extends string,
  45. T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown,
  46. >(
  47. glob: string | string[],
  48. options?: ImportGlobOptions<Eager, As>,
  49. ): (Eager extends true ? true : false) extends true
  50. ? Record<string, T>
  51. : Record<string, () => Promise<T>>
  52. /**
  53. * Import a list of files with a glob pattern.
  54. *
  55. * Overload 2: Module generic provided, infer the type from `eager: false`
  56. */
  57. <M>(
  58. glob: string | string[],
  59. options?: ImportGlobOptions<false, string>,
  60. ): Record<string, () => Promise<M>>
  61. /**
  62. * Import a list of files with a glob pattern.
  63. *
  64. * Overload 3: Module generic provided, infer the type from `eager: true`
  65. */
  66. <M>(
  67. glob: string | string[],
  68. options: ImportGlobOptions<true, string>,
  69. ): Record<string, M>
  70. }
  71. export interface ImportGlobEagerFunction {
  72. /**
  73. * Eagerly import a list of files with a glob pattern.
  74. *
  75. * Overload 1: No generic provided, infer the type from `as`
  76. */
  77. <
  78. As extends string,
  79. T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown,
  80. >(
  81. glob: string | string[],
  82. options?: Omit<ImportGlobOptions<boolean, As>, 'eager'>,
  83. ): Record<string, T>
  84. /**
  85. * Eagerly import a list of files with a glob pattern.
  86. *
  87. * Overload 2: Module generic provided
  88. */
  89. <M>(
  90. glob: string | string[],
  91. options?: Omit<ImportGlobOptions<boolean, string>, 'eager'>,
  92. ): Record<string, M>
  93. }