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

vite.config.ts

136 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 packageJson from "./package.json" with { type: "json" };
7import { WeightedShardSequencer } from "./src/testUtils/weightedShardSequencer.ts";
8​
9// NSIS install time tracks file count, not bytes.
10import {
11 isExternalCliDependency,
12 shouldBundleCliDependency,
13} from "../../scripts/lib/cli-external-packages.ts";
14​
15export { shouldBundleCliDependency };
16​
17const repoEnv = loadRepoEnv();
18const cliBuildChannel = /^[^-+]+-(?:nightly|preview)\./.test(packageJson.version)
19 ? "nightly"
20 : "latest";
21// Sent with every analytics event. Release workflows set it for pingdotgg/t3code
22// builds only, so local builds and forks report "dev". A typo fails the build
23// instead of mislabeling events.
24const TELEMETRY_CHANNELS = ["stable", "nightly", "preview", "dev"];
25const telemetryChannel = process.env.T3CODE_TELEMETRY_CHANNEL?.trim() || "dev";
26if (!TELEMETRY_CHANNELS.includes(telemetryChannel)) {
27 throw new Error(
28 `T3CODE_TELEMETRY_CHANNEL must be one of ${TELEMETRY_CHANNELS.join(", ")}, got "${telemetryChannel}".`,
29 );
31​
32// `build:exe` wraps the same bundle in a Node single-executable. tsdown's exe
33// step refuses multi-chunk output and counts the sourcemap as a chunk, and the
34// executable needs a host Node that supports `--build-sea` (25.7+), so this is
35// a separate mode rather than a second entry in the default build.
36const packExecutable = process.env.T3CODE_PACK_EXE === "1";
37const SEA_NODE_VERSION = "26.8.2";
38const SEA_TARGETS = {
39 "darwin-arm64": { platform: "darwin", arch: "arm64" },
40 "darwin-x64": { platform: "darwin", arch: "x64" },
41 "linux-arm64": { platform: "linux", arch: "arm64" },
42 "linux-x64": { platform: "linux", arch: "x64" },
43 "win-arm64": { platform: "win", arch: "arm64" },
44 "win-x64": { platform: "win", arch: "x64" },
45} as const;
46const packExecutableTarget = process.env.T3CODE_PACK_EXE_TARGET?.trim();
47if (packExecutableTarget && !Object.hasOwn(SEA_TARGETS, packExecutableTarget)) {
48 throw new Error(
49 `T3CODE_PACK_EXE_TARGET must be one of ${Object.keys(SEA_TARGETS).join(", ")}, got "${packExecutableTarget}".`,
50 );
52const packExecutableTargets = packExecutableTarget
53 ? [
54 {
55 ...SEA_TARGETS[packExecutableTarget as keyof typeof SEA_TARGETS],
56 nodeVersion: SEA_NODE_VERSION,
57 },
58 ]
59 : undefined;
60​
61export default mergeConfig(
62 baseConfig,
63 defineConfig({
64 run: {
65 tasks: {
66 build: {
67 command: "node scripts/cli.ts build",
68 dependsOn: ["@t3tools/web#build"],
69 cache: false,
70 },
71 },
72 },
73 pack: {
74 // The executable embeds one entry; the history worker becomes a hidden
75 // subcommand there instead of a sibling script.
76 entry: packExecutable ? ["src/bin.ts"] : ["src/bin.ts", "src/claude-history-worker.ts"],
77 outDir: packExecutable ? "dist-exe" : "dist",
78 sourcemap: !packExecutable,
79 clean: true,
80 ...(packExecutable
81 ? {
82 exe: {
83 fileName: "t3",
84 outDir: "dist-exe",
85 ...(packExecutableTargets ? { targets: packExecutableTargets } : {}),
86 // Node's SEA docs: `import()` does not work when useCodeCache is
87 // true, and the server reaches several modules that way.
88 seaConfig: { useCodeCache: false },
89 },
90 }
91 : {}),
92 deps: {
93 // `neverBundle` forces the native packages out: returning false from
94 // `alwaysBundle` only means "no opinion", so a transitive dependency
95 // would still be bundled — which silently inlined native loaders such
96 // as node-gyp-build, losing native acceleration.
97 alwaysBundle: shouldBundleCliDependency,
98 neverBundle: (id: string) => isExternalCliDependency(id),
99 onlyBundle: false,
100 },
101 banner: {
102 js: "#!/usr/bin/env node\n",
103 },
104 define: {
105 __T3CODE_BUILD_CHANNEL__: JSON.stringify(cliBuildChannel),
106 __T3CODE_TELEMETRY_CHANNEL__: JSON.stringify(telemetryChannel),
107 __T3CODE_BUILD_RELAY_URL__: JSON.stringify(repoEnv.T3CODE_RELAY_URL?.trim() ?? ""),
108 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
109 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
110 ),
111 __T3CODE_BUILD_CLERK_CLI_OAUTH_CLIENT_ID__: JSON.stringify(
112 repoEnv.T3CODE_CLERK_CLI_OAUTH_CLIENT_ID?.trim() ?? "",
113 ),
114 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_URL__: JSON.stringify(
115 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_URL?.trim() ?? "",
116 ),
117 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_DATASET__: JSON.stringify(
118 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET?.trim() ?? "",
119 ),
120 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_TOKEN__: JSON.stringify(
121 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN?.trim() ?? "",
122 ),
123 },
124 },
125 test: {
126 // The server suite exercises sqlite, git, temp worktrees, and orchestration
127 // runtimes heavily. Running files in parallel introduces load-sensitive flakes.
128 fileParallelism: false,
129 sequence: { sequencer: WeightedShardSequencer },
130 // Appended to the root setup, which mergeConfig concatenates.
131 setupFiles: ["./src/testUtils/gitConfig.setup.ts"],
132 hookTimeout: 120_000,
133 testTimeout: 120_000,
134 },
135 }),
136);