Skip to content

Commit

Permalink
Add type definition file (#211)
Browse files Browse the repository at this point in the history
* Add type definition file

* Mention type definition original project

* Fix npm registry

Co-authored-by: dengbin03 <dengbin03@kuaishou.com>
  • Loading branch information
chang-ke and dengbin03 authored Feb 7, 2021
1 parent c45a213 commit 65c904a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
registry=https://registry.npmjs.org
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.0.0",
"description": "Autoload Config for PostCSS",
"main": "src/index.js",
"types": "types/index.d.ts",
"files": [
"src"
],
Expand Down
45 changes: 45 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<ProcessOptions, Exclude<keyof ProcessOptions, keyof ProcessOptionsPreload>>;

// 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<Result>;

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

export = postcssrc;

0 comments on commit 65c904a

Please sign in to comment.