diff --git a/types/css-modules-loader-core/css-modules-loader-core-tests.ts b/types/css-modules-loader-core/css-modules-loader-core-tests.ts new file mode 100644 index 0000000000..d8fe2966d7 --- /dev/null +++ b/types/css-modules-loader-core/css-modules-loader-core-tests.ts @@ -0,0 +1,24 @@ +/// + +import Core, { Source } from "css-modules-loader-core"; + +const core = new Core(); +const emptyPlugins = new Core([]); +const withPlugins = new Core([ + Core.values, + Core.localByDefault, + Core.extractImports, + Core.scope +]); +const withDefaultPlugins = new Core(Core.defaultPlugins); + +// $ExpectError +const noArray = new Core(Core.values); + +// Validating the source can be anything that has toString() defined +const bufferSource: Source = new Buffer("str"); + +core.load("str").then(({ injectableSource, exportTokens }) => { + const str: string = injectableSource; + exportTokens["key"] = "value"; +}); diff --git a/types/css-modules-loader-core/index.d.ts b/types/css-modules-loader-core/index.d.ts new file mode 100644 index 0000000000..d7bd533ac1 --- /dev/null +++ b/types/css-modules-loader-core/index.d.ts @@ -0,0 +1,50 @@ +// Type definitions for css-modules-loader-core 1.1 +// Project: https://github.com/css-modules/css-modules-loader-core +// Definitions by: Spencer Miskoviak +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +import { Plugin } from "postcss"; + +declare namespace Core { + type Source = + | string + | { + toString(): string; + }; + + type PathFetcher = ( + file: string, + relativeTo: string, + depTrace: string + ) => void; + + interface ExportTokens { + [index: string]: string; + } + + interface Result { + injectableSource: string; + exportTokens: ExportTokens; + } +} + +declare class Core { + static values: Plugin<{}>; + static localByDefault: Plugin<{}>; + static extractImports: Plugin<{}>; + static scope: Plugin<{}>; + static defaultPlugins: Array>; + + constructor(plugins?: Array>); + + load( + source: Core.Source, + sourcePath?: string, + trace?: string, + pathFetcher?: Core.PathFetcher + ): Promise; +} + +export = Core; +export as namespace Core; diff --git a/types/css-modules-loader-core/package.json b/types/css-modules-loader-core/package.json new file mode 100644 index 0000000000..06a694067a --- /dev/null +++ b/types/css-modules-loader-core/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "postcss": "7.x.x" + } +} diff --git a/types/css-modules-loader-core/tsconfig.json b/types/css-modules-loader-core/tsconfig.json new file mode 100644 index 0000000000..a4b15a0258 --- /dev/null +++ b/types/css-modules-loader-core/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true, + "strictFunctionTypes": true + }, + "files": [ + "index.d.ts", + "css-modules-loader-core-tests.ts" + ] +} diff --git a/types/css-modules-loader-core/tslint.json b/types/css-modules-loader-core/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/css-modules-loader-core/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }