File size: 2,221 Bytes
d8f0e51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// based on @types/[email protected]
// Type definitions for postcss-load-config 2.1
import Processor from 'postcss/lib/processor';
import { Plugin, ProcessOptions, Transformer } from 'postcss';
import { Options as ConfigOptions } from "lilconfig";

declare function postcssrc(
  ctx?: postcssrc.ConfigContext,
  path?: string,
  options?: ConfigOptions
): Promise<postcssrc.Result>;

declare namespace postcssrc {
  function sync(
    ctx?: ConfigContext,
    path?: string,
    options?: ConfigOptions
  ): Result;

  // In the ConfigContext, these three options can be instances of the
  // appropriate class, or strings. If they are strings, postcss-load-config will
  // require() them and pass the instances along.
  export interface ProcessOptionsPreload {
    parser?: string | ProcessOptions['parser'];
    stringifier?: string | ProcessOptions['stringifier'];
    syntax?: string | ProcessOptions['syntax'];
  }

  // The remaining ProcessOptions, sans the three above.
  export type RemainingProcessOptions = Pick<
    ProcessOptions,
    Exclude<keyof ProcessOptions, keyof ProcessOptionsPreload>
  >;

  // Additional context options that postcss-load-config understands.
  export interface Context {
    cwd?: string;
    env?: string;
  }

  // The full shape of the ConfigContext.
  export type ConfigContext = Context &
    ProcessOptionsPreload &
    RemainingProcessOptions;

  // Result of postcssrc is a Promise containing the filename plus the options
  // and plugins that are ready to pass on to postcss.
  export type ResultPlugin = Plugin | Transformer | Processor;

  export interface Result {
    file: string;
    options: ProcessOptions;
    plugins: ResultPlugin[];
  }

  export type ConfigPlugin = Transformer | Plugin | Processor;

  export interface Config {
    parser?: string | ProcessOptions['parser'] | false;
    stringifier?: string | ProcessOptions['stringifier'] | false;
    syntax?: string | ProcessOptions['syntax'] | false;
    map?: string | false;
    from?: string;
    to?: string;
    plugins?: Array<ConfigPlugin | false> | Record<string, object | false>;
  }

  export type ConfigFn = (ctx: ConfigContext) => Config | Promise<Config>;
}

export = postcssrc;