Skip to content

Commit 37d2824

Browse files
committed
ensure fileInformationCache is not cloned by safeCloneDeep
This allows to always get the global fileInformationCache from project context to get / set information in it from different contexts.
1 parent 91e1424 commit 37d2824

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/project/project-context.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as ld from "../core/lodash.ts";
1919
import { ProjectType } from "./types/types.ts";
2020
import { Format, Metadata, PandocFlags } from "../config/types.ts";
2121
import {
22+
FileInformation,
2223
kProjectLibDir,
2324
kProjectOutputDir,
2425
kProjectPostRender,
@@ -106,6 +107,16 @@ import { createTempContext } from "../core/temp.ts";
106107

107108
import { onCleanup } from "../core/cleanup.ts";
108109
import { once } from "../core/once.ts";
110+
import { Cloneable } from "../core/safe-clone-deep.ts";
111+
112+
// Create a class that extends Map and implements Cloneable
113+
class FileInformationCacheMap extends Map<string, FileInformation>
114+
implements Cloneable<Map<string, FileInformation>> {
115+
clone(): Map<string, FileInformation> {
116+
// Return the same instance (reference) instead of creating a clone
117+
return this;
118+
}
119+
}
109120

110121
export async function projectContext(
111122
path: string,
@@ -272,7 +283,7 @@ export async function projectContext(
272283
dir: join(dir, ".quarto"),
273284
prefix: "quarto-session-temp",
274285
});
275-
const fileInformationCache = new Map();
286+
const fileInformationCache = new FileInformationCacheMap();
276287
const result: ProjectContext = {
277288
resolveBrand: async (fileName?: string) =>
278289
projectResolveBrand(result, fileName),
@@ -368,7 +379,7 @@ export async function projectContext(
368379
dir: join(dir, ".quarto"),
369380
prefix: "quarto-session-temp",
370381
});
371-
const fileInformationCache = new Map();
382+
const fileInformationCache = new FileInformationCacheMap();
372383
const result: ProjectContext = {
373384
resolveBrand: async (fileName?: string) =>
374385
projectResolveBrand(result, fileName),
@@ -443,7 +454,7 @@ export async function projectContext(
443454
dir: join(originalDir, ".quarto"),
444455
prefix: "quarto-session-temp",
445456
});
446-
const fileInformationCache = new Map();
457+
const fileInformationCache = new FileInformationCacheMap();
447458
const context: ProjectContext = {
448459
resolveBrand: async (fileName?: string) =>
449460
projectResolveBrand(context, fileName),

0 commit comments

Comments
 (0)