diff --git a/packages/@vuepress/core/lib/plugin-api/abstract/AsyncOption.js b/packages/@vuepress/core/lib/plugin-api/abstract/AsyncOption.js index 26186a8bbf01f5a52a4fe13ad44df0094d1948c0..b3ea711d6c1f2d8a34b471cfd78be30d8fefca63 100644 --- a/packages/@vuepress/core/lib/plugin-api/abstract/AsyncOption.js +++ b/packages/@vuepress/core/lib/plugin-api/abstract/AsyncOption.js @@ -11,69 +11,69 @@ const Option = require('./Option') * Expose Asynchronous Option. */ -class AsyncOption extends Option {} +class AsyncOption extends Option { + /** + * Asynchronous serial running + * @param args + * @param {Array} args + */ -/** - * Asynchronous serial running - * @param args - * @param {Array} args - */ - -AsyncOption.prototype.asyncApply = async function (...args) { - const items = [] - for (const { name, value } of this.items) { - try { - items.push({ - name, - value: isFunction(value) - ? await value(...args) - : value - }) - } catch (error) { - logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`) - throw error + async asyncApply (...args) { + const items = [] + for (const { name, value } of this.items) { + try { + items.push({ + name, + value: isFunction(value) + ? await value(...args) + : value + }) + } catch (error) { + logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`) + throw error + } } + this.appliedItems = items } - this.appliedItems = items -} -/** - * Asynchronous serial running - * @param args - * @param {Array} args - */ + /** + * Asynchronous serial running + * @param args + * @param {Array} args + */ -AsyncOption.prototype.parallelApply = async function (...args) { - const items = [] - await Promise.all(this.items.map(async ({ name, value }) => { - try { - items.push({ - name, - value: isFunction(value) - ? await value(...args) - : value - }) - } catch (error) { - logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`) + async parallelApply (...args) { + const items = [] + await Promise.all(this.items.map(async ({ name, value }) => { + try { + items.push({ + name, + value: isFunction(value) + ? await value(...args) + : value + }) + } catch (error) { + logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`) + throw error + } + })).catch(error => { throw error - } - })).catch(error => { - throw error - }) - return items -} + }) + return items + } -/** - * Process a value via a pipeline. - * @param input - * @returns {*} - */ + /** + * Process a value via a pipeline. + * @param input + * @returns {*} + */ -AsyncOption.prototype.pipeline = async function (input) { - for (const fn of this.values) { - input = await fn(input) + async pipeline (input) { + for (const fn of this.values) { + input = await fn(input) + } + return input } - return input } AsyncOption.prototype.apply = AsyncOption.prototype.asyncApply