@@ -27,7 +27,11 @@ import {
27
27
import { kTitle } from "../config/constants.ts" ;
28
28
import { fileExecutionEngine } from "../execute/engine.ts" ;
29
29
30
- import { projectConfigFile , projectOutputDir } from "./project-shared.ts" ;
30
+ import {
31
+ ensureFileInformationCache ,
32
+ projectConfigFile ,
33
+ projectOutputDir ,
34
+ } from "./project-shared.ts" ;
31
35
import { projectScratchPath } from "./project-scratch.ts" ;
32
36
import { parsePandocTitle } from "../core/pandoc/pandoc-partition.ts" ;
33
37
import { readYamlFromString } from "../core/yaml.ts" ;
@@ -297,20 +301,13 @@ export async function resolveInputTarget(
297
301
}
298
302
}
299
303
300
- export async function inputFileForOutputFile (
304
+ // populates the outputNameIndex field in the project context
305
+ export async function resolveOutputFileNames (
301
306
project : ProjectContext ,
302
- output : string ,
303
- ) : Promise < { file : string ; format : Format } | undefined > {
304
- // compute output dir
307
+ ) : Promise < void > {
308
+ if ( project . outputNameIndex ) return ;
305
309
const outputDir = projectOutputDir ( project ) ;
306
310
307
- // full path to output (it's relative to output dir)
308
- output = isAbsolute ( output ) ? output : join ( outputDir , output ) ;
309
-
310
- if ( project . outputNameIndex !== undefined ) {
311
- return project . outputNameIndex . get ( output ) ;
312
- }
313
-
314
311
project . outputNameIndex = new Map ( ) ;
315
312
for ( const file of project . files . input ) {
316
313
const inputRelative = relative ( project . dir , file ) ;
@@ -319,6 +316,8 @@ export async function inputFileForOutputFile(
319
316
relative ( project . dir , file ) ,
320
317
) ;
321
318
if ( index ) {
319
+ const cache = ensureFileInformationCache ( project , file ) ;
320
+ cache . outputFiles = cache . outputFiles || { } ;
322
321
Object . keys ( index . formats ) . forEach ( ( key ) => {
323
322
const format = index . formats [ key ] ;
324
323
const outputFile = formatOutputFile ( format ) ;
@@ -329,11 +328,25 @@ export async function inputFileForOutputFile(
329
328
outputFile ,
330
329
) ;
331
330
project . outputNameIndex ! . set ( formatOutputPath , { file, format } ) ;
331
+ cache . outputFiles ! [ formatOutputPath ] = format . identifier ;
332
332
}
333
333
} ) ;
334
334
}
335
335
}
336
- return project . outputNameIndex . get ( output ) ;
336
+ }
337
+
338
+ export async function inputFileForOutputFile (
339
+ project : ProjectContext ,
340
+ output : string ,
341
+ ) : Promise < { file : string ; format : Format } | undefined > {
342
+ // compute output dir
343
+ const outputDir = projectOutputDir ( project ) ;
344
+
345
+ // full path to output (it's relative to output dir)
346
+ output = isAbsolute ( output ) ? output : join ( outputDir , output ) ;
347
+
348
+ await resolveOutputFileNames ( project ) ;
349
+ return project . outputNameIndex ?. get ( output ) ;
337
350
}
338
351
339
352
export async function inputTargetIndexForOutputFile (
0 commit comments