MCPcopy
hub / github.com/freshframework/fresh / ProdBuildCache

Class ProdBuildCache

packages/fresh/src/build_cache.ts:50–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50export class ProdBuildCache<State> implements BuildCache<State> {
51 #snapshot: BuildSnapshot<State>;
52 islandRegistry: ServerIslandRegistry;
53 clientEntry: string;
54 features = { errorOverlay: false };
55
56 constructor(public root: string, snapshot: BuildSnapshot<State>) {
57 setBuildId(snapshot.version);
58 this.#snapshot = snapshot;
59 this.islandRegistry = snapshot.islands;
60 this.clientEntry = snapshot.clientEntry;
61 }
62
63 getEntryAssets(): string[] {
64 return this.#snapshot.entryAssets;
65 }
66
67 getFsRoutes(): Command<State>[] {
68 return fsItemsToCommands(this.#snapshot.fsRoutes);
69 }
70
71 async readFile(pathname: string): Promise<StaticFile | null> {
72 const { staticFiles } = this.#snapshot;
73
74 const info = staticFiles.get(pathname);
75 if (info === undefined) return null;
76
77 const filePath = path.isAbsolute(info.filePath)
78 ? info.filePath
79 : path.join(this.root, info.filePath);
80
81 const [stat, file] = await Promise.all([
82 Deno.stat(filePath),
83 Deno.open(filePath),
84 ]);
85
86 return {
87 hash: info.hash,
88 contentType: info.contentType,
89 size: stat.size,
90 readable: file.readable,
91 close: () => file.close(),
92 immutable: info.immutable,
93 };
94 }
95}
96
97export class IslandPreparer {
98 #namer = new UniqueNamer();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected