@@ -2,7 +2,9 @@ import hook from './hook';
22import { readFileSync } from 'fs' ;
33import { dirname , sep , relative , resolve } from 'path' ;
44import { get , removeQuotes } from './utility' ;
5+ import assign from 'lodash.assign' ;
56import identity from 'lodash.identity' ;
7+ import pick from 'lodash.pick' ;
68import postcss from 'postcss' ;
79
810import ExtractImports from 'postcss-modules-extract-imports' ;
@@ -17,6 +19,7 @@ let tokensByFile = {};
1719const preProcess = identity ;
1820let postProcess ;
1921// defaults
22+ let lazyResultOpts = { } ;
2023let plugins = [ LocalByDefault , ExtractImports , Scope ] ;
2124let rootDir = process . cwd ( ) ;
2225
@@ -26,6 +29,7 @@ let rootDir = process.cwd();
2629 * @param {function } opts.generateScopedName
2730 * @param {function } opts.processCss
2831 * @param {string } opts.rootDir
32+ * @param {string } opts.to
2933 * @param {array } opts.use
3034 */
3135export default function setup ( opts = { } ) {
@@ -35,6 +39,8 @@ export default function setup(opts = {}) {
3539
3640 postProcess = get ( 'processCss' , null , 'function' , opts ) || null ;
3741 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' ] ) ;
3844
3945 const customPlugins = get ( 'use' , [ 'u' ] , 'array' , opts ) ;
4046 if ( customPlugins ) {
@@ -83,7 +89,7 @@ function fetch(_newPath, _sourcePath, _trace) {
8389 const CSSSource = preProcess ( readFileSync ( filename , 'utf8' ) ) ;
8490
8591 const result = postcss ( plugins . concat ( new Parser ( { fetch, trace } ) ) )
86- . process ( CSSSource , { from : rootRelativePath } )
92+ . process ( CSSSource , assign ( lazyResultOpts , { from : rootRelativePath } ) )
8793 . root ;
8894
8995 tokens = result . tokens ;
0 commit comments