@@ -63,7 +63,7 @@ export const resolveMarkdown = (markdown, label, filePath) => {
6363 * @param {GeneratorMetadata } generator - The generator
6464 * @returns {import('../configuration/types').MarkdownPipeline }
6565 */
66- export const resolveMarkdownPipeline = generator => {
66+ const resolveMarkdownPipeline = generator => {
6767 const module = getGeneratorModule ( generator ) ;
6868
6969 return resolveMarkdown (
@@ -112,19 +112,30 @@ const configureList = (own = [], configured = []) => {
112112 const plugins = own . map ( entry => ( { entry, added : false } ) ) ;
113113 const added = [ ] ;
114114
115+ // Each plugin by its specifier: the first listing of it takes the options
116+ const listed = new Map ( ) ;
117+
118+ for ( const plugin of plugins ) {
119+ const [ specifier ] = enforceArray ( plugin . entry ) ;
120+
121+ if ( ! listed . has ( specifier ) ) {
122+ listed . set ( specifier , plugin ) ;
123+ }
124+ }
125+
115126 for ( const entry of configured ) {
116127 const [ specifier , options ] = enforceArray ( entry ) ;
128+ const plugin = listed . get ( specifier ) ;
117129
118- const listed = [ ...plugins , ...added ] . find (
119- plugin => enforceArray ( plugin . entry ) [ 0 ] === specifier
120- ) ;
130+ if ( ! plugin ) {
131+ const addedPlugin = { entry, added : true } ;
121132
122- if ( ! listed ) {
123- added . push ( { entry , added : true } ) ;
133+ added . push ( addedPlugin ) ;
134+ listed . set ( specifier , addedPlugin ) ;
124135 } else if ( options !== undefined ) {
125- const [ , listedOptions ] = enforceArray ( listed . entry ) ;
136+ const [ , listedOptions ] = enforceArray ( plugin . entry ) ;
126137
127- listed . entry = [ specifier , mergeOptions ( listedOptions , options ) ] ;
138+ plugin . entry = [ specifier , mergeOptions ( listedOptions , options ) ] ;
128139 }
129140 }
130141
@@ -183,16 +194,19 @@ export const loadMarkdownPlugins = async (generator, markdown = {}) => {
183194 const configured = { } ;
184195 const own = { } ;
185196
186- for ( const list of PLUGIN_LISTS ) {
187- const plugins = configureList ( pipeline [ list ] , markdown [ list ] ) ;
197+ // The lists import at once, so a slow plugin (Shiki) doesn't hold the rest
198+ await Promise . all (
199+ PLUGIN_LISTS . map ( async list => {
200+ const plugins = configureList ( pipeline [ list ] , markdown [ list ] ) ;
188201
189- const imported = await Promise . all (
190- plugins . map ( ( { entry } ) => importPlugin ( entry ) )
191- ) ;
202+ const imported = await Promise . all (
203+ plugins . map ( ( { entry } ) => importPlugin ( entry ) )
204+ ) ;
192205
193- configured [ list ] = imported ;
194- own [ list ] = imported . filter ( ( _ , index ) => ! plugins [ index ] . added ) ;
195- }
206+ configured [ list ] = imported ;
207+ own [ list ] = imported . filter ( ( _ , index ) => ! plugins [ index ] . added ) ;
208+ } )
209+ ) ;
196210
197211 loadedPipelines . set ( generator . name , { generator, key, configured, own } ) ;
198212} ;
0 commit comments