Skip to content

Commit 6b93624

Browse files
committed
possibility to set up "to" option to the lazyResult instance
1 parent f02fbc8 commit 6b93624

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
"node": ">=0.12"
88
},
99
"dependencies": {
10+
"lodash.assign": "^3.2.0",
1011
"lodash.identity": "^3.0.0",
1112
"lodash.isarray": "^3.0.4",
1213
"lodash.isfunction": "^3.0.6",
13-
"lodash.isstring": "^3.0.1"
14+
"lodash.isstring": "^3.0.1",
15+
"lodash.pick": "^3.1.0"
1416
},
1517
"devDependencies": {
1618
"babel": "^5.8.20",

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import hook from './hook';
22
import { readFileSync } from 'fs';
33
import { dirname, sep, relative, resolve } from 'path';
44
import { get, removeQuotes } from './utility';
5+
import assign from 'lodash.assign';
56
import identity from 'lodash.identity';
7+
import pick from 'lodash.pick';
68
import postcss from 'postcss';
79

810
import ExtractImports from 'postcss-modules-extract-imports';
@@ -17,6 +19,7 @@ let tokensByFile = {};
1719
const preProcess = identity;
1820
let postProcess;
1921
// defaults
22+
let lazyResultOpts = {};
2023
let plugins = [LocalByDefault, ExtractImports, Scope];
2124
let 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
*/
3135
export 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

Comments
 (0)