Skip to content

Commit

Permalink
Merge 4620550 into 1cd87ad
Browse files Browse the repository at this point in the history
  • Loading branch information
seebees authored Oct 17, 2019
2 parents 1cd87ad + 4620550 commit 9d6e4cf
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,34 @@ function executeProcessor (process, file, content) {
}
}
})
return process(content, file, done) || donePromise

/* The original API for Preprocessors assumed callback.
* Now promises are a valid return.
* If an implementer returns a promise from `process`
* but only resolves content via the callback,
* then while the result of `process` is a promise,
* it will not resolve to the intended content.
* An easy example is for `process` to be an `async` function.
* e.g.
* ```
* async function process(content, file, done) {
* const newContent = await magic(content)
* done(newContent)
* }
* ```
*/
const result = process(content, file, done)
return result && result.then
? result.then(intendedToReturnContentInPromise)
: donePromise

function intendedToReturnContentInPromise(content) {
if (content) {
return content
} else {
return donePromise
}
}
}

async function runProcessors (preprocessors, file, content) {
Expand Down

0 comments on commit 9d6e4cf

Please sign in to comment.