diff --git a/packages/@vuepress/core/lib/node/Page.js b/packages/@vuepress/core/lib/node/Page.js index 99cb6d4eaa..07f50b4b5c 100644 --- a/packages/@vuepress/core/lib/node/Page.js +++ b/packages/@vuepress/core/lib/node/Page.js @@ -286,13 +286,17 @@ module.exports = class Page { */ async enhance (enhancers) { - for (const { name: pluginName, value: enhancer } of enhancers) { - try { - await enhancer(this) - } catch (error) { - console.log(error) - throw new Error(`[${pluginName}] execute extendPageData failed.`) - } - } + return Promise.all( + enhancers.map( + async ({ value: enhancer, name: pluginName }) => { + try { + await enhancer(this) + } catch (error) { + console.log(error) + throw new Error(`[${pluginName}] execute extendPageData failed.`) + } + } + ) + ) } } diff --git a/packages/@vuepress/core/lib/node/__tests__/prepare/Page.spec.js b/packages/@vuepress/core/lib/node/__tests__/prepare/Page.spec.js index 7843b14f2b..e176f6dd5f 100644 --- a/packages/@vuepress/core/lib/node/__tests__/prepare/Page.spec.js +++ b/packages/@vuepress/core/lib/node/__tests__/prepare/Page.spec.js @@ -111,11 +111,11 @@ describe('Page', () => { page = new Page({ path: '/' }, app) enhancers = [ { - pluginName: 'foo', + name: 'foo', value: jest.fn() }, { - pluginName: 'foo', + name: 'bar', value: jest.fn() } ] @@ -130,7 +130,7 @@ describe('Page', () => { test('should loop over sync and async enhancers', async () => { const mixedEnhancers = [...enhancers, { - pluginName: 'blog', + name: 'blog', value: jest.fn().mockResolvedValue({}) }] await page.enhance(mixedEnhancers) @@ -138,13 +138,14 @@ describe('Page', () => { return mixedEnhancers.map(enhancer => expect(enhancer.value).toHaveBeenCalled()) }) - test('should log when enhancing when failing', async () => { + test('should log and throw an error when enhancing fails', async () => { const error = { errorMessage: 'this is an error message' } + const pluginName = 'error-plugin' await expect(page.enhance([{ - pluginName: 'error-plugin', + name: pluginName, value: jest.fn().mockRejectedValue(error) - }])).rejects.toThrow() + }])).rejects.toThrowError(`[${pluginName}] execute extendPageData failed.`) expect(console.log).toHaveBeenCalledWith(error) }) diff --git a/packages/@vuepress/core/lib/node/build/index.js b/packages/@vuepress/core/lib/node/build/index.js index 912eca8c23..271af8843e 100644 --- a/packages/@vuepress/core/lib/node/build/index.js +++ b/packages/@vuepress/core/lib/node/build/index.js @@ -89,10 +89,9 @@ module.exports = class Build extends EventEmitter { // render pages logger.wait('Rendering static HTML...') - const pagePaths = [] - for (const page of this.context.pages) { - pagePaths.push(await this.renderPage(page)) - } + const pagePaths = await Promise.all( + this.context.pages.map(page => this.renderPage(page)) + ) readline.clearLine(process.stdout, 0) readline.cursorTo(process.stdout, 0) @@ -134,9 +133,6 @@ module.exports = class Build extends EventEmitter { async renderPage (page) { const pagePath = decodeURIComponent(page.path) - readline.clearLine(process.stdout, 0) - readline.cursorTo(process.stdout, 0) - process.stdout.write(`Rendering page: ${pagePath}`) // #565 Avoid duplicate description meta at SSR. const meta = (page.frontmatter && page.frontmatter.meta || []).filter(item => item.name !== 'description')