Open History to see the last commit
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" };
7
8// The bundle used to inline only workspace packages, leaving every third-party
9// runtime dep external. External deps must exist on the real filesystem (the WSL
10// backend runs plain `wsl.exe -- node`, which cannot read inside an asar), so the
11// desktop build unpacked `**\/node_modules\/**` wholesale: 13,875 loose files to
12// support 20 native binaries. NSIS install time tracks file count, not bytes.
13//
14// Inverted here — bundle everything except the packages that genuinely cannot be
15// inlined. See scripts/lib/cli-external-packages.ts for what earns an exemption.
16import {
17 isExternalCliDependency,
18 shouldBundleCliDependency,
19} from "../../scripts/lib/cli-external-packages.ts";
20
21export { shouldBundleCliDependency };
22
23const repoEnv = loadRepoEnv();
24const cliBuildChannel = /^[^-+]+-(?:nightly|preview)\./.test(packageJson.version)
25 ? "nightly"
26 : "latest";
27
28// `build:exe` wraps the same bundle in a Node single-executable. tsdown's exe
29// step refuses multi-chunk output and counts the sourcemap as a chunk, and the
30// executable needs a host Node that supports `--build-sea` (25.7+), so this is
31// a separate mode rather than a second entry in the default build.
32const packExecutable = process.env.T3CODE_PACK_EXE === "1";
33// `<platform>-<arch>` in nodejs.org naming (darwin-x64, linux-arm64, win-x64).
34// When set, tsdown injects the bundle into a downloaded Node of that target
35// instead of the host Node, which is how the arm64 macOS runner produces the
36// x64 archive. Cross-building is safe because the code cache is off.
37//
38// The Node inside the executable is pinned here rather than taken from the
39// build host, so every archive of a release embeds the same runtime no matter
40// which Node happens to run the build.
41const SEA_NODE_VERSION = "26.8.2";
42const SEA_TARGETS = {
43 "darwin-arm64": { platform: "darwin", arch: "arm64" },
44 "darwin-x64": { platform: "darwin", arch: "x64" },
45 "linux-arm64": { platform: "linux", arch: "arm64" },
46 "linux-x64": { platform: "linux", arch: "x64" },
47 "win-arm64": { platform: "win", arch: "arm64" },
48 "win-x64": { platform: "win", arch: "x64" },
49} as const;
50const packExecutableTarget = process.env.T3CODE_PACK_EXE_TARGET?.trim();
51if (packExecutableTarget && !Object.hasOwn(SEA_TARGETS, packExecutableTarget)) {
52 throw new Error(
53 `T3CODE_PACK_EXE_TARGET must be one of ${Object.keys(SEA_TARGETS).join(", ")}, got "${packExecutableTarget}".`,
54 );
55}
56const packExecutableTargets = packExecutableTarget
57 ? [
58 {
59 ...SEA_TARGETS[packExecutableTarget as keyof typeof SEA_TARGETS],
60 nodeVersion: SEA_NODE_VERSION,
61 },
62 ]
63 : undefined;
64
65export default mergeConfig(
66 baseConfig,
67 defineConfig({
68 run: {
69 tasks: {
70 build: {
71 command: "node scripts/cli.ts build",
72 dependsOn: ["@t3tools/web#build"],
73 cache: false,
74 },
75 },
76 },
77 pack: {
78 // The executable embeds one entry; the history worker becomes a hidden
79 // subcommand there instead of a sibling script.
80 entry: packExecutable ? ["src/bin.ts"] : ["src/bin.ts", "src/claude-history-worker.ts"],
81 outDir: packExecutable ? "dist-exe" : "dist",
82 sourcemap: !packExecutable,
83 clean: true,
84 ...(packExecutable
85 ? {
86 exe: {
87 fileName: "t3",
88 outDir: "dist-exe",
89 ...(packExecutableTargets ? { targets: packExecutableTargets } : {}),
90 // Node's SEA docs: `import()` does not work when useCodeCache is
91 // true, and the server reaches several modules that way. The
92 // cache is also platform-bound, so leaving it off keeps the
93 // build correct on any host.
94 seaConfig: { useCodeCache: false },
95 },
96 }
97 : {}),
98 deps: {
99 // Both halves are required. `alwaysBundle` forces the JS dependencies in
100 // (declared deps are external by default, which is what this change is
101 // undoing). `neverBundle` forces the native packages out: returning
102 // false from `alwaysBundle` only means "no opinion", so a transitive
103 // dependency would still be bundled — which silently inlined native
104 // loaders such as node-gyp-build, losing native acceleration.
105 alwaysBundle: shouldBundleCliDependency,
106 neverBundle: (id: string) => isExternalCliDependency(id),
107 onlyBundle: false,
108 },
109 banner: {
110 js: "#!/usr/bin/env node\n",
111 },
112 define: {
113 __T3CODE_BUILD_CHANNEL__: JSON.stringify(cliBuildChannel),
114 __T3CODE_BUILD_RELAY_URL__: JSON.stringify(repoEnv.T3CODE_RELAY_URL?.trim() ?? ""),
115 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
116 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
117 ),
118 __T3CODE_BUILD_CLERK_CLI_OAUTH_CLIENT_ID__: JSON.stringify(
119 repoEnv.T3CODE_CLERK_CLI_OAUTH_CLIENT_ID?.trim() ?? "",
120 ),
121 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_URL__: JSON.stringify(
122 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_URL?.trim() ?? "",
123 ),
124 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_DATASET__: JSON.stringify(
125 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_DATASET?.trim() ?? "",
126 ),
127 __T3CODE_BUILD_RELAY_CLIENT_OTLP_TRACES_TOKEN__: JSON.stringify(
128 repoEnv.T3CODE_RELAY_CLIENT_OTLP_TRACES_TOKEN?.trim() ?? "",
129 ),
130 },
131 },
132 test: {
133 // The server suite exercises sqlite, git, temp worktrees, and orchestration
134 // runtimes heavily. Running files in parallel introduces load-sensitive flakes.
135 fileParallelism: false,
136 // Appended to the root setup, which mergeConfig concatenates.
137 setupFiles: ["./src/testUtils/gitConfig.setup.ts"],
138 // Server integration tests exercise sqlite, git, and orchestration together.
139 // Under package-wide runs they can exceed the default budget on loaded CI hosts.
140 hookTimeout: 120_000,
141 testTimeout: 120_000,
142 },
143 }),
144);