Compare commits

..
7 changed files with 465 additions and 361 deletions

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@
"@effect/vitest": "catalog:",
"@types/node": "catalog:",
"cross-env": "^10.1.0",
"electron-builder": "26.8.1",
"electron-builder": "26.15.6",
"tailwindcss": "^4.0.0",
"vite-plus": "catalog:"
},
Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 KiB

After

Width:  |  Height:  |  Size: 302 KiB

@@ -2,7 +2,7 @@ import { useNavigate } from "@tanstack/react-router";
import { useAtomValue } from "@effect/atom-react";
import type { ServerProvider } from "@t3tools/contracts";
import { CircleCheckIcon, DownloadIcon, LoaderIcon, TriangleAlertIcon, XIcon } from "lucide-react";
import { useCallback, useEffect, useState, type CSSProperties } from "react";
import { useCallback, useEffect, useRef, useState, type CSSProperties } from "react";
import { primaryServerProvidersAtom } from "../../state/server";
import {
@@ -28,62 +28,19 @@ const PROVIDER_UPDATE_PILL_PROGRESS_STYLES = {
error: "bg-destructive/14",
} as const;
function latestProviderCheckedAt(
providers: ReadonlyArray<Pick<ServerProvider, "checkedAt">>,
): string | undefined {
return providers.reduce<string | undefined>(
(latest, provider) =>
latest === undefined || provider.checkedAt > latest ? provider.checkedAt : latest,
undefined,
);
function useMountedIsoTimestamp(): string {
const [mountedIsoTimestamp] = useState(() => new Date().toISOString());
return mountedIsoTimestamp;
}
export function SidebarProviderUpdatePill() {
const navigate = useNavigate();
const providers = useAtomValue(primaryServerProvidersAtom);
const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set());
const [renderedView, setRenderedView] = useState<ProviderUpdateSidebarPillView | null>(null);
const [pendingView, setPendingView] = useState<ProviderUpdateSidebarPillView | null>(null);
const [exitingKey, setExitingKey] = useState<string | null>(null);
const [dismissAfterExitKey, setDismissAfterExitKey] = useState<string | null>(null);
const [visibleAfterIso, setVisibleAfterIso] = useState<string | undefined>();
const effectiveVisibleAfterIso = visibleAfterIso ?? latestProviderCheckedAt(providers);
const view = getProviderUpdateSidebarPillView(providers, {
...(effectiveVisibleAfterIso !== undefined
? { visibleAfterIso: effectiveVisibleAfterIso }
: {}),
dismissedKeys,
});
useEffect(() => {
if (visibleAfterIso === undefined && effectiveVisibleAfterIso !== undefined) {
setVisibleAfterIso(effectiveVisibleAfterIso);
}
}, [effectiveVisibleAfterIso, visibleAfterIso]);
const openProviderSettings = useCallback(() => {
void navigate({ to: "/settings/providers" });
}, [navigate]);
const displayedView = renderedView ?? view;
const dismissAfterVisibleMs = displayedView?.dismissAfterVisibleMs;
const viewKey = displayedView?.key ?? null;
const showDismissProgress =
dismissAfterVisibleMs !== undefined &&
displayedView?.tone !== "loading" &&
exitingKey !== viewKey;
const startExit = useCallback(
(key: string, nextView: ProviderUpdateSidebarPillView | null, dismissKey?: string) => {
if (exitingKey === key) {
return;
}
setPendingView(nextView);
setExitingKey(key);
setDismissAfterExitKey(dismissKey ?? null);
},
[exitingKey],
);
function useProviderUpdateRenderedViewSynchronization(input: {
readonly exitingKey: string | null;
readonly renderedView: ProviderUpdateSidebarPillView | null;
readonly setRenderedView: (view: ProviderUpdateSidebarPillView | null) => void;
readonly startExit: (key: string, nextView: ProviderUpdateSidebarPillView | null) => void;
readonly view: ProviderUpdateSidebarPillView | null;
}) {
const { exitingKey, renderedView, setRenderedView, startExit, view } = input;
useEffect(() => {
if (exitingKey !== null) {
return;
@@ -102,8 +59,20 @@ export function SidebarProviderUpdatePill() {
startExit(renderedView.key, view);
return;
}
}, [exitingKey, renderedView, startExit, view]);
}, [exitingKey, renderedView, setRenderedView, startExit, view]);
}
function useProviderUpdateAutoDismiss(input: {
readonly dismissAfterVisibleMs: number | undefined;
readonly exitingKey: string | null;
readonly startExit: (
key: string,
nextView: ProviderUpdateSidebarPillView | null,
dismissKey?: string,
) => void;
readonly viewKey: string | null;
}) {
const { dismissAfterVisibleMs, exitingKey, startExit, viewKey } = input;
useEffect(() => {
if (!dismissAfterVisibleMs || !viewKey) {
return;
@@ -117,6 +86,60 @@ export function SidebarProviderUpdatePill() {
return () => window.clearTimeout(timeoutId);
}, [dismissAfterVisibleMs, exitingKey, startExit, viewKey]);
}
export function SidebarProviderUpdatePill() {
const navigate = useNavigate();
const providers = useAtomValue(primaryServerProvidersAtom);
const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set());
const visibleAfterIso = useMountedIsoTimestamp();
const view = getProviderUpdateSidebarPillView(providers, {
visibleAfterIso,
dismissedKeys,
});
const [renderedView, setRenderedView] = useState<ProviderUpdateSidebarPillView | null>(
() => view,
);
const pendingViewRef = useRef<ProviderUpdateSidebarPillView | null>(null);
const [exitingKey, setExitingKey] = useState<string | null>(null);
const dismissAfterExitKeyRef = useRef<string | null>(null);
const openProviderSettings = useCallback(() => {
void navigate({ to: "/settings/providers" });
}, [navigate]);
const displayedView = renderedView ?? view;
const dismissAfterVisibleMs = displayedView?.dismissAfterVisibleMs;
const viewKey = displayedView?.key ?? null;
const showDismissProgress =
dismissAfterVisibleMs !== undefined &&
displayedView?.tone !== "loading" &&
exitingKey !== viewKey;
const startExit = useCallback(
(key: string, nextView: ProviderUpdateSidebarPillView | null, dismissKey?: string) => {
if (exitingKey === key) {
return;
}
pendingViewRef.current = nextView;
dismissAfterExitKeyRef.current = dismissKey ?? null;
setExitingKey(key);
},
[exitingKey],
);
useProviderUpdateRenderedViewSynchronization({
exitingKey,
renderedView,
setRenderedView,
startExit,
view,
});
useProviderUpdateAutoDismiss({
dismissAfterVisibleMs,
exitingKey,
startExit,
viewKey,
});
if (!displayedView) {
return null;
@@ -138,13 +161,13 @@ export function SidebarProviderUpdatePill() {
if (!displayedView || exitingKey !== displayedView.key) {
return;
}
if (dismissAfterExitKey === displayedView.key) {
if (dismissAfterExitKeyRef.current === displayedView.key) {
setDismissedKeys((previous) => new Set(previous).add(displayedView.key));
}
setRenderedView(pendingView);
setPendingView(null);
setRenderedView(pendingViewRef.current);
pendingViewRef.current = null;
setExitingKey(null);
setDismissAfterExitKey(null);
dismissAfterExitKeyRef.current = null;
}}
>
{showDismissProgress ? (
+249 -247
View File
File diff suppressed because it is too large. Load diff
+14 -6
View File
@@ -23,13 +23,13 @@ allowBuilds:
workerd: false
catalog:
"@clerk/backend": 3.8.4
"@clerk/clerk-js": 6.22.0
"@clerk/electron": 0.0.5
"@clerk/backend": 3.11.1
"@clerk/clerk-js": 6.25.0
"@clerk/electron": 0.0.10
"@clerk/electron-passkeys": 0.0.3
"@clerk/expo": 3.6.2
"@clerk/react": 6.11.1
"@clerk/shared": 4.22.0
"@clerk/expo": 3.7.1
"@clerk/react": 6.12.0
"@clerk/shared": 4.25.0
"@effect/atom-react": 4.0.0-beta.78
"@effect/openapi-generator": 4.0.0-beta.78
"@effect/platform-bun": 4.0.0-beta.78
@@ -51,6 +51,14 @@ catalog:
vite-plus: 0.2.2
yaml: ^2.9.0
minimumReleaseAgeExclude:
- "@clerk/[email protected]"
- "@clerk/[email protected]"
- "@clerk/[email protected]"
- "@clerk/[email protected]"
- "@clerk/[email protected]"
- "@clerk/[email protected]"
overrides:
"@clerk/backend": "catalog:"
"@clerk/clerk-js": "catalog:"
+68 -14
View File
@@ -11,7 +11,7 @@ import { ChildProcessSpawner } from "effect/unstable/process";
import {
BuildCommandFailedError,
createStageWorkspaceConfig,
createStagePnpmConfig,
createStagePatchedDependencies,
createBuildConfig,
DESKTOP_ASAR_UNPACK,
InvalidMacPasskeyRpDomainError,
@@ -168,7 +168,7 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
it("carries only staged dependency patch metadata into staged desktop installs", () => {
assert.deepStrictEqual(
createStagePnpmConfig(
createStagePatchedDependencies(
{
"@expo/[email protected]": "patches/@expo%[email protected]",
"@ff-labs/[email protected]": "patches/@[email protected]",
@@ -183,28 +183,26 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
},
),
{
patchedDependencies: {
"@ff-labs/[email protected]": "patches/@[email protected].patch",
"@pierre/[email protected]": "patches/@pierre%[email protected].patch",
"[email protected]": "patches/[email protected]",
},
"@ff-labs/[email protected]": "patches/@[email protected]",
"@pierre/[email protected]": "patches/@pierre%[email protected].patch",
"[email protected]": "patches/[email protected].patch",
},
);
assert.equal(
createStagePnpmConfig(
assert.deepStrictEqual(
createStagePatchedDependencies(
{
"@expo/[email protected]": "patches/@expo%[email protected]",
},
{ effect: "4.0.0-beta.73" },
),
undefined,
{},
);
});
it("installs optional native dependencies for the target desktop architecture", () => {
assert.deepStrictEqual(STAGE_INSTALL_ARGS, ["install", "--prod"]);
assert.deepStrictEqual(createStageWorkspaceConfig("mac", "x64"), {
assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "x64" }), {
supportedArchitectures: {
os: ["darwin"],
cpu: ["x64"],
@@ -212,21 +210,21 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
});
// Windows artifacts also bundle the same-architecture WSL (Linux, glibc) backend, so the
// staged install must fetch its native optional deps (e.g. ffi-rs) too.
assert.deepStrictEqual(createStageWorkspaceConfig("win", "x64"), {
assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "win", arch: "x64" }), {
supportedArchitectures: {
os: ["win32", "linux"],
cpu: ["x64"],
libc: ["glibc"],
},
});
assert.deepStrictEqual(createStageWorkspaceConfig("win", "arm64"), {
assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "win", arch: "arm64" }), {
supportedArchitectures: {
os: ["win32", "linux"],
cpu: ["arm64"],
libc: ["glibc"],
},
});
assert.deepStrictEqual(createStageWorkspaceConfig("mac", "universal"), {
assert.deepStrictEqual(createStageWorkspaceConfig({ platform: "mac", arch: "universal" }), {
supportedArchitectures: {
os: ["darwin"],
cpu: ["arm64", "x64"],
@@ -234,6 +232,62 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
});
});
it("stages pnpm 11 allowBuilds and patchedDependencies in the workspace yaml", () => {
assert.deepStrictEqual(
createStageWorkspaceConfig({
platform: "linux",
arch: "x64",
allowBuilds: {
electron: true,
"node-pty": true,
"browser-tabs-lock": false,
},
patchedDependencies: {
"[email protected]": "patches/[email protected]",
},
overrides: {
effect: "4.0.0-beta.73",
},
}),
{
supportedArchitectures: {
os: ["linux"],
cpu: ["x64"],
},
allowBuilds: {
electron: true,
"node-pty": true,
"browser-tabs-lock": false,
},
patchedDependencies: {
"[email protected]": "patches/[email protected]",
},
overrides: {
effect: "4.0.0-beta.73",
},
},
);
// Empty maps must not be written — pnpm would still require reviewed
// packages if allowBuilds is present but incomplete, and omitting empty
// patchedDependencies keeps the stage yaml minimal.
assert.deepStrictEqual(
createStageWorkspaceConfig({
platform: "mac",
arch: "arm64",
allowBuilds: {},
patchedDependencies: {},
overrides: {},
}),
{
supportedArchitectures: {
os: ["darwin"],
cpu: ["arm64"],
},
},
);
});
it("unpacks the fff shared library for filesystem and FFI access", () => {
assert.deepStrictEqual(DESKTOP_ASAR_UNPACK, ["node_modules/@ff-labs/fff-bin-*/**/*"]);
});
+50 -33
View File
@@ -40,6 +40,7 @@ const WorkspaceConfig = Schema.Struct({
catalog: Schema.optional(Schema.Record(Schema.String, Schema.String)),
overrides: Schema.optional(Schema.Record(Schema.String, Schema.String)),
patchedDependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
allowBuilds: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
});
type WorkspaceConfig = typeof WorkspaceConfig.Type;
@@ -49,7 +50,14 @@ const StageWorkspaceConfig = Schema.Struct({
cpu: Schema.Array(Schema.String),
libc: Schema.optional(Schema.Array(Schema.String)),
}),
// pnpm 11 only reads these from pnpm-workspace.yaml (not package.json#pnpm).
// Without allowBuilds the staged `vp install --prod` fails with
// ERR_PNPM_IGNORED_BUILDS for packages that have lifecycle scripts.
allowBuilds: Schema.optional(Schema.Record(Schema.String, Schema.Boolean)),
patchedDependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
overrides: Schema.optional(Schema.Record(Schema.String, Schema.String)),
});
type StageWorkspaceConfig = typeof StageWorkspaceConfig.Type;
const RepoRoot = Effect.service(Path.Path).pipe(
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
@@ -563,10 +571,6 @@ interface StagePackageJson {
readonly devDependencies: {
readonly electron: string;
};
readonly overrides: Record<string, unknown>;
readonly pnpm?: {
readonly patchedDependencies?: Record<string, string>;
};
}
export const STAGE_INSTALL_ARGS = ["install", "--prod"] as const;
@@ -876,10 +880,14 @@ const stageClerkPasskeyNativeBinaries = Effect.fn("stageClerkPasskeyNativeBinari
}
});
export function createStageWorkspaceConfig(
platform: typeof BuildPlatform.Type,
arch: typeof BuildArch.Type,
): typeof StageWorkspaceConfig.Type {
export function createStageWorkspaceConfig(input: {
readonly platform: typeof BuildPlatform.Type;
readonly arch: typeof BuildArch.Type;
readonly allowBuilds?: Record<string, boolean>;
readonly patchedDependencies?: Record<string, string>;
readonly overrides?: Record<string, string>;
}): StageWorkspaceConfig {
const { platform, arch, allowBuilds, patchedDependencies, overrides } = input;
const hostOs = platform === "mac" ? "darwin" : platform === "win" ? "win32" : "linux";
const hostCpu = arch === "universal" ? ["arm64", "x64"] : [arch];
// Windows artifacts also bundle the same-architecture WSL Linux backend, which loads
@@ -887,36 +895,37 @@ export function createStageWorkspaceConfig(
// Pull the Linux (glibc) variants in addition to the host platform's so
// they ship in the asar; without them the WSL backend crash-loops on require
// ("Cannot find module '@yuuang/ffi-rs-linux-x64-gnu'").
if (platform === "win") {
return {
supportedArchitectures: {
os: Array.from(new Set([hostOs, "linux"])),
cpu: hostCpu,
libc: ["glibc"],
},
};
}
const supportedArchitectures =
platform === "win"
? {
os: Array.from(new Set([hostOs, "linux"])),
cpu: hostCpu,
libc: ["glibc"],
}
: {
os: [hostOs],
cpu: hostCpu,
};
return {
supportedArchitectures: {
os: [hostOs],
cpu: hostCpu,
},
supportedArchitectures,
...(allowBuilds && Object.keys(allowBuilds).length > 0 ? { allowBuilds } : {}),
...(patchedDependencies && Object.keys(patchedDependencies).length > 0
? { patchedDependencies }
: {}),
...(overrides && Object.keys(overrides).length > 0 ? { overrides } : {}),
};
}
export function createStagePnpmConfig(
export function createStagePatchedDependencies(
patchedDependencies: Record<string, string>,
dependencies: Record<string, unknown>,
): StagePackageJson["pnpm"] | undefined {
const stagePatchedDependencies = Object.fromEntries(
): Record<string, string> {
return Object.fromEntries(
Object.entries(patchedDependencies).filter(([patchKey]) =>
Object.hasOwn(dependencies, getPatchedDependencyPackageName(patchKey)),
),
);
return Object.keys(stagePatchedDependencies).length > 0
? { patchedDependencies: stagePatchedDependencies }
: undefined;
}
function getPatchedDependencyPackageName(patchKey: string): string {
@@ -1540,6 +1549,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
const workspaceCatalog = workspaceConfig.catalog ?? {};
const workspaceOverrides = workspaceConfig.overrides ?? {};
const workspacePatchedDependencies = workspaceConfig.patchedDependencies ?? {};
const workspaceAllowBuilds = workspaceConfig.allowBuilds ?? {};
const platformConfig = PLATFORM_CONFIG[options.platform];
if (!platformConfig) {
@@ -1709,7 +1719,10 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
)
: {}),
};
const stagePnpmConfig = createStagePnpmConfig(workspacePatchedDependencies, stageDependencies);
const stagePatchedDependencies = createStagePatchedDependencies(
workspacePatchedDependencies,
stageDependencies,
);
const stagePackageJson: StagePackageJson = {
name: "t3code",
version: appVersion,
@@ -1738,20 +1751,24 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
devDependencies: {
electron: electronVersion,
},
overrides: resolvedOverrides,
...(stagePnpmConfig ? { pnpm: stagePnpmConfig } : {}),
};
const stagePackageJsonString = yield* encodeJsonString(stagePackageJson);
yield* fs.writeFileString(path.join(stageAppDir, "package.json"), `${stagePackageJsonString}\n`);
const stageWorkspaceConfig = createStageWorkspaceConfig(options.platform, options.arch);
const stageWorkspaceConfig = createStageWorkspaceConfig({
platform: options.platform,
arch: options.arch,
allowBuilds: workspaceAllowBuilds,
patchedDependencies: stagePatchedDependencies,
overrides: resolvedOverrides,
});
const stageWorkspaceConfigString = yield* encodeStageWorkspaceConfig(stageWorkspaceConfig);
yield* fs.writeFileString(
path.join(stageAppDir, "pnpm-workspace.yaml"),
stageWorkspaceConfigString,
);
if (Object.keys(workspacePatchedDependencies).length > 0) {
if (Object.keys(stagePatchedDependencies).length > 0) {
yield* fs.copy(path.join(repoRoot, "patches"), path.join(stageAppDir, "patches"));
}