| 60 | } |
| 61 | |
| 62 | export class MemoryBuildCache<State> implements DevBuildCache<State> { |
| 63 | #processedFiles = new Map<string, MemoryFile>(); |
| 64 | #unprocessedFiles = new Map<string, string>(); |
| 65 | #config: ResolvedBuildConfig; |
| 66 | #transformer: FileTransformer; |
| 67 | islandModNameToChunk = new Map<string, IslandModChunk>(); |
| 68 | #fsRoutes: FsRoute<State>; |
| 69 | #commands: Command<State>[] = []; |
| 70 | root: string; |
| 71 | islandRegistry: ServerIslandRegistry = new Map(); |
| 72 | clientEntry: string; |
| 73 | hmrClientEntry: string | undefined = undefined; |
| 74 | features = { errorOverlay: false }; |
| 75 | |
| 76 | constructor( |
| 77 | config: ResolvedBuildConfig, |
| 78 | fsRoutes: FsRoute<State>, |
| 79 | transformer: FileTransformer, |
| 80 | ) { |
| 81 | if (config.mode === "development") { |
| 82 | this.features.errorOverlay = true; |
| 83 | } |
| 84 | |
| 85 | this.#config = config; |
| 86 | this.#fsRoutes = fsRoutes; |
| 87 | this.#transformer = transformer; |
| 88 | this.root = config.root; |
| 89 | |
| 90 | this.clientEntry = getClientEntry(config.buildId); |
| 91 | } |
| 92 | |
| 93 | getEntryAssets(): string[] { |
| 94 | return []; |
| 95 | } |
| 96 | |
| 97 | getFsRoutes(): Command<State>[] { |
| 98 | return this.#commands; |
| 99 | } |
| 100 | |
| 101 | async readFile(pathname: string): Promise<StaticFile | null> { |
| 102 | const processed = this.#processedFiles.get(pathname); |
| 103 | if (processed !== undefined) { |
| 104 | return { |
| 105 | hash: processed.hash, |
| 106 | readable: processed.content, |
| 107 | size: processed.content.byteLength, |
| 108 | contentType: processed.contentType, |
| 109 | close: () => {}, |
| 110 | }; |
| 111 | } |
| 112 | |
| 113 | const unprocessed = this.#unprocessedFiles.get(pathname); |
| 114 | if (unprocessed !== undefined) { |
| 115 | try { |
| 116 | const [stat, file] = await Promise.all([ |
| 117 | Deno.stat(unprocessed), |
| 118 | Deno.open(unprocessed, { read: true }), |
| 119 | ]); |
nothing calls this directly
no outgoing calls
no test coverage detected