Migrate workspace to Vite+ and pnpm (#2899)

Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-06-03 16:16:53 -07:00
1 parent d78e02cd0b
commit b440dd1812
299 files changed
+16445 -4576

No files matched your search

+30 -25
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import { parse as parseYaml } from "yaml";
import rootPackageJson from "../package.json" with { type: "json" };
import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
import serverPackageJson from "../apps/server/package.json" with { type: "json" };
@@ -28,11 +29,24 @@ const LINUX_ICON_SIZES = [16, 22, 24, 32, 48, 64, 128, 256, 512] as const;
const BuildPlatform = Schema.Literals(["mac", "linux", "win"]);
const BuildArch = Schema.Literals(["arm64", "x64", "universal"]);
interface WorkspaceConfig {
readonly catalog?: Record<string, string>;
readonly overrides?: Record<string, string>;
}
const RepoRoot = Effect.service(Path.Path).pipe(
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
);
const encodeJsonString = Schema.encodeEffect(Schema.UnknownFromJsonString);
const readWorkspaceConfig = Effect.fn("readWorkspaceConfig")(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const repoRoot = yield* RepoRoot;
const workspaceYaml = yield* fs.readFileString(path.join(repoRoot, "pnpm-workspace.yaml"));
return parseYaml(workspaceYaml) as WorkspaceConfig;
});
interface DesktopBuildIconAssets {
readonly macIconPng: string;
readonly linuxIconPng: string;
@@ -214,6 +228,7 @@ interface StagePackageJson {
readonly buildVersion: string;
readonly t3codeCommitHash: string;
readonly private: true;
readonly packageManager: string;
readonly description: string;
readonly author: string;
readonly main: string;
@@ -695,6 +710,9 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
const repoRoot = yield* RepoRoot;
const path = yield* Path.Path;
const fs = yield* FileSystem.FileSystem;
const workspaceConfig = yield* readWorkspaceConfig();
const workspaceCatalog = workspaceConfig.catalog ?? {};
const workspaceOverrides = workspaceConfig.overrides ?? {};
const platformConfig = PLATFORM_CONFIG[options.platform];
if (!platformConfig) {
@@ -713,12 +731,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
}
const resolvedOverrides = yield* Effect.try({
try: () =>
resolveCatalogDependencies(
rootPackageJson.overrides,
rootPackageJson.workspaces.catalog,
"apps/desktop",
),
try: () => resolveCatalogDependencies(workspaceOverrides, workspaceCatalog, "apps/desktop"),
catch: (cause) =>
new BuildScriptError({
message: "Could not resolve overrides from package.json.",
@@ -727,12 +740,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
});
const resolvedServerDependencies = yield* Effect.try({
try: () =>
resolveCatalogDependencies(
serverDependencies,
rootPackageJson.workspaces.catalog,
"apps/server",
),
try: () => resolveCatalogDependencies(serverDependencies, workspaceCatalog, "apps/server"),
catch: (cause) =>
new BuildScriptError({
message: "Could not resolve production dependencies from apps/server/package.json.",
@@ -740,11 +748,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
}),
});
const resolvedDesktopRuntimeDependencies = yield* Effect.try({
try: () =>
resolveDesktopRuntimeDependencies(
desktopPackageJson.dependencies,
rootPackageJson.workspaces.catalog,
),
try: () => resolveDesktopRuntimeDependencies(desktopPackageJson.dependencies, workspaceCatalog),
catch: (cause) =>
new BuildScriptError({
message: "Could not resolve desktop runtime dependencies from apps/desktop/package.json.",
@@ -775,23 +779,23 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
ChildProcess.make({
cwd: repoRoot,
...commandOutputOptions(options.verbose),
// Windows needs shell mode to resolve .cmd shims (e.g. bun.cmd).
// Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd).
shell: process.platform === "win32",
})`bun run build:desktop`,
})`vp run build:desktop`,
);
}
for (const [label, dir] of Object.entries(distDirs)) {
if (!(yield* fs.exists(dir))) {
return yield* new BuildScriptError({
message: `Missing ${label} at ${dir}. Run 'bun run build:desktop' first.`,
message: `Missing ${label} at ${dir}. Run 'vp run build:desktop' first.`,
});
}
}
if (!(yield* fs.exists(bundledClientEntry))) {
return yield* new BuildScriptError({
message: `Missing bundled server client at ${bundledClientEntry}. Run 'bun run build:desktop' first.`,
message: `Missing bundled server client at ${bundledClientEntry}. Run 'vp run build:desktop' first.`,
});
}
@@ -825,6 +829,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
buildVersion: appVersion,
t3codeCommitHash: commitHash,
private: true,
packageManager: rootPackageJson.packageManager,
description: "T3 Code desktop build",
author: "T3 Tools",
main: "apps/desktop/dist-electron/main.cjs",
@@ -854,9 +859,9 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
ChildProcess.make({
cwd: stageAppDir,
...commandOutputOptions(options.verbose),
// Windows needs shell mode to resolve .cmd shims (e.g. bun.cmd).
// Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd).
shell: process.platform === "win32",
})`bun install --production --omit optional`,
})`vp install --prod --no-optional`,
);
const buildEnv: NodeJS.ProcessEnv = {
@@ -896,7 +901,7 @@ const buildDesktopArtifact = Effect.fn("buildDesktopArtifact")(function* (
...commandOutputOptions(options.verbose),
// Windows needs shell mode to resolve .cmd shims.
shell: process.platform === "win32",
})`bun x --install=fallback electron-builder ${platformConfig.cliFlag} --${options.arch} --publish never`,
})`vp dlx electron-builder ${platformConfig.cliFlag} --${options.arch} --publish never`,
);
const stageDistDir = path.join(stageAppDir, "dist");
@@ -956,7 +961,7 @@ const buildDesktopArtifactCli = Command.make("build-desktop-artifact", {
),
skipBuild: Flag.boolean("skip-build").pipe(
Flag.withDescription(
"Skip `bun run build:desktop` and use existing dist artifacts (env: T3CODE_DESKTOP_SKIP_BUILD).",
"Skip `vp run build:desktop` and use existing dist artifacts (env: T3CODE_DESKTOP_SKIP_BUILD).",
),
Flag.optional,
),
+27
View File
@@ -8,11 +8,38 @@ import {
checkPortAvailabilityOnHosts,
createDevRunnerEnv,
findFirstAvailableOffset,
getDevRunnerModeArgs,
resolveModePortOffsets,
resolveOffset,
} from "./dev-runner.ts";
it.layer(NodeServices.layer)("dev-runner", (it) => {
describe("getDevRunnerModeArgs", () => {
it.effect("lets Vite+ honor the desktop dev task graph", () =>
Effect.sync(() => {
assert.deepStrictEqual(getDevRunnerModeArgs("dev:desktop"), [
"run",
"--filter=@t3tools/desktop",
"--filter=@t3tools/web",
"dev",
]);
}),
);
it.effect("places Vite+ run flags before the task name", () =>
Effect.sync(() => {
assert.deepStrictEqual(getDevRunnerModeArgs("dev"), [
"run",
"--filter=@t3tools/contracts",
"--filter=@t3tools/web",
"--filter=t3",
"--parallel",
"dev",
]);
}),
);
});
describe("resolveOffset", () => {
it.effect("uses explicit T3CODE_PORT_OFFSET when provided", () =>
Effect.sync(() => {
+27 -28
View File
@@ -31,16 +31,15 @@ export const DEFAULT_T3_HOME = Effect.map(Effect.service(Path.Path), (path) =>
const MODE_ARGS = {
dev: [
"run",
"dev",
"--ui=tui",
"--filter=@t3tools/contracts",
"--filter=@t3tools/web",
"--filter=t3",
"--parallel",
"dev",
],
"dev:server": ["run", "dev", "--filter=t3"],
"dev:web": ["run", "dev", "--filter=@t3tools/web"],
"dev:desktop": ["run", "dev", "--filter=@t3tools/desktop", "--filter=@t3tools/web", "--parallel"],
"dev:server": ["run", "--filter=t3", "dev"],
"dev:web": ["run", "--filter=@t3tools/web", "dev"],
"dev:desktop": ["run", "--filter=@t3tools/desktop", "--filter=@t3tools/web", "dev"],
} as const satisfies Record<string, ReadonlyArray<string>>;
type DevMode = keyof typeof MODE_ARGS;
@@ -48,6 +47,10 @@ type PortAvailabilityCheck<R = never> = (port: number) => Effect.Effect<boolean,
const DEV_RUNNER_MODES = Object.keys(MODE_ARGS) as Array<DevMode>;
export function getDevRunnerModeArgs(mode: DevMode): ReadonlyArray<string> {
return MODE_ARGS[mode];
}
class DevRunnerError extends Data.TaggedError("DevRunnerError")<{
readonly message: string;
readonly cause?: unknown;
@@ -380,7 +383,7 @@ interface DevRunnerCliInput {
readonly port: number | undefined;
readonly devUrl: URL | undefined;
readonly dryRun: boolean;
readonly turboArgs: ReadonlyArray<string>;
readonly runArgs: ReadonlyArray<string>;
}
export function runDevRunnerWithInput(input: DevRunnerCliInput) {
@@ -438,29 +441,25 @@ export function runDevRunnerWithInput(input: DevRunnerCliInput) {
return;
}
const child = yield* ChildProcess.make(
"turbo",
[...MODE_ARGS[input.mode], ...input.turboArgs],
{
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
env,
extendEnv: false,
// Windows needs shell mode to resolve .cmd shims (e.g. bun.cmd).
shell: process.platform === "win32",
// Keep turbo in the same process group so terminal signals (Ctrl+C)
// reach it directly. Effect defaults to detached: true on non-Windows,
// which would put turbo in a new group and require manual forwarding.
detached: false,
forceKillAfter: "1500 millis",
},
);
const child = yield* ChildProcess.make("vp", [...MODE_ARGS[input.mode], ...input.runArgs], {
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
env,
extendEnv: false,
// Windows needs shell mode to resolve .cmd shims (e.g. vp.cmd).
shell: process.platform === "win32",
// Keep Vite+ in the same process group so terminal signals (Ctrl+C)
// reach it directly. Effect defaults to detached: true on non-Windows,
// which would put the runner in a new group and require manual forwarding.
detached: false,
forceKillAfter: "1500 millis",
});
const exitCode = yield* child.exitCode;
if (exitCode !== 0) {
return yield* new DevRunnerError({
message: `turbo exited with code ${exitCode}`,
message: `vp run exited with code ${exitCode}`,
});
}
}).pipe(
@@ -513,11 +512,11 @@ const devRunnerCli = Command.make("dev-runner", {
Flag.withFallbackConfig(optionalUrlConfig("VITE_DEV_SERVER_URL")),
),
dryRun: Flag.boolean("dry-run").pipe(
Flag.withDescription("Resolve mode/ports/env and print, but do not spawn turbo."),
Flag.withDescription("Resolve mode/ports/env and print, but do not spawn Vite+."),
Flag.withDefault(false),
),
turboArgs: Argument.string("turbo-arg").pipe(
Argument.withDescription("Additional turbo args (pass after `--`)."),
runArgs: Argument.string("run-arg").pipe(
Argument.withDescription("Additional Vite+ run args (pass after `--`)."),
Argument.variadic(),
),
}).pipe(
+1 -1
View File
@@ -1,4 +1,4 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it } from "vite-plus/test";
import {
BRAND_ASSET_PATHS,
+1 -2
View File
@@ -1,5 +1,4 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
import { NodeHttpServer, NodeServices } from "@effect/platform-node";
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
+1 -3
View File
@@ -1,9 +1,7 @@
// @effect-diagnostics-next-line nodeBuiltinImport:off - NodeHttpServer.layer takes `NodeHttp.createServer` as arg
import * as NodeHttp from "node:http";
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { NodeHttpServer, NodeRuntime, NodeServices } from "@effect/platform-node";
import * as Config from "effect/Config";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
+2 -1
View File
@@ -4,7 +4,7 @@
"type": "module",
"scripts": {
"typecheck": "tsgo --noEmit",
"test": "vitest run"
"test": "vp test run"
},
"dependencies": {
"@anthropic-ai/claude-agent-sdk": "^0.2.77",
@@ -16,6 +16,7 @@
"devDependencies": {
"@effect/vitest": "catalog:",
"@types/bun": "catalog:",
"vite-plus": "catalog:",
"vitest": "catalog:"
}
}
+32 -18
View File
@@ -19,10 +19,15 @@ const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const workspaceFiles = [
"package.json",
"bun.lock",
"pnpm-lock.yaml",
"pnpm-workspace.yaml",
"apps/server/package.json",
"apps/desktop/package.json",
"apps/web/package.json",
"apps/mobile/package.json",
"apps/mobile/deps/react-native-nitro-markdown-0.5.0.tgz",
"apps/mobile/modules/t3-review-diff/package.json",
"apps/mobile/modules/t3-terminal/package.json",
"apps/marketing/package.json",
"oxlint-plugin-t3code/package.json",
"packages/client-runtime/package.json",
@@ -43,15 +48,9 @@ function copyWorkspaceManifestFixture(targetRoot: string): void {
cpSync(sourcePath, destinationPath);
}
const packageJson = JSON.parse(readFileSync(resolve(repoRoot, "package.json"), "utf8")) as {
readonly patchedDependencies?: Record<string, string>;
};
for (const relativePath of Object.values(packageJson.patchedDependencies ?? {})) {
const sourcePath = resolve(repoRoot, relativePath);
const destinationPath = resolve(targetRoot, relativePath);
mkdirSync(dirname(destinationPath), { recursive: true });
cpSync(sourcePath, destinationPath);
const patchesDirectory = resolve(repoRoot, "patches");
if (existsSync(patchesDirectory)) {
cpSync(patchesDirectory, resolve(targetRoot, "patches"), { recursive: true });
}
}
@@ -176,6 +175,16 @@ function assertExists(path: string, message: string): void {
}
}
function assertPackageVersion(path: string, version: string): void {
const packageJson = JSON.parse(readFileSync(path, "utf8")) as {
readonly version?: unknown;
};
if (packageJson.version !== version) {
throw new Error(`Expected ${path} to have version ${version}.`);
}
}
function assertMissing(path: string, message: string): void {
if (existsSync(path)) {
throw new Error(message);
@@ -201,19 +210,24 @@ try {
},
);
rmSync(resolve(tempRoot, "bun.lock"), { force: true });
rmSync(resolve(tempRoot, "pnpm-lock.yaml"), { force: true });
execFileSync("bun", ["install", "--ignore-scripts"], {
execFileSync("vp", ["install", "--lockfile-only", "--ignore-scripts"], {
cwd: tempRoot,
stdio: "inherit",
});
const lockfile = readFileSync(resolve(tempRoot, "bun.lock"), "utf8");
assertContains(
lockfile,
`"version": "9.9.9-smoke.0"`,
"Expected bun.lock to contain the smoke version.",
);
const lockfile = readFileSync(resolve(tempRoot, "pnpm-lock.yaml"), "utf8");
assertContains(lockfile, "lockfileVersion:", "Expected pnpm-lock.yaml to be regenerated.");
for (const relativePath of [
"apps/server/package.json",
"apps/desktop/package.json",
"apps/web/package.json",
"packages/contracts/package.json",
]) {
assertPackageVersion(resolve(tempRoot, relativePath), "9.9.9-smoke.0");
}
const nightlyReleaseMetadata = execFileSync(
process.execPath,