Skip to content

make the whole projectContext still a reference after safeCloneDeep #12826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/safe-clone-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Copyright (C) 2025 Posit Software, PBC
*/

// This is used to create new interfaces that extend the Cloneable interface
// to make the object having a clone method for specific cloning behavior in safeCloneDeep.
export interface Cloneable<T> {
clone(): T;
}
Expand Down
3 changes: 3 additions & 0 deletions src/project/project-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export async function projectContext(
});
const fileInformationCache = new FileInformationCacheMap();
const result: ProjectContext = {
clone: () => result,
resolveBrand: async (fileName?: string) =>
projectResolveBrand(result, fileName),
resolveFullMarkdownForFile: (
Expand Down Expand Up @@ -371,6 +372,7 @@ export async function projectContext(
});
const fileInformationCache = new FileInformationCacheMap();
const result: ProjectContext = {
clone: () => result,
resolveBrand: async (fileName?: string) =>
projectResolveBrand(result, fileName),
resolveFullMarkdownForFile: (
Expand Down Expand Up @@ -446,6 +448,7 @@ export async function projectContext(
});
const fileInformationCache = new FileInformationCacheMap();
const context: ProjectContext = {
clone: () => context,
resolveBrand: async (fileName?: string) =>
projectResolveBrand(context, fileName),
resolveFullMarkdownForFile: (
Expand Down
3 changes: 2 additions & 1 deletion src/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { ProjectEnvironment } from "./project-environment-types.ts";
import { ProjectCache } from "../core/cache/cache-types.ts";
import { TempContext } from "../core/temp-types.ts";
import { Cloneable } from "../core/safe-clone-deep.ts";

export {
type NavigationItem as NavItem,
Expand Down Expand Up @@ -58,7 +59,7 @@ export type FileInformation = {
brand?: LightDarkBrand;
};

export interface ProjectContext {
export interface ProjectContext extends Cloneable<ProjectContext> {
dir: string;
engines: string[];
files: ProjectFiles;
Expand Down
1 change: 1 addition & 0 deletions src/project/types/single-file/single-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function singleFileProjectContext(
const projectCacheBaseDir = temp.createDir();

const result: ProjectContext = {
clone: () => result,
resolveBrand: (fileName?: string) => projectResolveBrand(result, fileName),
dir: normalizePath(dirname(source)),
engines: [],
Expand Down
Loading