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