From a49be2377a230c77808af89bb9279e846602aab9 Mon Sep 17 00:00:00 2001 From: Michael Ciniawsky Date: Wed, 14 Jun 2017 16:55:48 +0200 Subject: [PATCH] fix(index): simplify config loading behaviour --- lib/index.js | 62 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/index.js b/lib/index.js index eb135a75..6e433f6d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -47,43 +47,43 @@ module.exports = function loader (css, map) { validateOptions(require('./options.json'), options, 'PostCSS Loader') - const rc = { - path: path.dirname(file), - ctx: { - file: { - extname: path.extname(file), - dirname: path.dirname(file), - basename: path.basename(file) - }, - options: {} - } - } + const sourceMap = options.sourceMap - if (options.config) { - if (options.config.path) { - rc.path = path.resolve(options.config.path) - } + Promise.resolve().then(() => { + const length = Object.keys(options) + .filter((option) => { + // if (option === 'exec') return + if (option === 'config') return + if (option === 'sourceMap') return - if (options.config.ctx) { - rc.ctx.options = options.config.ctx + return option + }) + .length + + if (length) { + return parseOptions.call(this, options) } - } - const sourceMap = options.sourceMap + const rc = { + path: path.dirname(file), + ctx: { + file: { + extname: path.extname(file), + dirname: path.dirname(file), + basename: path.basename(file) + }, + options: {} + } + } - Promise.resolve().then(() => { - const length = Object.keys(options).length + if (options.config) { + if (options.config.path) { + rc.path = path.resolve(options.config.path) + } - // TODO - // Refactor - if (!options.config && !sourceMap && length) { - return parseOptions.call(this, options) - } else if (options.config && !sourceMap && length > 1) { - return parseOptions.call(this, options) - } else if (!options.config && sourceMap && length > 1) { - return parseOptions.call(this, options) - } else if (options.config && sourceMap && length > 2) { - return parseOptions.call(this, options) + if (options.config.ctx) { + rc.ctx.options = options.config.ctx + } } return postcssrc(rc.ctx, rc.path, { argv: false })