(
url: string,
mod: EvaluatedModuleNode,
callstack: string[] = [],
metadata?: SSRImportMetadata,
)
| 163 | } |
| 164 | |
| 165 | private async cachedRequest( |
| 166 | url: string, |
| 167 | mod: EvaluatedModuleNode, |
| 168 | callstack: string[] = [], |
| 169 | metadata?: SSRImportMetadata, |
| 170 | ): Promise<any> { |
| 171 | const meta = mod.meta! |
| 172 | const moduleId = meta.id |
| 173 | |
| 174 | const importee = callstack[callstack.length - 1] |
| 175 | |
| 176 | if (importee) mod.importers.add(importee) |
| 177 | |
| 178 | // fast path: already evaluated modules can't deadlock |
| 179 | if (mod.evaluated && mod.promise) { |
| 180 | return this.processImport(await mod.promise, meta, metadata) |
| 181 | } |
| 182 | |
| 183 | if (mod.promise) { |
| 184 | if ( |
| 185 | mod.exports && |
| 186 | (callstack.includes(moduleId) || this.isCircularRequest(mod, callstack)) |
| 187 | ) { |
| 188 | return this.processImport(mod.exports, meta, metadata) |
| 189 | } |
| 190 | return this.processImport(await mod.promise, meta, metadata) |
| 191 | } |
| 192 | |
| 193 | let debugTimer: any |
| 194 | if (this.debug) { |
| 195 | debugTimer = setTimeout(() => { |
| 196 | const getStack = () => |
| 197 | `stack:\n${[...callstack, moduleId] |
| 198 | .reverse() |
| 199 | .map((p) => ` - ${p}`) |
| 200 | .join('\n')}` |
| 201 | |
| 202 | this.debug!( |
| 203 | `[module runner] module ${moduleId} takes over 2s to load.\n${getStack()}`, |
| 204 | ) |
| 205 | }, 2000) |
| 206 | } |
| 207 | |
| 208 | try { |
| 209 | const promise = this.directRequest(url, mod, callstack) |
| 210 | mod.promise = promise |
| 211 | mod.evaluated = false |
| 212 | return this.processImport(await promise, meta, metadata) |
| 213 | } finally { |
| 214 | mod.evaluated = true |
| 215 | if (debugTimer) clearTimeout(debugTimer) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | private async cachedModule( |
| 220 | url: string, |
no test coverage detected