@@ -17,7 +17,7 @@ import { readYamlFromMarkdown } from "../../core/yaml.ts";
17
17
import { isInteractiveSession } from "../../core/platform.ts" ;
18
18
import { partitionMarkdown } from "../../core/pandoc/pandoc-partition.ts" ;
19
19
20
- import { dirAndStem , normalizePath , removeIfExists } from "../../core/path.ts" ;
20
+ import { dirAndStem , normalizePath } from "../../core/path.ts" ;
21
21
import { runningInCI } from "../../core/ci-info.ts" ;
22
22
23
23
import {
@@ -109,7 +109,10 @@ import {
109
109
import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts" ;
110
110
import { runExternalPreviewServer } from "../../preview/preview-server.ts" ;
111
111
import { 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" ;
113
116
import { assert } from "testing/asserts" ;
114
117
115
118
export const jupyterEngine : ExecutionEngine = {
@@ -436,7 +439,7 @@ export const jupyterEngine: ExecutionEngine = {
436
439
437
440
// if it's a transient notebook then remove it
438
441
// (unless keep-ipynb was specified)
439
- cleanupNotebook ( options . target , options . format ) ;
442
+ cleanupNotebook ( options . target , options . format , options . project ) ;
440
443
441
444
// Create markdown from the result
442
445
const outputs = result . cellOutputs . map ( ( output ) => output . markdown ) ;
@@ -713,12 +716,17 @@ async function disableDaemonForNotebook(target: ExecutionTarget) {
713
716
return false ;
714
717
}
715
718
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
718
725
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 ;
722
730
}
723
731
}
724
732
}
0 commit comments