Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

vite.config.ts

139 lines5.4 KB

1import "vite-plus/test/config";
2import { defineConfig, mergeConfig } from "vite-plus";
3​
4import baseConfig from "../../vite.config.ts";
5import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
6import rootPackageJson from "../../package.json" with { type: "json" };
7import packageJson from "./package.json" with { type: "json" };
8import { WeightedShardSequencer } from "./src/testUtils/weightedShardSequencer.ts";
9​
10// NSIS install time tracks file count, not bytes.
11import {
12 isExternalCliDependency,
13 shouldBundleCliDependency,
14} from "../../scripts/lib/cli-external-packages.ts";
15​
16export { shouldBundleCliDependency };
17​
18const repoEnv = loadRepoEnv();
19const cliBuildChannel = /^[^-+]+-(?:nightly|preview)\./.test(packageJson.version)
20 ? "nightly"
21 : "latest";
22// Official release workflows set the telemetry channel; local builds and forks use "dev".
23const TELEMETRY_CHANNELS = ["stable", "nightly", "preview", "dev"];
24const telemetryChannel = process.env.T3CODE_TELEMETRY_CHANNEL?.trim() || "dev";
25if (!TELEMETRY_CHANNELS.includes(telemetryChannel)) {
26 throw new Error(
27 `T3CODE_TELEMETRY_CHANNEL must be one of ${TELEMETRY_CHANNELS.join(", ")}, got "${telemetryChannel}".`,
28 );
30​
31// tsdown SEA needs one chunk (sourcemaps count) and Node >=25.7, so package separately.
32const packExecutable = process.env.T3CODE_PACK_EXE === "1";
33const SEA_TARGETS = {
34 "darwin-arm64": { platform: "darwin", arch: "arm64" },
35 "darwin-x64": { platform: "darwin", arch: "x64" },
36 "linux-arm64": { platform: "linux", arch: "arm64" },
37 "linux-x64": { platform: "linux", arch: "x64" },
38 "win-arm64": { platform: "win", arch: "arm64" },
39 "win-x64": { platform: "win", arch: "x64" },
40} as const;
41const packExecutableTarget = process.env.T3CODE_PACK_EXE_TARGET?.trim();
42const cliNodeVersion = rootPackageJson.engines.node;
43if (packExecutable && !packExecutableTarget && process.versions.node !== cliNodeVersion) {
44 throw new Error(
45 `Native CLI executables must be built with Node ${cliNodeVersion}; running ${process.versions.node}.`,
46 );
48if (packExecutableTarget && !Object.hasOwn(SEA_TARGETS, packExecutableTarget)) {
49 throw new Error(
50 `T3CODE_PACK_EXE_TARGET must be one of ${Object.keys(SEA_TARGETS).join(", ")}, got "${packExecutableTarget}".`,
51 );
53const packExecutableTargets = packExecutableTarget
54 ? [
55 {
56 ...SEA_TARGETS[packExecutableTarget as keyof typeof SEA_TARGETS],
57 nodeVersion: cliNodeVersion,
58 },
59 ]
60 : undefined;
61​
62// The root config's `projects` route repo-root runs to package configs,
63// including this one. Inheriting them would make this config a container.
64const { projects: _rootTestProjects, ...baseTestConfig } = baseConfig.test ?? {};
65// Workspace cache configuration is invalid on a package config.
66const { run: _rootRunConfig, ...basePackageConfig } = baseConfig;
67​
68export default mergeConfig(
69 { ...basePackageConfig, test: baseTestConfig },
70 defineConfig({
71 run: {
72 tasks: {
73 build: {
74 command: "node scripts/cli.ts build",
75 dependsOn: ["@t3tools/web#build"],
76 cache: false,
77 },
78 },
79 },
80 pack: {
81 // SEA embeds one entry; expose the history worker as a hidden subcommand.
82 entry: packExecutable ? ["src/bin.ts"] : ["src/bin.ts", "src/claude-history-worker.ts"],
83 outDir: packExecutable ? "dist-exe" : "dist",
84 sourcemap: !packExecutable,
85 clean: true,
86 ...(packExecutable
87 ? {
88 exe: {
89 fileName: "t3",
90 outDir: "dist-exe",
91 ...(packExecutableTargets ? { targets: packExecutableTargets } : {}),
92 // Node SEA useCodeCache breaks import(), which the server needs.
93 seaConfig: { useCodeCache: false },
94 },
95 }
96 : {}),
97 deps: {
98 // alwaysBundle=false has no opinion; neverBundle must retain transitive native acceleration.
99 alwaysBundle: shouldBundleCliDependency,
100 neverBundle: (id: string) => isExternalCliDependency(id),
101 onlyBundle: false,
102 },
103 banner: {
104 js: "#!/usr/bin/env node\n",
105 },
106 define: {
107 __T3CODE_BUILD_CHANNEL__: JSON.stringify(cliBuildChannel),
108 __T3CODE_TELEMETRY_CHANNEL__: JSON.stringify(telemetryChannel),
109 __T3CODE_BUILD_RELAY_URL__: JSON.stringify(repoEnv.T3CODE_RELAY_URL?.trim() ?? ""),
110 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
111 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
112 ),
113 __T3CODE_BUILD_CLERK_CLI_OAUTH_CLIENT_ID__: JSON.stringify(
114 repoEnv.T3CODE_CLERK_CLI_OAUTH_CLIENT_ID?.trim() ?? "",
115 ),
116 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_URL__: JSON.stringify(
117 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_URL?.trim() ?? "",
118 ),
119 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_DATASET__: JSON.stringify(
120 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET?.trim() ?? "",
121 ),
122 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_TOKEN__: JSON.stringify(
123 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN?.trim() ?? "",
124 ),
125 },
126 },
127 test: {
128 // Parallel sqlite/git/worktree/orchestration tests introduce load-sensitive flakes.
129 fileParallelism: false,
130 sequence: { sequencer: WeightedShardSequencer },
131 setupFiles: [
132 "./src/testUtils/gitConfig.setup.ts",
133 "./src/testUtils/managedServiceEnv.setup.ts",
134 ],
135 hookTimeout: 120_000,
136 testTimeout: 120_000,
137 },
138 }),
139);