@@ -104,6 +104,9 @@ import { makeTimedFunctionAsync } from "../core/performance/function-times.ts";
104104import { createProjectCache } from "../core/cache/cache.ts" ;
105105import { createTempContext } from "../core/temp.ts" ;
106106
107+ import { onCleanup } from "../core/cleanup.ts" ;
108+ import { once } from "../core/once.ts" ;
109+
107110export async function projectContext (
108111 path : string ,
109112 notebookContext : NotebookContext ,
@@ -314,11 +317,11 @@ export async function projectContext(
314317 isSingleFile : false ,
315318 diskCache : await createProjectCache ( join ( dir , ".quarto" ) ) ,
316319 temp,
317- cleanup : ( ) => {
320+ cleanup : once ( ( ) => {
318321 cleanupFileInformationCache ( result ) ;
319322 result . diskCache . close ( ) ;
320323 temp . cleanup ( ) ;
321- } ,
324+ } ) ,
322325 } ;
323326
324327 // see if the project [kProjectType] wants to filter the project config
@@ -357,7 +360,7 @@ export async function projectContext(
357360 config : configFiles ,
358361 configResources : projectConfigResources ( dir , projectConfig , type ) ,
359362 } ;
360-
363+ onCleanup ( result . cleanup ) ;
361364 return result ;
362365 } else {
363366 debug ( `projectContext: Found Quarto project in ${ dir } ` ) ;
@@ -408,11 +411,11 @@ export async function projectContext(
408411 isSingleFile : false ,
409412 diskCache : await createProjectCache ( join ( dir , ".quarto" ) ) ,
410413 temp,
411- cleanup : ( ) => {
414+ cleanup : once ( ( ) => {
412415 cleanupFileInformationCache ( result ) ;
413416 result . diskCache . close ( ) ;
414417 temp . cleanup ( ) ;
415- } ,
418+ } ) ,
416419 } ;
417420 const { files, engines } = await projectInputFiles (
418421 result ,
@@ -425,6 +428,7 @@ export async function projectContext(
425428 config : configFiles ,
426429 configResources : projectConfigResources ( dir , projectConfig ) ,
427430 } ;
431+ onCleanup ( result . cleanup ) ;
428432 return result ;
429433 }
430434 } else {
@@ -486,11 +490,11 @@ export async function projectContext(
486490 isSingleFile : false ,
487491 diskCache : await createProjectCache ( join ( temp . baseDir , ".quarto" ) ) ,
488492 temp,
489- cleanup : ( ) => {
493+ cleanup : once ( ( ) => {
490494 cleanupFileInformationCache ( context ) ;
491495 context . diskCache . close ( ) ;
492496 temp . cleanup ( ) ;
493- } ,
497+ } ) ,
494498 } ;
495499 if ( Deno . statSync ( path ) . isDirectory ) {
496500 const { files, engines } = await projectInputFiles ( context ) ;
@@ -503,6 +507,7 @@ export async function projectContext(
503507 context . files . input = [ input ] ;
504508 }
505509 debug ( `projectContext: Found Quarto project in ${ originalDir } ` ) ;
510+ onCleanup ( context . cleanup ) ;
506511 return context ;
507512 } else {
508513 return undefined ;
0 commit comments