diff --git a/src/core/post-process.js b/src/core/post-process.js index 20d0fc53f3..a1dc31a894 100644 --- a/src/core/post-process.js +++ b/src/core/post-process.js @@ -15,27 +15,25 @@ export const name = "core/post-process"; export async function run(config) { if (Array.isArray(config.postProcess)) { - const promises = config.postProcess - .filter(f => { - const isFunction = typeof f === "function"; - if (!isFunction) { - const msg = "Every item in `postProcess` must be a JS function."; - showError(msg, name); - } - return isFunction; - }) - .map(async (f, i) => { - const fnName = `${name}/${f.name || `[${i}]`}`; - const utils = makePluginUtils(fnName); - try { - return await f(config, document, utils); - } catch (err) { - const msg = `Function ${f.name} threw an error during \`postProcess\`.`; - const hint = "See developer console."; - showError(msg, name, { hint, cause: err }); - } - }); - await Promise.all(promises); + const functions = config.postProcess.filter(f => { + const isFunction = typeof f === "function"; + if (!isFunction) { + const msg = "Every item in `postProcess` must be a JS function."; + showError(msg, name); + } + return isFunction; + }); + for (const [i, f] of functions.entries()) { + const fnName = `${name}/${f.name || `[${i}]`}`; + const utils = makePluginUtils(fnName); + try { + await f(config, document, utils); + } catch (err) { + const msg = `Function ${fnName} threw an error during \`postProcess\`.`; + const hint = "See developer console."; + showError(msg, name, { hint, cause: err }); + } + } } if (typeof config.afterEnd === "function") { await config.afterEnd(config, document); diff --git a/src/core/pre-process.js b/src/core/pre-process.js index b9a389f920..e66fde2ac8 100644 --- a/src/core/pre-process.js +++ b/src/core/pre-process.js @@ -14,26 +14,24 @@ export const name = "core/pre-process"; export async function run(config) { if (Array.isArray(config.preProcess)) { - const promises = config.preProcess - .filter(f => { - const isFunction = typeof f === "function"; - if (!isFunction) { - const msg = "Every item in `preProcess` must be a JS function."; - showError(msg, name); - } - return isFunction; - }) - .map(async (f, i) => { - const fnName = `${name}/${f.name || `[${i}]`}`; - const utils = makePluginUtils(fnName); - try { - return await f(config, document, utils); - } catch (err) { - const msg = `Function ${f.name} threw an error during \`preProcess\`.`; - const hint = "See developer console."; - showError(msg, name, { hint, cause: err }); - } - }); - await Promise.all(promises); + const functions = config.preProcess.filter(f => { + const isFunction = typeof f === "function"; + if (!isFunction) { + const msg = "Every item in `preProcess` must be a JS function."; + showError(msg, name); + } + return isFunction; + }); + for (const [i, f] of functions.entries()) { + const fnName = `${name}/${f.name || `[${i}]`}`; + const utils = makePluginUtils(fnName); + try { + await f(config, document, utils); + } catch (err) { + const msg = `Function ${fnName} threw an error during \`preProcess\`.`; + const hint = "See developer console."; + showError(msg, name, { hint, cause: err }); + } + } } } diff --git a/tests/spec/core/pre-process-spec.html b/tests/spec/core/pre-process-spec.html index f08ca1a7a5..0bc399306c 100644 --- a/tests/spec/core/pre-process-spec.html +++ b/tests/spec/core/pre-process-spec.html @@ -1,53 +1,58 @@