Skip to content

Commit 2a6f905

Browse files
committed
possibility to provide any processor options
1 parent b1bc1ef commit 2a6f905

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function setupHook({
2626
ignore,
2727
preprocessCss = identity,
2828
processCss,
29-
to,
29+
processorOpts,
3030
append = [],
3131
prepend = [],
3232
createImportedName,
@@ -96,7 +96,7 @@ module.exports = function setupHook({
9696

9797
const source = preprocessCss(readFileSync(filename, 'utf8'), filename);
9898
// https://github.com/postcss/postcss/blob/master/docs/api.md#processorprocesscss-opts
99-
const lazyResult = runner.process(source, assign({}, {from: filename}));
99+
const lazyResult = runner.process(source, assign({}, processorOpts, {from: filename}));
100100

101101
// https://github.com/postcss/postcss/blob/master/docs/api.md#lazywarnings
102102
lazyResult.warnings().forEach(message => console.warn(message.text));

lib/validate.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const rules = {
99
ignore: 'function|regex|string',
1010
preprocessCss: 'function',
1111
processCss: 'function',
12-
to: 'string',
12+
processorOpts: 'object',
1313
// plugins
1414
append: 'array',
1515
prepend: 'array',
@@ -24,6 +24,7 @@ const tests = {
2424
array: require('lodash').isArray,
2525
boolean: require('lodash').isBoolean,
2626
function: require('lodash').isFunction,
27+
object: require('lodash').isPlainObject,
2728
regex: require('lodash').isRegExp,
2829
string: require('lodash').isString,
2930
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"in-publish": "^2.0.0",
5858
"isparta": "^4.0.0",
5959
"mocha": "^2.4.5",
60+
"postcss-less": "^0.2.0",
6061
"sinon": "^1.17.3"
6162
}
6263
}

test/api/fixture/oceanic.less

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.color
2+
{
3+
background: #1e2a35;
4+
}

test/api/processorOpts.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const detachHook = require('../sugar').detachHook;
2+
const dropCache = require('../sugar').dropCache;
3+
const identity = require('lodash').identity;
4+
5+
const lessParser = require('postcss-less').parse;
6+
7+
// https://github.com/postcss/postcss/blob/master/docs/api.md#processorprocesscss-opts
8+
suite('api/processorOpts()', () => {
9+
test('should provide possibility to specify custom processor options, for example: parser', () => {
10+
const tokens = require('./fixture/oceanic.less');
11+
assert.deepEqual(tokens, {color: '_test_api_fixture_oceanic__color'});
12+
});
13+
14+
setup(() => {
15+
hook({
16+
extensions: '.less',
17+
processorOpts: {parser: lessParser},
18+
});
19+
});
20+
21+
teardown(() => {
22+
detachHook('.less');
23+
dropCache('./api/fixture/oceanic.less');
24+
});
25+
});

0 commit comments

Comments
 (0)