Skip to content

Commit

Permalink
fix(lib/plugins): support node v0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Oct 14, 2016
1 parent c78eb77 commit c440e6b
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@
* @return {Array} plugins PostCSS Plugins
*/
module.exports = function plugins (config) {
let plugins = []
var plugins = []

if (Array.isArray(config.plugins)) {
plugins = config.plugins

plugins.forEach((plugin) => {
if (typeof plugin !== 'function') {
throw new TypeError(`
${plugin} must be a function, did you require() it ?
`)
}
})
if (plugins.length > 0) {
plugins.forEach(function (plugin) {
if (typeof plugin !== 'function') {
throw new TypeError(
plugin + ' must be a function, did you require() it ?'
)
}
})
}

return plugins
} else {
config = config.plugins

const load = (plugin, options) => {
if (options === null) {
var load = function (plugin, options) {
if (options === null || Object.keys(options).length === 0) {
try {
return require(plugin)
} catch (err) {
Expand All @@ -46,8 +48,12 @@ module.exports = function plugins (config) {
}

Object.keys(config)
.filter((plugin) => config[plugin] !== false ? plugin : '')
.forEach((plugin) => plugins.push(load(plugin, config[plugin])))
.filter(function (plugin) {
return config[plugin] !== false ? plugin : ''
})
.forEach(function (plugin) {
return plugins.push(load(plugin, config[plugin]))
})

return plugins
}
Expand Down

0 comments on commit c440e6b

Please sign in to comment.