Skip to content

Commit

Permalink
fix(index): simplify config loading behaviour (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky authored Jun 14, 2017
1 parent 2ef4449 commit b313478
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit b313478

Please sign in to comment.