From f396262330cd60f0483db8ebd7aa54e86cd254d6 Mon Sep 17 00:00:00 2001 From: Bob Matcuk Date: Wed, 12 Jun 2019 16:18:16 -0700 Subject: [PATCH] added definitions for postcss-load-config (#36053) --- types/postcss-load-config/index.d.ts | 47 +++++++++++++++++++ types/postcss-load-config/package.json | 6 +++ .../postcss-load-config-tests.ts | 11 +++++ types/postcss-load-config/tsconfig.json | 23 +++++++++ types/postcss-load-config/tslint.json | 1 + 5 files changed, 88 insertions(+) create mode 100644 types/postcss-load-config/index.d.ts create mode 100644 types/postcss-load-config/package.json create mode 100644 types/postcss-load-config/postcss-load-config-tests.ts create mode 100644 types/postcss-load-config/tsconfig.json create mode 100644 types/postcss-load-config/tslint.json diff --git a/types/postcss-load-config/index.d.ts b/types/postcss-load-config/index.d.ts new file mode 100644 index 0000000000..4ece32da66 --- /dev/null +++ b/types/postcss-load-config/index.d.ts @@ -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 +// 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>; + +// 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?: cosmiconfig.ExplorerOptions): Promise; + +declare namespace postcssrc { + function sync(ctx?: ConfigContext, path?: string, options?: cosmiconfig.ExplorerOptions): Result; +} + +export = postcssrc; diff --git a/types/postcss-load-config/package.json b/types/postcss-load-config/package.json new file mode 100644 index 0000000000..57e9c40057 --- /dev/null +++ b/types/postcss-load-config/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "postcss": "^7.0.0" + } +} diff --git a/types/postcss-load-config/postcss-load-config-tests.ts b/types/postcss-load-config/postcss-load-config-tests.ts new file mode 100644 index 0000000000..72731600f4 --- /dev/null +++ b/types/postcss-load-config/postcss-load-config-tests.ts @@ -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 }); diff --git a/types/postcss-load-config/tsconfig.json b/types/postcss-load-config/tsconfig.json new file mode 100644 index 0000000000..eec67f2941 --- /dev/null +++ b/types/postcss-load-config/tsconfig.json @@ -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" + ] +} diff --git a/types/postcss-load-config/tslint.json b/types/postcss-load-config/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/postcss-load-config/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }