@@ -27,7 +27,11 @@ import {
2727import { kTitle } from "../config/constants.ts" ;
2828import { fileExecutionEngine } from "../execute/engine.ts" ;
2929
30- import { projectConfigFile , projectOutputDir } from "./project-shared.ts" ;
30+ import {
31+ ensureFileInformationCache ,
32+ projectConfigFile ,
33+ projectOutputDir ,
34+ } from "./project-shared.ts" ;
3135import { projectScratchPath } from "./project-scratch.ts" ;
3236import { parsePandocTitle } from "../core/pandoc/pandoc-partition.ts" ;
3337import { readYamlFromString } from "../core/yaml.ts" ;
@@ -297,20 +301,13 @@ export async function resolveInputTarget(
297301 }
298302}
299303
300- export async function inputFileForOutputFile (
304+ // populates the outputNameIndex field in the project context
305+ export async function resolveOutputFileNames (
301306 project : ProjectContext ,
302- output : string ,
303- ) : Promise < { file : string ; format : Format } | undefined > {
304- // compute output dir
307+ ) : Promise < void > {
308+ if ( project . outputNameIndex ) return ;
305309 const outputDir = projectOutputDir ( project ) ;
306310
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-
314311 project . outputNameIndex = new Map ( ) ;
315312 for ( const file of project . files . input ) {
316313 const inputRelative = relative ( project . dir , file ) ;
@@ -319,6 +316,8 @@ export async function inputFileForOutputFile(
319316 relative ( project . dir , file ) ,
320317 ) ;
321318 if ( index ) {
319+ const cache = ensureFileInformationCache ( project , file ) ;
320+ cache . outputFiles = cache . outputFiles || { } ;
322321 Object . keys ( index . formats ) . forEach ( ( key ) => {
323322 const format = index . formats [ key ] ;
324323 const outputFile = formatOutputFile ( format ) ;
@@ -329,11 +328,25 @@ export async function inputFileForOutputFile(
329328 outputFile ,
330329 ) ;
331330 project . outputNameIndex ! . set ( formatOutputPath , { file, format } ) ;
331+ cache . outputFiles ! [ formatOutputPath ] = format . identifier ;
332332 }
333333 } ) ;
334334 }
335335 }
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 ) ;
337350}
338351
339352export async function inputTargetIndexForOutputFile (
0 commit comments