@@ -17,7 +17,7 @@ import { readYamlFromMarkdown } from "../../core/yaml.ts";
1717import { isInteractiveSession } from "../../core/platform.ts" ;
1818import { partitionMarkdown } from "../../core/pandoc/pandoc-partition.ts" ;
1919
20- import { dirAndStem , normalizePath , removeIfExists } from "../../core/path.ts" ;
20+ import { dirAndStem , normalizePath } from "../../core/path.ts" ;
2121import { runningInCI } from "../../core/ci-info.ts" ;
2222
2323import {
@@ -109,7 +109,10 @@ import {
109109import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts" ;
110110import { runExternalPreviewServer } from "../../preview/preview-server.ts" ;
111111import { onCleanup } from "../../core/cleanup.ts" ;
112- import { projectOutputDir } from "../../project/project-shared.ts" ;
112+ import {
113+ ensureFileInformationCache ,
114+ projectOutputDir ,
115+ } from "../../project/project-shared.ts" ;
113116import { assert } from "testing/asserts" ;
114117
115118export const jupyterEngine : ExecutionEngine = {
@@ -436,7 +439,7 @@ export const jupyterEngine: ExecutionEngine = {
436439
437440 // if it's a transient notebook then remove it
438441 // (unless keep-ipynb was specified)
439- cleanupNotebook ( options . target , options . format ) ;
442+ cleanupNotebook ( options . target , options . format , options . project ) ;
440443
441444 // Create markdown from the result
442445 const outputs = result . cellOutputs . map ( ( output ) => output . markdown ) ;
@@ -713,12 +716,17 @@ async function disableDaemonForNotebook(target: ExecutionTarget) {
713716 return false ;
714717}
715718
716- function cleanupNotebook ( target : ExecutionTarget , format : Format ) {
717- // remove transient notebook if appropriate
719+ function cleanupNotebook (
720+ target : ExecutionTarget ,
721+ format : Format ,
722+ project : ProjectContext ,
723+ ) {
724+ // Make notebook non-transient when keep-ipynb is set
718725 const data = target . data as JupyterTargetData ;
719- if ( data . transient ) {
720- if ( ! format . execute [ kKeepIpynb ] ) {
721- removeIfExists ( target . input ) ;
726+ const cached = ensureFileInformationCache ( project , target . source ) ;
727+ if ( data . transient && format . execute [ kKeepIpynb ] ) {
728+ if ( cached . target && cached . target . data ) {
729+ ( cached . target . data as JupyterTargetData ) . transient = false ;
722730 }
723731 }
724732}
0 commit comments