Skip to content
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

fix: Preprocessors may return promises, but not resolve to 'content'. #3383

Closed
Closed
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
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