@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 169 lines 4.92 KB
Raw
1 import { defineConfig, type UserConfig } from "tsdown";
2 import { DEFAULT_COMPATIBILITY_DATE } from "./src/core/internal/constants.ts";
3 import {
4 InternalWorkerExportPlugin,
5 RuntimeSubpathExportPlugin,
6 } from "./src/internal/build-tools/index.ts";
7 import cloudflare from "./src/rolldown/plugin.ts";
8
9 /**
10 * Internal workers are built per compatibility-flag set: the `cloudflare`
11 * plugin adjusts its bundling (Node.js polyfills, warnings) based on the
12 * flags, which apply to a whole build.
13 */
14 const workerConfig = (
15 entry: Array<string> | Record<string, string>,
16 options: { compatibilityFlags?: Array<string>; clean?: boolean } = {},
17 ): UserConfig => ({
18 cwd: ".",
19 entry,
20 outDir: "dist/core/workers",
21 clean: options.clean,
22 tsconfig: "tsconfig.json",
23 format: "esm",
24 minify: {
25 mangle: false,
26 },
27 target: "esnext",
28 dts: false,
29 // The cloudflare/build-utils plugins are typed against the workspace's
30 // rolldown while tsdown's `UserConfig` is typed against its own nested
31 // copy; the structural compare between the two plugin types blows tsc's
32 // depth limit, so bridge through `unknown`.
33 plugins: [
34 cloudflare({
35 compatibilityDate: DEFAULT_COMPATIBILITY_DATE,
36 compatibilityFlags: options.compatibilityFlags,
37 externalRequire: false,
38 }),
39 InternalWorkerExportPlugin(),
40 ] as unknown as UserConfig["plugins"],
41 deps: {
42 neverBundle: [/^cloudflare-internal:/],
43 alwaysBundle: [/.+/],
44 },
45 outputOptions: {
46 entryFileNames: "[name].mjs",
47 },
48 });
49
50 export default defineConfig([
51 {
52 cwd: ".",
53 entry: ["src/rolldown/**/*.ts", "!src/rolldown/test/**/*.ts"],
54 exports: false,
55 outDir: "dist/rolldown",
56 tsconfig: "tsconfig.json",
57 unbundle: true,
58 dts: { incremental: false },
59 shims: false,
60 sourcemap: true,
61 target: "esnext",
62 format: "esm",
63 outputOptions: {
64 entryFileNames: "[name].js",
65 },
66 },
67 // `internal/shared.worker.ts` is a module shared between the workers, not a
68 // worker itself, so it isn't an entry: it's bundled into its importers (as
69 // a shared chunk when there are several).
70 workerConfig([
71 "src/core/**/*.worker.ts",
72 "!src/core/internal/shared.worker.ts",
73 "!src/core/**/R2Bucket.worker.ts",
74 ]),
75 // The R2 worker uses `node:crypto`; the 2026-08-31 date enables Node.js
76 // compatibility without a redundant flag. Don't
77 // clean the shared `dist/workers` directory, which the previous config
78 // already populated. The entry is named explicitly to keep the output at
79 // the path `worker:` imports resolve to.
80 workerConfig(
81 {
82 "bindings/r2-bucket/R2Bucket.worker": "src/core/bindings/r2-bucket/R2Bucket.worker.ts",
83 },
84 { clean: false },
85 ),
86 {
87 cwd: ".",
88 entry: [
89 "src/core/**/*.ts",
90 "!src/core/**/*.worker.ts",
91 "!src/core/globals.d.ts",
92 "!src/core/scripts/**/*.ts",
93 "!src/core/test/**/*.ts",
94 ],
95 // The consolidated package owns a hand-authored, prefixed export map.
96 // Component builds must never rewrite the root package.json.
97 exports: false,
98 outDir: "dist/core/node",
99 tsconfig: "tsconfig.json",
100 unbundle: true,
101 dts: { incremental: false },
102 shims: false,
103 target: "esnext",
104 format: "esm",
105 inputOptions: {
106 external: [/^#cloudflare-runtime-/],
107 makeAbsoluteExternalsRelative: true,
108 },
109 outputOptions: {
110 entryFileNames: (chunkInfo) => {
111 const name = chunkInfo.name.replace(
112 /(^node_modules\/.+\/node_modules\/)|(^packages\/vendor\/)/,
113 "vendor/",
114 );
115 return `${name}.${name.endsWith(".d") ? "mts" : "mjs"}`;
116 },
117 },
118 },
119 {
120 cwd: ".",
121 entry: ["src/vite/**/*.worker.ts"],
122 outDir: "dist/vite/workers",
123 tsconfig: "tsconfig.json",
124 format: "esm",
125 minify: {
126 mangle: false,
127 },
128 plugins: [
129 cloudflare({
130 compatibilityDate: DEFAULT_COMPATIBILITY_DATE,
131 // These workers are exported as single modules, so they cannot carry
132 // the helper chunk emitted by the external-require rewrite.
133 externalRequire: false,
134 }),
135 InternalWorkerExportPlugin(),
136 ],
137 deps: {
138 alwaysBundle: [/.+/],
139 },
140 dts: false,
141 outputOptions: {
142 entryFileNames: "[name].mjs",
143 },
144 },
145 {
146 cwd: ".",
147 entry: ["src/vite/plugin.ts"],
148 exports: false,
149 outDir: "dist/vite/node",
150 tsconfig: "tsconfig.json",
151 dts: { incremental: false },
152 shims: false,
153 target: "esnext",
154 format: "esm",
155 plugins: [RuntimeSubpathExportPlugin()],
156 deps: {
157 // These are subpaths of this consolidated package. Keep them as public
158 // imports so the Vite declaration bundle shares the core runtime types.
159 neverBundle: [/^@alchemy\.run\/cloudflare-runtime(?:\/|$)/],
160 },
161 inputOptions: {
162 external: [/^#cloudflare-runtime-/, /^@alchemy\.run\/cloudflare-runtime(?:\/|$)/],
163 makeAbsoluteExternalsRelative: true,
164 },
165 outputOptions: {
166 exports: "named",
167 },
168 },
169 ]);