@@ -91,7 +91,7 @@ export async function resolveFormatsFromMetadata(
9191 input : string ,
9292 formats : string [ ] ,
9393 flags ?: RenderFlags ,
94- ) : Promise < Record < string , Format > > {
94+ ) : Promise < Record < string , { format : Format ; active : boolean } > > {
9595 const includeDir = dirname ( input ) ;
9696
9797 // Read any included metadata files and merge in and metadata from the command
@@ -139,9 +139,12 @@ export async function resolveFormatsFromMetadata(
139139 renderFormats . push ( ...toFormats ) ;
140140 }
141141
142- const resolved : Record < string , Format > = { } ;
142+ // get a list of _all_ formats
143+ formats = ld . uniq ( formats . concat ( renderFormats ) ) ;
144+
145+ const resolved : Record < string , { format : Format ; active : boolean } > = { } ;
143146
144- renderFormats . forEach ( ( to ) => {
147+ formats . forEach ( ( to ) => {
145148 // determine the target format
146149 const format = formatFromMetadata (
147150 baseFormat ,
@@ -185,7 +188,10 @@ export async function resolveFormatsFromMetadata(
185188 config . execute [ kExecuteDebug ] = flags . executeDebug ;
186189 }
187190
188- resolved [ to ] = config ;
191+ resolved [ to ] = {
192+ format : config ,
193+ active : renderFormats . includes ( to ) ,
194+ } ;
189195 } ) ;
190196
191197 return resolved ;
@@ -225,17 +231,18 @@ export async function renderContexts(
225231
226232 // return contexts
227233 const contexts : Record < string , RenderContext > = { } ;
228- for ( const format of Object . keys ( formats ) ) {
234+ for ( const formatKey of Object . keys ( formats ) ) {
229235 // set format
230236 const context : RenderContext = {
231237 target,
232238 options,
233239 engine,
234- format : formats [ format ] ,
240+ format : formats [ formatKey ] . format ,
241+ active : formats [ formatKey ] . active ,
235242 project,
236243 libDir : libDir ! ,
237244 } ;
238- contexts [ format ] = context ;
245+ contexts [ formatKey ] = context ;
239246
240247 // at this point we have enough to fix up the target and engine
241248 // in case that's needed.
@@ -281,7 +288,7 @@ export async function renderContexts(
281288
282289 // if this isn't for execute then cleanup context
283290 if ( ! forExecute && engine . executeTargetSkipped ) {
284- engine . executeTargetSkipped ( target , formats [ format ] ) ;
291+ engine . executeTargetSkipped ( target , formats [ formatKey ] . format ) ;
285292 }
286293 }
287294 return contexts ;
@@ -380,7 +387,7 @@ async function resolveFormats(
380387 engine : ExecutionEngine ,
381388 options : RenderOptions ,
382389 project ?: ProjectContext ,
383- ) : Promise < Record < string , Format > > {
390+ ) : Promise < Record < string , { format : Format ; active : boolean } > > {
384391 // input level metadata
385392 const inputMetadata = target . metadata ;
386393
@@ -456,19 +463,33 @@ async function resolveFormats(
456463 options . flags ,
457464 ) ;
458465
459- // merge the formats
460- const targetFormats = ld . uniq (
466+ const activeKeys = (
467+ formats : Record < string , { format : Format ; active : boolean } > ,
468+ ) => {
469+ return Object . keys ( formats ) . filter ( ( key ) => {
470+ return formats [ key ] . active ;
471+ } ) ;
472+ } ;
473+
474+ // A list of all the active format keys
475+ const activeFormatKeys = ld . uniq (
476+ activeKeys ( projFormats ) . concat ( activeKeys ( directoryFormats ) ) . concat (
477+ activeKeys ( inputFormats ) ,
478+ ) ,
479+ ) ;
480+ // A list of all the format keys included
481+ const allFormatKeys = ld . uniq (
461482 Object . keys ( projFormats ) . concat ( Object . keys ( directoryFormats ) ) . concat (
462483 Object . keys ( inputFormats ) ,
463484 ) ,
464485 ) ;
465486
466487 const mergedFormats : Record < string , Format > = { } ;
467- for ( const format of targetFormats ) {
488+ for ( const format of allFormatKeys ) {
468489 // alias formats
469- const projFormat = projFormats [ format ] ;
470- const directoryFormat = directoryFormats [ format ] ;
471- const inputFormat = inputFormats [ format ] ;
490+ const projFormat = projFormats [ format ] . format ;
491+ const directoryFormat = directoryFormats [ format ] . format ;
492+ const inputFormat = inputFormats [ format ] . format ;
472493
473494 // resolve theme (project-level bootstrap theme always wins for web drived output)
474495 if (
@@ -513,14 +534,18 @@ async function resolveFormats(
513534 // do the merge of the writer format into this format
514535 mergedFormats [ format ] = mergeFormatMetadata (
515536 defaultWriterFormat ( formatDesc . formatWithVariants ) ,
516- extensionMetadata [ formatDesc . baseFormat ] ,
537+ extensionMetadata [ formatDesc . baseFormat ]
538+ ? extensionMetadata [ formatDesc . baseFormat ] . format
539+ : { } ,
517540 userFormat ,
518541 ) ;
519542 //deno-lint-ignore no-explicit-any
520543 mergedFormats [ format ] . mergeAdditionalFormats = ( ...configs : any [ ] ) => {
521544 return mergeFormatMetadata (
522545 defaultWriterFormat ( formatDesc . formatWithVariants ) ,
523- extensionMetadata [ formatDesc . baseFormat ] ,
546+ extensionMetadata [ formatDesc . baseFormat ]
547+ ? extensionMetadata [ formatDesc . baseFormat ] . format
548+ : { } ,
524549 ...configs ,
525550 userFormat ,
526551 ) ;
@@ -581,7 +606,15 @@ async function resolveFormats(
581606 mergedFormats [ formatName ] = format ;
582607 }
583608
584- return mergedFormats ;
609+ const finalFormats : Record < string , { format : Format ; active : boolean } > = { } ;
610+ for ( const key of Object . keys ( mergedFormats ) ) {
611+ const active = activeFormatKeys . includes ( key ) ;
612+ finalFormats [ key ] = {
613+ format : mergedFormats [ key ] ,
614+ active,
615+ } ;
616+ }
617+ return finalFormats ;
585618}
586619
587620const readExtensionFormat = async (
0 commit comments