@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 46 lines 1.52 KB
Raw
1 import type { OutputAsset, OutputChunk, RolldownOutput } from "rolldown";
2
3 const CLOUDFLARE_MODULE_REFERENCE_REGEX =
4 /__CLOUDFLARE_MODULE__(CompiledWasm|Data|Text)__(.*?)__CLOUDFLARE_MODULE__/;
5
6 export function getEntryChunk(output: RolldownOutput): OutputChunk {
7 const entry = output.output.find(
8 (item): item is OutputChunk => item.type === "chunk" && item.isEntry,
9 );
10 if (!entry) {
11 throw new Error("Expected generated output to contain an entry chunk");
12 }
13 return entry;
14 }
15
16 export function getChunk(output: RolldownOutput, fileName: string): OutputChunk {
17 const chunk = output.output.find(
18 (item): item is OutputChunk => item.type === "chunk" && item.fileName === fileName,
19 );
20 if (!chunk) {
21 throw new Error(`Expected generated output to contain chunk "${fileName}"`);
22 }
23 return chunk;
24 }
25
26 export function findAsset(output: RolldownOutput, matcher: RegExp): OutputAsset | undefined {
27 return output.output.find(
28 (item): item is OutputAsset => item.type === "asset" && matcher.test(item.fileName),
29 );
30 }
31
32 export function getAsset(output: RolldownOutput, matcher: RegExp): OutputAsset {
33 const asset = findAsset(output, matcher);
34 if (!asset) {
35 throw new Error(`Expected generated output to contain asset matching ${matcher}`);
36 }
37 return asset;
38 }
39
40 export function getFileNames(output: RolldownOutput): Array<string> {
41 return output.output.map((item) => item.fileName);
42 }
43
44 export function hasCloudflareModuleReferences(code: string): boolean {
45 return CLOUDFLARE_MODULE_REFERENCE_REGEX.test(code);
46 }