Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,42 @@ module.exports = {
npm run preprocess
```

#### Changing plugin order

If duplicate plugins are used, `suitcss` will remove duplicates but also respect the new order. This is useful if you need to change the default order:

```js
// Default order
var defaults = [
'postcss-import',
'postcss-custom-properties',
'postcss-calc',
'postcss-custom-media',
'autoprefixer',
'postcss-reporter'
];

// config
module.exports = {
use: [
'stylelint',
'postcss-calc',
'autoprefixer',
'postcss-reporter'
]
};

var result = [
'postcss-import',
'postcss-custom-properties',
'postcss-custom-media',
'stylelint',
'postcss-calc',
'autoprefixer',
'postcss-reporter'
];
```

### Node.js

Returns a [PostCSS promise](https://github.com/postcss/postcss/blob/master/docs/api.md#lazyresult-class)
Expand Down
14 changes: 7 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Module dependencies
*/
var assign = require('object-assign-deep');
var without = require('lodash/array/without');
var last = require('lodash/array/last');
var isEmpty = require('lodash.isempty');
var difference = require('lodash.difference');
var autoprefixer = require('autoprefixer');
var bemLinter = require('postcss-bem-linter');
var postcss = require('postcss');
Expand Down Expand Up @@ -104,11 +104,11 @@ function mergeOptions(options) {
merged['postcss-import'].root = options.root;
merged['postcss-import'].transform = lintImportedFiles(merged);

// Ensure postcss-reporter is always the final plugin
if (last(merged.use) !== 'postcss-reporter') {
var plugins = without(merged.use, 'postcss-reporter');
plugins.push('postcss-reporter');
merged.use = plugins;
// Allow additional plugins to be merged with the defaults
// but remove any duplicates so that it respects the new order
if (!isEmpty(options.config.use)) {
var dedupedPlugins = difference(merged.use, options.config.use);
merged.use = dedupedPlugins.concat(options.config.use);
}

return merged;
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"chokidar": "^1.3.0",
"colors": "~1.1.2",
"commander": "~2.9.0",
"fs-extra": "^0.26.2",
"cssnano": "^3.3.2",
"lodash": "^3.10.1",
"fs-extra": "^0.26.2",
"lodash.difference": "^3.2.2",
"lodash.isempty": "^3.0.4",
"object-assign-deep": "0.0.4",
"pad-component": "0.0.1",
"postcss": "^5.0.12",
Expand Down
46 changes: 43 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ describe('suitcss', function () {
expect(function() {suitcss({});}).to.throw(Error);
});

describe('passing options', function() {
describe('using options', function() {
var mergeOptions, defaults;

beforeEach(function() {
mergeOptions = suitcss.__get__('mergeOptions');
defaults = suitcss.__get__('defaults');
});

it('should use default options when nothing is passed', function() {
Expand All @@ -41,6 +42,8 @@ describe('suitcss', function () {
];
expect(mergeOptions({})).to.have.keys(keys);
expect(mergeOptions()).to.have.keys(keys);
expect(mergeOptions({}).use).to.eql(defaults.use);
expect(mergeOptions().use).to.eql(defaults.use);
});

it('should allow an import root to be set', function() {
Expand All @@ -58,7 +61,6 @@ describe('suitcss', function () {
var opts = mergeOptions({
root: 'test/root',
config: {
use: ['postcss-property-lookup'],
autoprefixer: autoprefixer
}
});
Expand All @@ -69,12 +71,50 @@ describe('suitcss', function () {
'postcss-calc',
'postcss-custom-media',
'autoprefixer',
'postcss-property-lookup',
'postcss-reporter'
]);
expect(opts.autoprefixer).to.eql(autoprefixer);
expect(opts['postcss-import'].root).to.equal('test/root');
});

describe('re-ordering plugins', function() {
it('should allow reordering of use array and remove duplicates', function() {
var opts = mergeOptions({
config: {
use: ['autoprefixer', 'postcss-at2x', 'postcss-calc', 'postcss-reporter']
}
});

expect(opts.use).to.eql([
'postcss-import',
'postcss-custom-properties',
'postcss-custom-media',
'autoprefixer',
'postcss-at2x',
'postcss-calc',
'postcss-reporter'
]);
});

it('should just append plugins if no duplicates are used', function() {
var opts = mergeOptions({
config: {
use: ['postcss-at2x', 'postcss-property-lookup']
}
});

expect(opts.use).to.eql([
'postcss-import',
'postcss-custom-properties',
'postcss-calc',
'postcss-custom-media',
'autoprefixer',
'postcss-reporter',
'postcss-at2x',
'postcss-property-lookup'
]);
});
});
});
});

Expand Down