( categories?: LibraryCategory[] | LibraryCategory | 'all' )
| 335 | * Topological sort of libraries that keeps the input order wherever the |
| 336 | * dependencies allow it. |
| 337 | * |
| 338 | * The libraries are visited in input order. Before a library is added, each |
| 339 | * library in its `requires` list is visited (and added) first, also in order. |
| 340 | * As a result, a library comes after every library listed before it in the |
| 341 | * input, unless an earlier library requires it: then it moves ahead of the |
| 342 | * first library that requires it. A caller library listed after |
| 343 | * the standard libraries, which no standard library requires, thus loads after |
| 344 | * them, even when it has no `requires` list: its definitions can use operators |
| 345 | * such as `Loop` (from `control-structures`) without declaring them. |
| 346 | * |
| 347 | * Throws on a duplicate name, a cycle or a missing dependency. |
| 348 | */ |
| 349 | export function sortLibraries(libs: LibraryDefinition[]): LibraryDefinition[] { |
| 350 | const byName = new Map<string, LibraryDefinition>(); |
| 351 | for (const lib of libs) { |
| 352 | if (byName.has(lib.name)) |
| 353 | throw new Error(`Duplicate library name: "${lib.name}"`); |
| 354 | byName.set(lib.name, lib); |
| 355 | } |
no test coverage detected