@@ -47,9 +47,11 @@ import { normalizeNewlines } from "../core/lib/text.ts";
4747import { DirectiveCell } from "../core/lib/break-quarto-md-types.ts" ;
4848import { QuartoJSONSchema , readYamlFromMarkdown } from "../core/yaml.ts" ;
4949import { refSchema } from "../core/lib/yaml-schema/common.ts" ;
50- import { Brand as BrandJson , BrandPathBoolLightDark } from "../resources/types/schema-types.ts" ;
50+ import {
51+ Brand as BrandJson ,
52+ BrandPathBoolLightDark ,
53+ } from "../resources/types/schema-types.ts" ;
5154import { Brand } from "../core/brand/brand.ts" ;
52- import { warnOnce } from "../core/log.ts" ;
5355import { assert } from "testing/asserts" ;
5456
5557export function projectExcludeDirs ( context : ProjectContext ) : string [ ] {
@@ -503,6 +505,10 @@ export const ensureFileInformationCache = (
503505 if ( ! project . fileInformationCache ) {
504506 project . fileInformationCache = new Map ( ) ;
505507 }
508+ assert (
509+ project . fileInformationCache instanceof Map ,
510+ JSON . stringify ( project . fileInformationCache ) ,
511+ ) ;
506512 if ( ! project . fileInformationCache . has ( file ) ) {
507513 project . fileInformationCache . set ( file , { } as FileInformation ) ;
508514 }
@@ -512,16 +518,19 @@ export const ensureFileInformationCache = (
512518export async function projectResolveBrand (
513519 project : ProjectContext ,
514520 fileName ?: string ,
515- ) : Promise < { light ?: Brand , dark ?: Brand } | undefined > {
516- async function loadBrand ( brandPath : string ) : Promise < Brand > {
521+ ) : Promise < { light ?: Brand ; dark ?: Brand } | undefined > {
522+ async function loadBrand ( brandPath : string ) : Promise < Brand > {
517523 const brand = await readAndValidateYamlFromFile (
518524 brandPath ,
519525 refSchema ( "brand" , "Format-independent brand configuration." ) ,
520526 "Brand validation failed for " + brandPath + "." ,
521527 ) as BrandJson ;
522528 return new Brand ( brand , dirname ( brandPath ) , project . dir ) ;
523529 }
524- async function loadRelativeBrand ( brandPath : string , dir : string = dirname ( fileName ! ) ) : Promise < Brand > {
530+ async function loadRelativeBrand (
531+ brandPath : string ,
532+ dir : string = dirname ( fileName ! ) ,
533+ ) : Promise < Brand > {
525534 let resolved : string = "" ;
526535 if ( brandPath . startsWith ( "/" ) ) {
527536 resolved = join ( project . dir , brandPath ) ;
@@ -538,18 +547,27 @@ export async function projectResolveBrand(
538547 let fileNames = [ "_brand.yml" , "_brand.yaml" ] . map ( ( file ) =>
539548 join ( project . dir , file )
540549 ) ;
541- let brand = project ?. config ?. brand as Boolean | string | { light ?: string , dark ?: string } ;
550+ let brand = project ?. config ?. brand as Boolean | string | {
551+ light ?: string ;
552+ dark ?: string ;
553+ } ;
542554 if ( brand === false ) {
543555 project . brandCache . brand = undefined ;
544556 return project . brandCache . brand ;
545557 }
546- if ( typeof brand === "object" && brand &&
547- ( "light" in brand || "dark" in brand ) ) {
558+ if (
559+ typeof brand === "object" && brand &&
560+ ( "light" in brand || "dark" in brand )
561+ ) {
548562 project . brandCache . brand = {
549- light : brand . light ? await loadRelativeBrand ( brand . light , project . dir ) : undefined ,
550- dark : brand . dark ? await loadRelativeBrand ( brand . dark , project . dir ) : undefined ,
563+ light : brand . light
564+ ? await loadRelativeBrand ( brand . light , project . dir )
565+ : undefined ,
566+ dark : brand . dark
567+ ? await loadRelativeBrand ( brand . dark , project . dir )
568+ : undefined ,
551569 } ;
552- return project . brandCache . brand ;
570+ return project . brandCache . brand ;
553571 }
554572 if ( typeof brand === "string" ) {
555573 fileNames = [ join ( project . dir , brand ) ] ;
@@ -559,7 +577,7 @@ export async function projectResolveBrand(
559577 if ( ! existsSync ( brandPath ) ) {
560578 continue ;
561579 }
562- project . brandCache . brand = { light : await loadBrand ( brandPath ) } ;
580+ project . brandCache . brand = { light : await loadBrand ( brandPath ) } ;
563581 }
564582 return project . brandCache . brand ;
565583 } else {
@@ -576,37 +594,39 @@ export async function projectResolveBrand(
576594 return fileInformation . brand ;
577595 }
578596 if ( typeof brand === "string" ) {
579- fileInformation . brand = { light : await loadRelativeBrand ( brand ) } ;
597+ fileInformation . brand = { light : await loadRelativeBrand ( brand ) } ;
580598 return fileInformation . brand ;
581599 } else {
582600 assert ( typeof brand === "object" ) ;
583601 if ( "light" in brand || "dark" in brand ) {
584602 let light , dark ;
585603 if ( typeof brand . light === "string" ) {
586- light = await loadRelativeBrand ( brand . light )
604+ light = await loadRelativeBrand ( brand . light ) ;
587605 } else {
588606 light = new Brand (
589607 brand . light ! ,
590608 dirname ( fileName ) ,
591- project . dir
609+ project . dir ,
592610 ) ;
593611 }
594612 if ( typeof brand . dark === "string" ) {
595- dark = await loadRelativeBrand ( brand . dark )
613+ dark = await loadRelativeBrand ( brand . dark ) ;
596614 } else {
597615 dark = new Brand (
598616 brand . dark ! ,
599617 dirname ( fileName ) ,
600- project . dir
618+ project . dir ,
601619 ) ;
602620 }
603- fileInformation . brand = { light, dark} ;
621+ fileInformation . brand = { light, dark } ;
604622 } else {
605- fileInformation . brand = { light : new Brand (
606- brand as BrandJson ,
607- dirname ( fileName ) ,
608- project . dir ,
609- ) } ;
623+ fileInformation . brand = {
624+ light : new Brand (
625+ brand as BrandJson ,
626+ dirname ( fileName ) ,
627+ project . dir ,
628+ ) ,
629+ } ;
610630 }
611631 return fileInformation . brand ;
612632 }
0 commit comments