Skip to content

Commit

Permalink
feat(index): pass AST (result.root) && Messages (result.messages)…
Browse files Browse the repository at this point in the history
… as metadata to other loaders (#322)
  • Loading branch information
michael-ciniawsky authored Feb 2, 2018
1 parent 4e8e20c commit 56232e7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const SyntaxError = require('./Error')
*
* @return {cb} cb Result
*/
module.exports = function loader (css, map) {
module.exports = function loader (css, map, meta) {
const options = Object.assign({}, loaderUtils.getOptions(this))

validateOptions(require('./options.json'), options, 'PostCSS Loader')
Expand Down Expand Up @@ -160,6 +160,11 @@ module.exports = function loader (css, map) {
map.sources = map.sources.map((src) => path.resolve(src))
}

if (!meta) meta = {}

meta.ast = { 'type': 'postcss', root: result.root }
meta.messages = result.messages

if (this.loaderIndex === 0) {
/**
* @memberof loader
Expand All @@ -173,6 +178,7 @@ module.exports = function loader (css, map) {

return null
}

/**
* @memberof loader
* @callback cb
Expand All @@ -181,12 +187,13 @@ module.exports = function loader (css, map) {
* @param {String} css Result (Raw Module)
* @param {Object} map Source Map
*/
cb(null, css, map)
cb(null, css, map, meta)

return null
})
}).catch((err) => {
if (err.file) this.addDependency(err.file)

return err.name === 'CssSyntaxError' ? cb(new SyntaxError(err)) : cb(err)
})
}

0 comments on commit 56232e7

Please sign in to comment.