Skip to content

Commit 4101fea

Browse files
committed
fix(client): avoid circular scratch project imports
1 parent 049658e commit 4101fea

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

‎packages/client-runtime/src/state/projectEntities.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@ import type {
77
ServerConfig,
88
} from "@t3tools/contracts";
99
import { Atom } from "effect/unstable/reactivity";
10+
import { normalizeProjectPathForComparison } from "@t3tools/shared/path";
1011

1112
import type { EnvironmentProject } from "./models.ts";
1213
import { scopeProject } from "./models.ts";
1314
import { type EnvironmentCatalogState, enabledEnvironmentIds } from "./connections.ts";
1415
import { arrayElementsEqual, parseProjectKey, projectKey, projectRefsEqual } from "./entities.ts";
15-
import { isScratchProject } from "./projects.ts";
16+
17+
/** Whether a project matches its environment's advertised scratch workspace root. */
18+
export function isScratchProject(
19+
project: { readonly workspaceRoot: string },
20+
scratchWorkspaceRoot: string | null | undefined,
21+
): boolean {
22+
if (scratchWorkspaceRoot == null || !project.workspaceRoot) return false;
23+
const scratchRoot = normalizeProjectPathForComparison(scratchWorkspaceRoot);
24+
return (
25+
scratchRoot.length > 0 &&
26+
normalizeProjectPathForComparison(project.workspaceRoot) === scratchRoot
27+
);
28+
}
1629

1730
const EMPTY_PROJECTS: ReadonlyArray<OrchestrationProjectShell> = Object.freeze([]);
1831
const EMPTY_PROJECT_INDEX: ReadonlyMap<ProjectId, OrchestrationProjectShell> = new Map();

‎packages/client-runtime/src/state/projects.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ export function findProjectByPath<T extends { workspaceRoot?: string; cwd?: stri
135135
});
136136
}
137137

138-
/** Whether a project is its environment's Scratch project (`ServerConfig.scratchWorkspaceRoot`). */
139-
export function isScratchProject(
140-
project: { readonly workspaceRoot: string },
141-
scratchWorkspaceRoot: string | null | undefined,
142-
): boolean {
143-
return (
144-
scratchWorkspaceRoot != null && findProjectByPath([project], scratchWorkspaceRoot) !== undefined
145-
);
146-
}
147-
148138
export function inferProjectTitleFromPath(value: string): string {
149139
const normalized = normalizeProjectPathForDispatch(value);
150140
const absolutePath = splitAbsolutePath(normalized);

0 commit comments

Comments
 (0)