| 206 | // once after the caller finishes preparing dependencies. Once dynamic import runs, failures are |
| 207 | // treated as permanent for this process because Bun caches failed module resolution. |
| 208 | export async function loadExternal<R = Loaded>(input: Input<R>): Promise<R[]> { |
| 209 | const candidates = input.items.map((origin) => ({ origin, plan: plan(origin.spec) })) |
| 210 | const list: Array<Promise<AttemptResult<R>>> = [] |
| 211 | for (const candidate of candidates) { |
| 212 | list.push(attempt(candidate, input.kind, false, input.finish, input.missing, input.report)) |
| 213 | } |
| 214 | const out = await Promise.all(list) |
| 215 | if (input.wait) { |
| 216 | let deps: Promise<void> | undefined |
| 217 | for (let i = 0; i < candidates.length; i++) { |
| 218 | const previous = out[i] |
| 219 | if (previous?.value !== undefined) continue |
| 220 | if (previous?.retry !== true) continue |
| 221 | |
| 222 | // Only pre-import file plugin setup failures are retried. Bun caches failed dynamic imports, |
| 223 | // so dependency waiting cannot fix load/build/runtime/shape failures in this process. |
| 224 | const candidate = candidates[i] |
| 225 | if (!candidate || pluginSource(candidate.plan.spec) !== "file") continue |
| 226 | deps ??= input.wait() |
| 227 | await deps |
| 228 | out[i] = await attempt(candidate, input.kind, true, input.finish, input.missing, input.report) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | // Drop skipped/failed entries while preserving the successful result order. |
| 233 | const ready: R[] = [] |
| 234 | for (const item of out) if (item.value !== undefined) ready.push(item.value) |
| 235 | return ready |
| 236 | } |
| 237 | } |