Skip to content

Commit 387dc07

Browse files
committed
make the whole projectContext still a reference after safeCloneDeep
projectContext should not be deep cloned. Only reference needs to be passed in the codebase.
1 parent 590d109 commit 387dc07

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

src/core/safe-clone-deep.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Copyright (C) 2025 Posit Software, PBC
77
*/
88

9+
// This is used to create new interfaces that extend the Cloneable interface
10+
// to make the object having a clone method for specific cloning behavior in safeCloneDeep.
911
export interface Cloneable<T> {
1012
clone(): T;
1113
}

src/project/project-context.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export async function projectContext(
275275
});
276276
const fileInformationCache = new FileInformationCacheMap();
277277
const result: ProjectContext = {
278+
clone: () => result,
278279
resolveBrand: async (fileName?: string) =>
279280
projectResolveBrand(result, fileName),
280281
resolveFullMarkdownForFile: (
@@ -371,6 +372,7 @@ export async function projectContext(
371372
});
372373
const fileInformationCache = new FileInformationCacheMap();
373374
const result: ProjectContext = {
375+
clone: () => result,
374376
resolveBrand: async (fileName?: string) =>
375377
projectResolveBrand(result, fileName),
376378
resolveFullMarkdownForFile: (
@@ -446,6 +448,7 @@ export async function projectContext(
446448
});
447449
const fileInformationCache = new FileInformationCacheMap();
448450
const context: ProjectContext = {
451+
clone: () => context,
449452
resolveBrand: async (fileName?: string) =>
450453
projectResolveBrand(context, fileName),
451454
resolveFullMarkdownForFile: (

src/project/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { ProjectEnvironment } from "./project-environment-types.ts";
2323
import { ProjectCache } from "../core/cache/cache-types.ts";
2424
import { TempContext } from "../core/temp-types.ts";
25+
import { Cloneable } from "../core/safe-clone-deep.ts";
2526

2627
export {
2728
type NavigationItem as NavItem,
@@ -58,7 +59,7 @@ export type FileInformation = {
5859
brand?: LightDarkBrand;
5960
};
6061

61-
export interface ProjectContext {
62+
export interface ProjectContext extends Cloneable<ProjectContext> {
6263
dir: string;
6364
engines: string[];
6465
files: ProjectFiles;

src/project/types/single-file/single-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export async function singleFileProjectContext(
4141
const projectCacheBaseDir = temp.createDir();
4242

4343
const result: ProjectContext = {
44+
clone: () => result,
4445
resolveBrand: (fileName?: string) => projectResolveBrand(result, fileName),
4546
dir: normalizePath(dirname(source)),
4647
engines: [],

0 commit comments

Comments
 (0)