@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, 06:00 UTC

main
ts 51 lines 1.25 KB
Raw
1 import path from "node:path";
2 import type { OutputAsset, OutputChunk } from "rolldown";
3
4 export interface MiniflareModule {
5 path: string;
6 type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm" | "PythonModule";
7 contents?: string | Uint8Array<ArrayBuffer> | undefined;
8 }
9
10 export function miniflareModulesFromRolldownOutput(
11 output: Array<OutputChunk | OutputAsset>,
12 ): Array<MiniflareModule> {
13 return output.flatMap((item) => {
14 const type = moduleTypeFromExtension(path.extname(item.fileName));
15 const contents =
16 item.type === "chunk" ? item.code : (item.source as string | Uint8Array<ArrayBuffer>);
17 if (type === "SourceMap") {
18 return [];
19 }
20 return {
21 path: item.fileName,
22 type,
23 contents,
24 };
25 });
26 }
27
28 export function moduleTypeFromExtension(ext: string): MiniflareModule["type"] | "SourceMap" {
29 switch (ext) {
30 case ".wasm":
31 return "CompiledWasm";
32 case ".txt":
33 case ".html":
34 case ".sql":
35 case ".css":
36 case ".json":
37 case ".custom":
38 return "Text";
39 case ".bin":
40 return "Data";
41 case ".mjs":
42 case ".js":
43 return "ESModule";
44 case ".cjs":
45 return "CommonJS";
46 case ".map":
47 return "SourceMap";
48 default:
49 return "Text";
50 }
51 }