index.d.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // based on @types/postcss-load-config@2.0.1
  2. // Type definitions for postcss-load-config 2.1
  3. import Processor from 'postcss/lib/processor';
  4. import { Plugin, ProcessOptions, Transformer } from 'postcss';
  5. import { Options as ConfigOptions } from "lilconfig";
  6. declare function postcssrc(
  7. ctx?: postcssrc.ConfigContext,
  8. path?: string,
  9. options?: ConfigOptions
  10. ): Promise<postcssrc.Result>;
  11. declare namespace postcssrc {
  12. function sync(
  13. ctx?: ConfigContext,
  14. path?: string,
  15. options?: ConfigOptions
  16. ): Result;
  17. // In the ConfigContext, these three options can be instances of the
  18. // appropriate class, or strings. If they are strings, postcss-load-config will
  19. // require() them and pass the instances along.
  20. export interface ProcessOptionsPreload {
  21. parser?: string | ProcessOptions['parser'];
  22. stringifier?: string | ProcessOptions['stringifier'];
  23. syntax?: string | ProcessOptions['syntax'];
  24. }
  25. // The remaining ProcessOptions, sans the three above.
  26. export type RemainingProcessOptions = Pick<
  27. ProcessOptions,
  28. Exclude<keyof ProcessOptions, keyof ProcessOptionsPreload>
  29. >;
  30. // Additional context options that postcss-load-config understands.
  31. export interface Context {
  32. cwd?: string;
  33. env?: string;
  34. }
  35. // The full shape of the ConfigContext.
  36. export type ConfigContext = Context &
  37. ProcessOptionsPreload &
  38. RemainingProcessOptions;
  39. // Result of postcssrc is a Promise containing the filename plus the options
  40. // and plugins that are ready to pass on to postcss.
  41. export type ResultPlugin = Plugin | Transformer | Processor;
  42. export interface Result {
  43. file: string;
  44. options: ProcessOptions;
  45. plugins: ResultPlugin[];
  46. }
  47. export type ConfigPlugin = Transformer | Plugin | Processor;
  48. export interface Config {
  49. parser?: string | ProcessOptions['parser'] | false;
  50. stringifier?: string | ProcessOptions['stringifier'] | false;
  51. syntax?: string | ProcessOptions['syntax'] | false;
  52. map?: string | false;
  53. from?: string;
  54. to?: string;
  55. plugins?: Array<ConfigPlugin | false> | Record<string, object | false>;
  56. }
  57. export type ConfigFn = (ctx: ConfigContext) => Config | Promise<Config>;
  58. }
  59. export = postcssrc;