@@ -57,6 +57,7 @@ export interface Config {
57
57
search : boolean ; // default to false
58
58
md : MarkdownIt ;
59
59
loaders : LoaderResolver ;
60
+ watchPath ?: string ;
60
61
}
61
62
62
63
/**
@@ -76,17 +77,16 @@ async function importConfig(path: string): Promise<any> {
76
77
}
77
78
78
79
export async function readConfig ( configPath ?: string , root ?: string ) : Promise < Config > {
79
- if ( configPath === undefined ) return readDefaultConfig ( root ) ;
80
- return normalizeConfig ( await importConfig ( resolveConfig ( configPath , root ) ) , root ) ;
80
+ if ( configPath === undefined ) configPath = await resolveDefaultConfig ( root ) ;
81
+ if ( configPath === undefined ) return normalizeConfig ( undefined , root ) ;
82
+ return normalizeConfig ( await importConfig ( configPath ) , root , configPath ) ;
81
83
}
82
84
83
- export async function readDefaultConfig ( root ?: string ) : Promise < Config > {
85
+ async function resolveDefaultConfig ( root ?: string ) : Promise < string | undefined > {
84
86
const jsPath = resolveConfig ( "observablehq.config.js" , root ) ;
85
- if ( existsSync ( jsPath ) ) return normalizeConfig ( await importConfig ( jsPath ) , root ) ;
87
+ if ( existsSync ( jsPath ) ) return jsPath ;
86
88
const tsPath = resolveConfig ( "observablehq.config.ts" , root ) ;
87
- if ( ! existsSync ( tsPath ) ) return normalizeConfig ( undefined , root ) ;
88
- await import ( "tsx/esm" ) ; // lazy tsx
89
- return normalizeConfig ( await importConfig ( tsPath ) , root ) ;
89
+ if ( existsSync ( tsPath ) ) return await import ( "tsx/esm" ) , tsPath ; // lazy tsx
90
90
}
91
91
92
92
let cachedPages : { key : string ; pages : Page [ ] } | null = null ;
@@ -127,7 +127,7 @@ export function setCurrentDate(date = new Date()): void {
127
127
// module), we want to return the same Config instance.
128
128
const configCache = new WeakMap < any , Config > ( ) ;
129
129
130
- export function normalizeConfig ( spec : any = { } , defaultRoot = "docs" ) : Config {
130
+ export function normalizeConfig ( spec : any = { } , defaultRoot = "docs" , watchPath ?: string ) : Config {
131
131
const cachedConfig = configCache . get ( spec ) ;
132
132
if ( cachedConfig ) return cachedConfig ;
133
133
let {
@@ -184,7 +184,8 @@ export function normalizeConfig(spec: any = {}, defaultRoot = "docs"): Config {
184
184
deploy,
185
185
search,
186
186
md,
187
- loaders : new LoaderResolver ( { root, interpreters} )
187
+ loaders : new LoaderResolver ( { root, interpreters} ) ,
188
+ watchPath
188
189
} ;
189
190
if ( pages === undefined ) Object . defineProperty ( config , "pages" , { get : ( ) => readPages ( root , md ) } ) ;
190
191
if ( sidebar === undefined ) Object . defineProperty ( config , "sidebar" , { get : ( ) => config . pages . length > 0 } ) ;
0 commit comments