diff --git a/.npmrc b/.npmrc index 43c97e7..29426fa 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ package-lock=false +registry=https://registry.npmjs.org \ No newline at end of file diff --git a/package.json b/package.json index 3196ad0..56de3c5 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "3.0.0", "description": "Autoload Config for PostCSS", "main": "src/index.js", + "types": "types/index.d.ts", "files": [ "src" ], diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..b2241cd --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,45 @@ +// based on @types/postcss-load-config@2.0.1 +// Type definitions for postcss-load-config 2.1 +import Processor from 'postcss/lib/processor' +import { Plugin, ProcessOptions, Transformer } from "postcss"; +import { Options as CosmiconfigOptions } from 'cosmiconfig'; + +// 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. +interface ProcessOptionsPreload { + parser?: string | ProcessOptions['parser']; + stringifier?: string | ProcessOptions['stringifier']; + syntax?: string | ProcessOptions['syntax']; +} + +// The remaining ProcessOptions, sans the three above. +type RemainingProcessOptions = + Pick>; + +// Additional context options that postcss-load-config understands. +interface Context { + cwd?: string; + env?: string; +} + +// The full shape of the ConfigContext. +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. +type ResultPlugin = Plugin | Transformer | Processor; + +interface Result { + file: string; + options: ProcessOptions; + plugins: ResultPlugin[]; +} + +declare function postcssrc(ctx?: ConfigContext, path?: string, options?: CosmiconfigOptions): Promise; + +declare namespace postcssrc { + function sync(ctx?: ConfigContext, path?: string, options?: CosmiconfigOptions): Result; +} + +export = postcssrc;