@@ -2,24 +2,25 @@ import fs from 'fs-extra';
2
2
import { cosmiconfigSync } from 'cosmiconfig' ;
3
3
import postcss , { AcceptedPlugin , Parser , Root } from 'postcss' ;
4
4
5
- // TODO this could proably use some better type definitions, but I can't find them :(
6
- const explorer = cosmiconfigSync ( 'postcss' ) ;
7
- const found = explorer . search ( ) ;
8
- const config = found ! . config ;
9
-
10
- export const importer = require ( 'postcss-import' ) ( config . plugins [ 'postcss-import' ] ) as AcceptedPlugin ;
11
- export const localByDefault = require ( 'postcss-modules-local-by-default' ) as AcceptedPlugin ;
12
- export const scope = require ( 'postcss-modules-scope' ) as AcceptedPlugin ;
13
- export const comment = require ( 'postcss-comment' ) as Parser ;
14
-
15
- export const defaultPlugins = [ importer , localByDefault , scope ] ;
16
-
17
5
export type ParserReturn = Set < string > ;
18
6
19
7
export async function parser (
20
8
filePath : string ,
9
+ config : any ,
21
10
plugins : AcceptedPlugin [ ] | null = null ,
22
11
) : Promise < ParserReturn > {
12
+ // TODO config is 'any' this could probably use some better type definitions, but I can't find them :(
13
+ if ( config === undefined ) {
14
+ config = cosmiconfigSync ( 'postcss' ) . search ( ) ?. config ?? { } ;
15
+ }
16
+
17
+ const importer = require ( 'postcss-import' ) ( config . plugins [ 'postcss-import' ] ) as AcceptedPlugin ;
18
+ const localByDefault = require ( 'postcss-modules-local-by-default' ) as AcceptedPlugin ;
19
+ const scope = require ( 'postcss-modules-scope' ) as AcceptedPlugin ;
20
+ const comment = require ( 'postcss-comment' ) as Parser ;
21
+
22
+ const defaultPlugins = [ importer , localByDefault , scope ] ;
23
+
23
24
const exportTokens = new Set < string > ( ) ;
24
25
25
26
const gatherPlugIn = ( root : Root ) => {
0 commit comments