File tree 3 files changed +35
-31
lines changed
packages/@vuepress/core/lib/plugin-api
3 files changed +35
-31
lines changed Original file line number Diff line number Diff line change @@ -19,21 +19,25 @@ class AsyncOption extends Option {
19
19
*/
20
20
21
21
async asyncApply ( ...args ) {
22
- const items = [ ]
23
- for ( const { name, value } of this . items ) {
22
+ const rawItems = this . items
23
+ this . items = [ ]
24
+ this . appliedItems = this . items
25
+
26
+ for ( const { name, value } of rawItems ) {
24
27
try {
25
- items . push ( {
28
+ this . add (
26
29
name ,
27
- value : isFunction ( value )
30
+ isFunction ( value )
28
31
? await value ( ...args )
29
32
: value
30
- } )
33
+ )
31
34
} catch ( error ) {
32
35
logger . error ( `${ chalk . cyan ( name ) } apply ${ chalk . cyan ( this . key ) } failed.` )
33
36
throw error
34
37
}
35
38
}
36
- this . appliedItems = items
39
+
40
+ this . items = rawItems
37
41
}
38
42
39
43
/**
@@ -43,23 +47,27 @@ class AsyncOption extends Option {
43
47
*/
44
48
45
49
async parallelApply ( ...args ) {
46
- const items = [ ]
47
- await Promise . all ( this . items . map ( async ( { name, value } ) => {
50
+ const rawItems = this . items
51
+ this . items = [ ]
52
+ this . appliedItems = this . items
53
+
54
+ await Promise . all ( rawItems . map ( async ( { name, value } ) => {
48
55
try {
49
- items . push ( {
56
+ this . add (
50
57
name ,
51
- value : isFunction ( value )
58
+ isFunction ( value )
52
59
? await value ( ...args )
53
60
: value
54
- } )
61
+ )
55
62
} catch ( error ) {
56
63
logger . error ( `${ chalk . cyan ( name ) } apply ${ chalk . cyan ( this . key ) } failed.` )
57
64
throw error
58
65
}
59
66
} ) ) . catch ( error => {
60
67
throw error
61
68
} )
62
- return items
69
+
70
+ this . items = rawItems
63
71
}
64
72
65
73
/**
Original file line number Diff line number Diff line change @@ -84,21 +84,25 @@ class Option {
84
84
*/
85
85
86
86
syncApply ( ...args ) {
87
- const items = [ ]
88
- for ( const { name, value } of this . items ) {
87
+ const rawItems = this . items
88
+ this . items = [ ]
89
+ this . appliedItems = this . items
90
+
91
+ for ( const { name, value } of rawItems ) {
89
92
try {
90
- items . push ( {
93
+ this . add (
91
94
name ,
92
- value : isFunction ( value )
95
+ isFunction ( value )
93
96
? value ( ...args )
94
97
: value
95
- } )
98
+ )
96
99
} catch ( error ) {
97
100
logger . error ( `${ chalk . cyan ( name ) } apply ${ chalk . cyan ( this . key ) } failed.` )
98
101
throw error
99
102
}
100
103
}
101
- this . appliedItems = items
104
+
105
+ this . items = rawItems
102
106
}
103
107
104
108
/**
Original file line number Diff line number Diff line change @@ -14,24 +14,16 @@ module.exports = class ClientDynamicModulesOption extends AsyncOption {
14
14
async apply ( ctx ) {
15
15
await super . asyncApply ( )
16
16
17
- for ( const item of this . appliedItems ) {
18
- let { value : modules } = item
19
- const { name : pluginName } = item
20
-
21
- if ( ! Array . isArray ( modules ) ) {
22
- modules = [ modules ]
23
- }
24
-
25
- await Promise . all ( modules . map ( async ( { name, content, dirname = 'dynamic' } ) => {
26
- await ctx . writeTemp (
27
- `${ dirname } /${ name } ` ,
28
- `
17
+ for ( const { value, name : pluginName } of this . appliedItems ) {
18
+ const { name, content, dirname = 'dynamic' } = value
19
+ await ctx . writeTemp (
20
+ `${ dirname } /${ name } ` ,
21
+ `
29
22
/**
30
23
* Generated by "${ pluginName } "
31
24
*/
32
25
${ content } \n\n
33
26
` . trim ( ) )
34
- } ) )
35
27
}
36
28
}
37
29
}
You can’t perform that action at this time.
0 commit comments