Skip to content

Commit 2b2b6d5

Browse files
committed
refactor($core): simplify code of additionalPages option
1 parent 49ebf10 commit 2b2b6d5

File tree

5 files changed

+9
-27
lines changed

5 files changed

+9
-27
lines changed

packages/@vuepress/core/lib/plugin-api/abstract/AsyncOption.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AsyncOption extends Option {
3030
this.add(
3131
name,
3232
isFunction(value)
33-
? await Promise.resolve(value(...args))
33+
? await value(...args)
3434
: value
3535
)
3636
} catch (error) {
@@ -60,7 +60,7 @@ class AsyncOption extends Option {
6060
this.add(
6161
name,
6262
isFunction(value)
63-
? await Promise.resolve(value(...args))
63+
? await value(...args)
6464
: value
6565
)
6666
} catch (error) {
@@ -84,7 +84,7 @@ class AsyncOption extends Option {
8484

8585
async pipeline (input) {
8686
for (const fn of this.values) {
87-
input = await Promise.resolve(fn(input))
87+
input = await fn(input)
8888
}
8989
return input
9090
}

packages/@vuepress/core/lib/plugin-api/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const PLUGIN_OPTION_META_MAP = {
1616
CHAIN_MARKDOWN: { name: 'chainMarkdown', types: [Function] },
1717
CLIENT_DYNAMIC_MODULES: { name: 'clientDynamicModules', types: [Object, Function] },
1818
CLIENT_ROOT_MIXIN: { name: 'clientRootMixin', types: [String] },
19-
ADDITIONAL_PAGES: { name: 'additionalPages', types: [Function, Array] },
19+
ADDITIONAL_PAGES: { name: 'additionalPages', types: [Function, Array], async: true },
2020
GLOBAL_UI_COMPONENTS: { name: 'globalUIComponents', types: [String, Array] },
2121
DEFINE: { name: 'define', types: [Function, Object] },
2222
ALIAS: { name: 'alias', types: [Function, Object] },

packages/@vuepress/core/lib/plugin-api/override/AdditionalPagesOption.js

-19
This file was deleted.

packages/@vuepress/core/lib/plugin-api/override/instantiateOption.js

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const GlobalUIComponentsOption = require('./GlobalUIComponentsOption')
44
const DefineOption = require('./DefineOption')
55
const AliasOption = require('./AliasOption')
66
const AsyncOption = require('../abstract/AsyncOption')
7-
const AdditionalPagesOption = require('./AdditionalPagesOption')
87
const Option = require('../abstract/Option')
98
const { PLUGIN_OPTION_MAP } = require('../constants')
109

@@ -25,9 +24,6 @@ module.exports = function instantiateOption ({ name, async }) {
2524
case PLUGIN_OPTION_MAP.ALIAS.name:
2625
return new AliasOption(name)
2726

28-
case PLUGIN_OPTION_MAP.ADDITIONAL_PAGES.name:
29-
return new AdditionalPagesOption(name)
30-
3127
default: return async ? new AsyncOption(name) : new Option(name)
3228
}
3329
}

packages/@vuepress/core/lib/prepare/AppContext.js

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ module.exports = class AppContext {
105105

106106
await this.resolvePages()
107107
await this.pluginAPI.options.additionalPages.apply(this)
108+
await Promise.all(
109+
this.pluginAPI.options.additionalPages.appliedValues.map(async (options) => {
110+
await this.addPage(options)
111+
})
112+
)
108113

109114
await this.pluginAPI.options.ready.apply()
110115
await Promise.all([

0 commit comments

Comments
 (0)