UNPKG

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