Skip to content

Commit

Permalink
refactor: detect process name
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Feb 8, 2018
1 parent 47184c1 commit 17b7866
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/post-processor.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
const findProcessorName = args => {
const ctx = args.find(ctx => Reflect.has(ctx, 'processor') && Reflect.has(ctx.processor, 'name'));
let name = ctx ? ctx.processor.name : undefined;
const detect = args => {
const {processor: {name, plugins}} = args.find(ctx => Reflect.has(ctx, 'processor') && Reflect.has(ctx.processor, 'name'));

// Detect postcss
if (name === undefined && args[0].type === 'root' && Reflect.has(args[1], 'processor')) {
name = 'postcss';
return {
name: (name || 'postcss').toLowerCase(),
plugins
}

// Detect reshape
if (name === undefined && Reflect.has(args[1], 'ReshapeError')) {
name = 'reshape';
}

return name.toLowerCase();
};

export default (...ctx) => ({
name: findProcessorName(ctx)
});
export default (...ctx) => detect(ctx);

0 comments on commit 17b7866

Please sign in to comment.