11// @ts -ignore This compiles fine, but Webstorm doesn't like the ESM import in a CJS context.
2- import type { DocEntry , JsDocTagEntry } from '@angular/compiler-cli' ;
3-
4- /** The JSON data file format for extracted API reference info. */
5- export interface EntryCollection {
6- moduleName : string ;
7- entries : DocEntry [ ] ;
8- }
2+ import type { DocEntry , EntryCollection , JsDocTagEntry } from '@angular/compiler-cli' ;
93
104export interface ManifestEntry {
115 name : string ;
@@ -16,7 +10,12 @@ export interface ManifestEntry {
1610}
1711
1812/** Manifest that maps each module name to a list of API symbols. */
19- export type Manifest = Record < string , ManifestEntry [ ] > ;
13+ export type Manifest = {
14+ moduleName : string ;
15+ normalizedModuleName : string ;
16+ moduleLabel : string ;
17+ entries : ManifestEntry [ ] ;
18+ } [ ] ;
2019
2120/** Gets a unique lookup key for an API, e.g. "@angular/core/ElementRef". */
2221function getApiLookupKey ( moduleName : string , name : string ) {
@@ -114,22 +113,39 @@ export function generateManifest(apiCollections: EntryCollection[]): Manifest {
114113 } ) ;
115114 }
116115
117- const manifest : Manifest = { } ;
116+ const manifest : Manifest = [ ] ;
118117 for ( const collection of apiCollections ) {
119- if ( ! manifest [ collection . moduleName ] ) {
120- manifest [ collection . moduleName ] = [ ] ;
118+ const entries = collection . entries . map ( ( entry ) => ( {
119+ name : entry . name ,
120+ type : entry . entryType ,
121+ isDeprecated : isDeprecated ( entryLookup , collection . moduleName , entry ) ,
122+ isDeveloperPreview : isDeveloperPreview ( entryLookup , collection . moduleName , entry ) ,
123+ isExperimental : isExperimental ( entryLookup , collection . moduleName , entry ) ,
124+ } ) ) ;
125+
126+ const existingEntry = manifest . find ( ( entry ) => entry . moduleName === collection . moduleName ) ;
127+ if ( existingEntry ) {
128+ existingEntry . entries . push ( ...entries ) ;
129+ } else {
130+ manifest . push ( {
131+ moduleName : collection . moduleName ,
132+ normalizedModuleName : collection . normalizedModuleName ,
133+ moduleLabel : collection . moduleLabel ?? collection . moduleName ,
134+ entries,
135+ } ) ;
121136 }
122-
123- manifest [ collection . moduleName ] . push (
124- ...collection . entries . map ( ( entry ) => ( {
125- name : entry . name ,
126- type : entry . entryType ,
127- isDeprecated : isDeprecated ( entryLookup , collection . moduleName , entry ) ,
128- isDeveloperPreview : isDeveloperPreview ( entryLookup , collection . moduleName , entry ) ,
129- isExperimental : isExperimental ( entryLookup , collection . moduleName , entry ) ,
130- } ) ) ,
131- ) ;
132137 }
133138
139+ manifest . sort ( ( entry1 , entry2 ) => {
140+ // Ensure that labels that start with a `code` tag like `window.ng` are last
141+ if ( entry1 . moduleLabel . startsWith ( '<' ) ) {
142+ return 1 ;
143+ } else if ( entry2 . moduleLabel . startsWith ( '<' ) ) {
144+ return - 1 ;
145+ }
146+
147+ return entry1 . moduleLabel . localeCompare ( entry2 . moduleLabel ) ;
148+ } ) ;
149+
134150 return manifest ;
135151}
0 commit comments