added definitions for postcss-load-config (#36053)

This commit is contained in:
Bob Matcuk 2019-06-12 16:18:16 -07:00 committed by Ron Buckton
parent 0c112a5de1
commit f396262330
5 changed files with 88 additions and 0 deletions

47
types/postcss-load-config/index.d.ts vendored Normal file
View File

@ -0,0 +1,47 @@
// Type definitions for postcss-load-config 2.0
// Project: https://github.com/michael-ciniawsky/postcss-load-config#readme
// Definitions by: Bob Matcuk <https://github.com/bmatcuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { Parser, Plugin, ProcessOptions, Processor, Stringifier, Syntax, Transformer } from "postcss";
import cosmiconfig = require("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<any> | Transformer | Processor;
interface Result {
file: string;
options: ProcessOptions;
plugins: ResultPlugin[];
}
declare function postcssrc(ctx?: ConfigContext, path?: string, options?: cosmiconfig.ExplorerOptions): Promise<Result>;
declare namespace postcssrc {
function sync(ctx?: ConfigContext, path?: string, options?: cosmiconfig.ExplorerOptions): Result;
}
export = postcssrc;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"postcss": "^7.0.0"
}
}

View File

@ -0,0 +1,11 @@
import postcss = require("postcss");
import postcssrc = require("postcss-load-config");
postcssrc();
postcssrc({ map: { inline: true } });
postcssrc({ env: 'development' }, 'path');
postcssrc({ from: 'from', to: 'to' }, 'path', { cache: true }).then(({ options, plugins }) => {
postcss(plugins).process('css', options);
});
postcssrc.sync({ parser: 'my-parser' }, 'path', { cache: true });

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"postcss-load-config-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }