( diff: ApiDiff, annotations: ReadonlyMap<string, MigrationAnnotation>, importMapSections: string )
| 286 | } |
| 287 | |
| 288 | export const renderMigrationDocument = ( |
| 289 | diff: ApiDiff, |
| 290 | annotations: ReadonlyMap<string, MigrationAnnotation>, |
| 291 | importMapSections: string |
| 292 | ): string => { |
| 293 | const entries = migrationEntries(diff, annotations, importMapSections) |
| 294 | const replacements = importMapReplacements(importMapSections) |
| 295 | const modulesRemoved = removedModules(diff) |
| 296 | const modules = new Map<string, Array<MigrationEntry>>() |
| 297 | for (const entry of entries) { |
| 298 | const group = modules.get(entry.module) |
| 299 | if (group === undefined) { |
| 300 | modules.set(entry.module, [entry]) |
| 301 | } else { |
| 302 | group.push(entry) |
| 303 | } |
| 304 | } |
| 305 | const lines = [ |
| 306 | "<!-- dprint-ignore-file -->", |
| 307 | "", |
| 308 | "# v3 to v4 Migration Reference", |
| 309 | "", |
| 310 | `Base: \`${diff.base.ref}\` (\`${diff.base.sha}\`)`, |
| 311 | "", |
| 312 | `Head: \`${diff.head.ref}\` (\`${diff.head.sha}\`)`, |
| 313 | "", |
| 314 | "This file is generated from the API diff and `migration/annotations/*.yaml`.", |
| 315 | "", |
| 316 | importMapSections.trim(), |
| 317 | "", |
| 318 | "## Removed Modules", |
| 319 | "" |
| 320 | ] |
| 321 | for (const module of modulesRemoved) { |
| 322 | const annotation = annotations.get(module) |
| 323 | const targets = replacements.get(module) |
| 324 | if (annotation !== undefined) { |
| 325 | lines.push( |
| 326 | `- ${codeSpan(module)} -> ${codeSpan(annotation.replacement)}: ${escapeAnnotationText(annotation.note)}` |
| 327 | ) |
| 328 | } else if (targets !== undefined) { |
| 329 | lines.push(`- ${codeSpan(module)} -> ${targets.map(codeSpan).join(", ")}`) |
| 330 | } else if ([...annotations.keys()].some((id) => id.startsWith(`${module}#`))) { |
| 331 | lines.push(`- ${codeSpan(module)}: No single module replacement; follow the curated per-API guidance below.`) |
| 332 | } else { |
| 333 | lines.push(`- ${codeSpan(module)}: TODO: needs module guidance`) |
| 334 | } |
| 335 | } |
| 336 | if (modulesRemoved.length === 0) { |
| 337 | lines.push("No modules were removed.") |
| 338 | } |
| 339 | lines.push( |
| 340 | "", |
| 341 | "## API Reference", |
| 342 | "" |
| 343 | ) |
| 344 | for (const [module, moduleEntries] of modules) { |
| 345 | lines.push(`### ${codeSpan(module)}`, "") |
no test coverage detected