@@ -2,7 +2,9 @@ import hook from './hook';
2
2
import { readFileSync } from 'fs' ;
3
3
import { dirname , sep , relative , resolve } from 'path' ;
4
4
import { get , removeQuotes } from './utility' ;
5
+ import assign from 'lodash.assign' ;
5
6
import identity from 'lodash.identity' ;
7
+ import pick from 'lodash.pick' ;
6
8
import postcss from 'postcss' ;
7
9
8
10
import ExtractImports from 'postcss-modules-extract-imports' ;
@@ -17,6 +19,7 @@ let tokensByFile = {};
17
19
const preProcess = identity ;
18
20
let postProcess ;
19
21
// defaults
22
+ let lazyResultOpts = { } ;
20
23
let plugins = [ LocalByDefault , ExtractImports , Scope ] ;
21
24
let rootDir = process . cwd ( ) ;
22
25
@@ -26,6 +29,7 @@ let rootDir = process.cwd();
26
29
* @param {function } opts.generateScopedName
27
30
* @param {function } opts.processCss
28
31
* @param {string } opts.rootDir
32
+ * @param {string } opts.to
29
33
* @param {array } opts.use
30
34
*/
31
35
export default function setup ( opts = { } ) {
@@ -35,6 +39,8 @@ export default function setup(opts = {}) {
35
39
36
40
postProcess = get ( 'processCss' , null , 'function' , opts ) || null ;
37
41
rootDir = get ( 'rootDir' , [ 'root' , 'd' ] , 'string' , opts ) || process . cwd ( ) ;
42
+ // https://github.com/postcss/postcss/blob/master/docs/api.md#processorprocesscss-opts
43
+ lazyResultOpts = pick ( opts , [ 'to' ] ) ;
38
44
39
45
const customPlugins = get ( 'use' , [ 'u' ] , 'array' , opts ) ;
40
46
if ( customPlugins ) {
@@ -83,7 +89,7 @@ function fetch(_newPath, _sourcePath, _trace) {
83
89
const CSSSource = preProcess ( readFileSync ( filename , 'utf8' ) ) ;
84
90
85
91
const result = postcss ( plugins . concat ( new Parser ( { fetch, trace } ) ) )
86
- . process ( CSSSource , { from : rootRelativePath } )
92
+ . process ( CSSSource , assign ( lazyResultOpts , { from : rootRelativePath } ) )
87
93
. root ;
88
94
89
95
tokens = result . tokens ;
0 commit comments