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