Skip to content

feat(index): pass AST (result.root) && Messages (result.messages) as metadata to other loaders #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}