Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4419ba0e0c | ||
|
|
8c4d76f7eb |
No files matched your search
@@ -6,10 +6,12 @@ import type {
|
|||||||
} from "@t3tools/contracts";
|
} from "@t3tools/contracts";
|
||||||
import * as Context from "effect/Context";
|
import * as Context from "effect/Context";
|
||||||
import * as DateTime from "effect/DateTime";
|
import * as DateTime from "effect/DateTime";
|
||||||
|
import * as Duration from "effect/Duration";
|
||||||
import * as Effect from "effect/Effect";
|
import * as Effect from "effect/Effect";
|
||||||
import * as Layer from "effect/Layer";
|
import * as Layer from "effect/Layer";
|
||||||
import * as Option from "effect/Option";
|
import * as Option from "effect/Option";
|
||||||
import * as Ref from "effect/Ref";
|
import * as Ref from "effect/Ref";
|
||||||
|
import * as Schedule from "effect/Schedule";
|
||||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -20,6 +22,7 @@ import {
|
|||||||
} from "./ProcessDiagnostics.ts";
|
} from "./ProcessDiagnostics.ts";
|
||||||
|
|
||||||
const SAMPLE_INTERVAL_MS = 5_000;
|
const SAMPLE_INTERVAL_MS = 5_000;
|
||||||
|
const SAMPLE_INTERVAL = Duration.millis(SAMPLE_INTERVAL_MS);
|
||||||
const RETENTION_MS = 60 * 60_000;
|
const RETENTION_MS = 60 * 60_000;
|
||||||
const MAX_RETAINED_SAMPLES = 20_000;
|
const MAX_RETAINED_SAMPLES = 20_000;
|
||||||
|
|
||||||
@@ -274,9 +277,7 @@ export const make = Effect.fn("makeProcessResourceMonitor")(function* () {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
yield* Effect.forever(sampleOnce.pipe(Effect.andThen(Effect.sleep(SAMPLE_INTERVAL_MS)))).pipe(
|
yield* sampleOnce.pipe(Effect.repeat(Schedule.spaced(SAMPLE_INTERVAL)), Effect.forkScoped);
|
||||||
Effect.forkScoped,
|
|
||||||
);
|
|
||||||
|
|
||||||
const readHistory: ProcessResourceMonitorShape["readHistory"] = (input) =>
|
const readHistory: ProcessResourceMonitorShape["readHistory"] = (input) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
|
|||||||
@@ -67,4 +67,24 @@ describe("VcsProjectConfig", () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.layer(TestLayer)("falls back to auto when config is invalid", (it) => {
|
||||||
|
it.effect("returns auto", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const fileSystem = yield* FileSystem.FileSystem;
|
||||||
|
const path = yield* Path.Path;
|
||||||
|
const root = yield* fileSystem.makeTempDirectoryScoped({
|
||||||
|
prefix: "t3-vcs-config-test-",
|
||||||
|
});
|
||||||
|
const configDir = path.join(root, ".t3code");
|
||||||
|
yield* fileSystem.makeDirectory(configDir, { recursive: true });
|
||||||
|
yield* fileSystem.writeFileString(path.join(configDir, "vcs.json"), "{");
|
||||||
|
|
||||||
|
const config = yield* VcsProjectConfig.VcsProjectConfig;
|
||||||
|
const kind = yield* config.resolveKind({ cwd: root });
|
||||||
|
|
||||||
|
assert.equal(kind, "auto");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -2,6 +2,7 @@ import * as Context from "effect/Context";
|
|||||||
import * as Effect from "effect/Effect";
|
import * as Effect from "effect/Effect";
|
||||||
import * as FileSystem from "effect/FileSystem";
|
import * as FileSystem from "effect/FileSystem";
|
||||||
import * as Layer from "effect/Layer";
|
import * as Layer from "effect/Layer";
|
||||||
|
import * as Option from "effect/Option";
|
||||||
import * as Path from "effect/Path";
|
import * as Path from "effect/Path";
|
||||||
import * as Schema from "effect/Schema";
|
import * as Schema from "effect/Schema";
|
||||||
|
|
||||||
@@ -15,16 +16,9 @@ const ProjectVcsConfig = Schema.Struct({
|
|||||||
),
|
),
|
||||||
vcsKind: Schema.optional(VcsDriverKind),
|
vcsKind: Schema.optional(VcsDriverKind),
|
||||||
});
|
});
|
||||||
const isProjectVcsConfig = Schema.is(ProjectVcsConfig);
|
type ProjectVcsConfigFile = Schema.Schema.Type<typeof ProjectVcsConfig>;
|
||||||
|
|
||||||
interface ProjectVcsConfigFile {
|
const decodeProjectVcsConfig = Schema.decodeUnknownEffect(Schema.fromJsonString(ProjectVcsConfig));
|
||||||
readonly vcs?:
|
|
||||||
| {
|
|
||||||
readonly kind?: VcsDriverKindType | undefined;
|
|
||||||
}
|
|
||||||
| undefined;
|
|
||||||
readonly vcsKind?: VcsDriverKindType | undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface VcsProjectConfigResolveInput {
|
export interface VcsProjectConfigResolveInput {
|
||||||
readonly cwd: string;
|
readonly cwd: string;
|
||||||
@@ -45,15 +39,6 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
|
|||||||
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
return config.vcs?.kind ?? config.vcsKind ?? "auto";
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseConfig(raw: string): ProjectVcsConfigFile | null {
|
|
||||||
try {
|
|
||||||
const parsed = JSON.parse(raw) as unknown;
|
|
||||||
return isProjectVcsConfig(parsed) ? parsed : null;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
||||||
const fileSystem = yield* FileSystem.FileSystem;
|
const fileSystem = yield* FileSystem.FileSystem;
|
||||||
const path = yield* Path.Path;
|
const path = yield* Path.Path;
|
||||||
@@ -63,12 +48,12 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
|||||||
while (true) {
|
while (true) {
|
||||||
const candidate = path.join(current, ".t3code", "vcs.json");
|
const candidate = path.join(current, ".t3code", "vcs.json");
|
||||||
if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
|
if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
|
||||||
return candidate;
|
return Option.some(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = path.dirname(current);
|
const parent = path.dirname(current);
|
||||||
if (parent === current) {
|
if (parent === current) {
|
||||||
return null;
|
return Option.none<string>();
|
||||||
}
|
}
|
||||||
current = parent;
|
current = parent;
|
||||||
}
|
}
|
||||||
@@ -78,26 +63,27 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
|||||||
configPath: string,
|
configPath: string,
|
||||||
) {
|
) {
|
||||||
const raw = yield* fileSystem.readFileString(configPath).pipe(
|
const raw = yield* fileSystem.readFileString(configPath).pipe(
|
||||||
|
Effect.map(Option.some),
|
||||||
Effect.catch((error) =>
|
Effect.catch((error) =>
|
||||||
Effect.logWarning("failed to read VCS project config", {
|
Effect.logWarning("failed to read VCS project config", {
|
||||||
configPath,
|
configPath,
|
||||||
error,
|
error,
|
||||||
}).pipe(Effect.as(null)),
|
}).pipe(Effect.as(Option.none<string>())),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (raw === null) {
|
if (Option.isNone(raw)) {
|
||||||
return "auto" as const;
|
return "auto" as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = parseConfig(raw);
|
const parsed = yield* decodeProjectVcsConfig(raw.value).pipe(Effect.option);
|
||||||
if (parsed === null) {
|
if (Option.isNone(parsed)) {
|
||||||
yield* Effect.logWarning("invalid VCS project config", {
|
yield* Effect.logWarning("invalid VCS project config", {
|
||||||
configPath,
|
configPath,
|
||||||
});
|
});
|
||||||
return "auto" as const;
|
return "auto" as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
return configuredKind(parsed);
|
return configuredKind(parsed.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
|
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
|
||||||
@@ -108,11 +94,10 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const configPath = yield* findConfigPath(input.cwd);
|
const configPath = yield* findConfigPath(input.cwd);
|
||||||
if (configPath === null) {
|
return yield* Option.match(configPath, {
|
||||||
return "auto";
|
onNone: () => Effect.succeed("auto" as const),
|
||||||
}
|
onSome: readConfiguredKind,
|
||||||
|
});
|
||||||
return yield* readConfiguredKind(configPath);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return VcsProjectConfig.of({
|
return VcsProjectConfig.of({
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
import {
|
import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";
|
||||||
useEffect,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
type CSSProperties,
|
|
||||||
type ReactNode,
|
|
||||||
type RefObject,
|
|
||||||
} from "react";
|
|
||||||
import { XIcon } from "lucide-react";
|
import { XIcon } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
@@ -41,19 +34,6 @@ export interface ComposerBannerStackItem {
|
|||||||
readonly onDismiss?: () => void;
|
readonly onDismiss?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function useDismissTimeoutCleanup(timeoutRef: RefObject<ReturnType<typeof setTimeout> | null>) {
|
|
||||||
useEffect(() => {
|
|
||||||
return () => clearDismissTimeout(timeoutRef);
|
|
||||||
}, [timeoutRef]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearDismissTimeout(timeoutRef: RefObject<ReturnType<typeof setTimeout> | null>) {
|
|
||||||
const timeout = timeoutRef.current;
|
|
||||||
if (timeout) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ComposerBannerStackProps {
|
interface ComposerBannerStackProps {
|
||||||
readonly className?: string;
|
readonly className?: string;
|
||||||
readonly items: ReadonlyArray<ComposerBannerStackItem>;
|
readonly items: ReadonlyArray<ComposerBannerStackItem>;
|
||||||
@@ -62,9 +42,20 @@ interface ComposerBannerStackProps {
|
|||||||
export function ComposerBannerStack({ className, items }: ComposerBannerStackProps) {
|
export function ComposerBannerStack({ className, items }: ComposerBannerStackProps) {
|
||||||
const [exitingItemId, setExitingItemId] = useState<string | null>(null);
|
const [exitingItemId, setExitingItemId] = useState<string | null>(null);
|
||||||
const dismissTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
const dismissTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
const activeExitingItemId =
|
|
||||||
exitingItemId && items.some((item) => item.id === exitingItemId) ? exitingItemId : null;
|
useEffect(() => {
|
||||||
useDismissTimeoutCleanup(dismissTimeoutRef);
|
if (exitingItemId && !items.some((item) => item.id === exitingItemId)) {
|
||||||
|
setExitingItemId(null);
|
||||||
|
}
|
||||||
|
}, [exitingItemId, items]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (dismissTimeoutRef.current) {
|
||||||
|
clearTimeout(dismissTimeoutRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
@@ -76,10 +67,10 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
|||||||
}
|
}
|
||||||
const stackedItems = items.slice(1);
|
const stackedItems = items.slice(1);
|
||||||
const hasStack = stackedItems.length > 0;
|
const hasStack = stackedItems.length > 0;
|
||||||
const showCollapsedStackCap = hasStack && activeExitingItemId !== frontItem.id;
|
const showCollapsedStackCap = hasStack && exitingItemId !== frontItem.id;
|
||||||
|
|
||||||
const requestDismiss = (item: ComposerBannerStackItem) => {
|
const requestDismiss = (item: ComposerBannerStackItem) => {
|
||||||
if (!item.onDismiss || activeExitingItemId) {
|
if (!item.onDismiss || exitingItemId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setExitingItemId(item.id);
|
setExitingItemId(item.id);
|
||||||
@@ -115,16 +106,16 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
|||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative z-10",
|
"relative z-10",
|
||||||
activeExitingItemId === frontItem.id ? "pointer-events-none" : null,
|
exitingItemId === frontItem.id ? "pointer-events-none" : null,
|
||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
...exitTransitionStyle,
|
...exitTransitionStyle,
|
||||||
...(activeExitingItemId === frontItem.id ? frontExitStyle : restingStyle),
|
...(exitingItemId === frontItem.id ? frontExitStyle : restingStyle),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ComposerBannerStackAlert
|
<ComposerBannerStackAlert
|
||||||
item={frontItem}
|
item={frontItem}
|
||||||
exiting={activeExitingItemId === frontItem.id}
|
exiting={exitingItemId === frontItem.id}
|
||||||
onDismissRequest={() => requestDismiss(frontItem)}
|
onDismissRequest={() => requestDismiss(frontItem)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -141,15 +132,15 @@ export function ComposerBannerStack({ className, items }: ComposerBannerStackPro
|
|||||||
{stackedItems.map((item) => (
|
{stackedItems.map((item) => (
|
||||||
<div
|
<div
|
||||||
key={item.id}
|
key={item.id}
|
||||||
className={cn(activeExitingItemId === item.id ? "pointer-events-none" : null)}
|
className={cn(exitingItemId === item.id ? "pointer-events-none" : null)}
|
||||||
style={{
|
style={{
|
||||||
...exitTransitionStyle,
|
...exitTransitionStyle,
|
||||||
...(activeExitingItemId === item.id ? stackedExitStyle : restingStyle),
|
...(exitingItemId === item.id ? stackedExitStyle : restingStyle),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ComposerBannerStackAlert
|
<ComposerBannerStackAlert
|
||||||
item={item}
|
item={item}
|
||||||
exiting={activeExitingItemId === item.id}
|
exiting={exitingItemId === item.id}
|
||||||
onDismissRequest={() => requestDismiss(item)}
|
onDismissRequest={() => requestDismiss(item)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user