@@ -55,7 +55,9 @@ async function compare() {
55
55
// find all matching pairs based on what's been published
56
56
for ( let pubApi of publishedAPIs ) {
57
57
let pubApiPath = pubApi . split ( path . sep ) ;
58
- let sharedPath = path . join ( ...pubApiPath . slice ( pubApiPath . length - 4 ) ) ;
58
+ let pkgJson = fs . readJsonSync ( path . join ( '/' , ...pubApiPath . slice ( 0 , pubApiPath . length - 2 ) , 'package.json' ) ) ;
59
+ let name = pkgJson . name ;
60
+ let sharedPath = path . join ( name , 'dist' , 'api.json' ) ;
59
61
let found = false ;
60
62
for ( let branchApi of branchAPIs ) {
61
63
if ( branchApi . includes ( sharedPath ) ) {
@@ -72,7 +74,9 @@ async function compare() {
72
74
// don't care about private APIs, but we do care if we're about to publish a new one
73
75
for ( let branchApi of branchAPIs ) {
74
76
let branchApiPath = branchApi . split ( path . sep ) ;
75
- let sharedPath = path . join ( ...branchApiPath . slice ( branchApiPath . length - 4 ) ) ;
77
+ let pkgJson = fs . readJsonSync ( path . join ( '/' , ...branchApiPath . slice ( 0 , branchApiPath . length - 2 ) , 'package.json' ) ) ;
78
+ let name = pkgJson . name ;
79
+ let sharedPath = path . join ( name , 'dist' , 'api.json' ) ;
76
80
let found = false ;
77
81
for ( let pubApi of publishedAPIs ) {
78
82
if ( pubApi . includes ( sharedPath ) ) {
@@ -114,10 +118,11 @@ async function compare() {
114
118
if ( diff . length > 0 ) {
115
119
let affected = followInvertedDependencies ( simplifiedName , invertedDeps ) ;
116
120
// combine export change messages
121
+ // remove extra newline we added between the name of the interface and the properties to make the diffs easier to read
117
122
changes . push ( `
118
123
#### ${ simplifiedName }
119
124
${ changedByDeps . length > 0 ? `changed by:
120
- - ${ changedByDeps . join ( '\n - ' ) } \n\n` : '' } ${ diff . length > 0 ? diff : '' } ${ affected . length > 0 ? `
125
+ - ${ changedByDeps . join ( '\n - ' ) } \n\n` : '' } ${ diff . split ( '\n' ) . filter ( line => line !== ' ' ) . join ( '\n' ) } ${ affected . length > 0 ? `
121
126
it changed:
122
127
- ${ affected . join ( '\n - ' ) }
123
128
` : '' }
@@ -371,6 +376,9 @@ function processType(value) {
371
376
}
372
377
return name ;
373
378
}
379
+ if ( value . type === 'mapped' ) {
380
+ return `${ value . readonly === '-' ? '-readonly' : '' } ${ processType ( value . typeParameter ) } : ${ processType ( value . typeAnnotation ) } ` ;
381
+ }
374
382
// interface still needed if we have it at top level?
375
383
if ( value . type === 'object' ) {
376
384
if ( value . properties ) {
@@ -428,7 +436,7 @@ ${value.exact ? '\\}' : '}'}`;
428
436
return `keyof ${ processType ( value . keyof ) } ` ;
429
437
}
430
438
431
- console . log ( 'unknown type' , value ) ;
439
+ return `UNKNOWN: ${ value . type } ` ;
432
440
}
433
441
434
442
function rebuildInterfaces ( json ) {
@@ -445,10 +453,12 @@ function rebuildInterfaces(json) {
445
453
let item = json . exports [ key ] ;
446
454
if ( item ?. type == null ) {
447
455
// todo what to do here??
456
+ exports [ item . name ] = 'UNTYPED' ;
448
457
return ;
449
458
}
450
459
if ( item . props ?. type === 'identifier' ) {
451
460
// todo what to do here??
461
+ exports [ item . name ] = 'UNTYPED' ;
452
462
return ;
453
463
}
454
464
if ( item . type === 'component' ) {
@@ -479,8 +489,11 @@ function rebuildInterfaces(json) {
479
489
compInterface [ name ] = { optional, defaultVal, value} ;
480
490
}
481
491
let name = item . name ?? key ;
482
- if ( item . typeParameters . length > 0 ) {
483
- name = name + `<${ item . typeParameters . map ( processType ) . sort ( ) . join ( ', ' ) } >` ;
492
+ if ( item . typeParameters ?. length > 0 ) {
493
+ compInterface [ 'typeParameters' ] = `<${ item . typeParameters . map ( processType ) . sort ( ) . join ( ', ' ) } >` ;
494
+ }
495
+ if ( item . props ?. extends ?. length > 0 ) {
496
+ compInterface [ 'extend' ] = `extends ${ item . props . extends . map ( processType ) . sort ( ) . join ( ', ' ) } ` ;
484
497
}
485
498
exports [ name ] = compInterface ;
486
499
} else if ( item . type === 'function' ) {
@@ -497,10 +510,11 @@ function rebuildInterfaces(json) {
497
510
} ) ;
498
511
let returnVal = processType ( item . return ) ;
499
512
let name = item . name ?? key ;
500
- if ( item . typeParameters . length > 0 ) {
501
- name = name + `<${ item . typeParameters . map ( processType ) . sort ( ) . join ( ', ' ) } >` ;
513
+ funcInterface [ 'returnVal' ] = returnVal ;
514
+ if ( item . typeParameters ?. length > 0 ) {
515
+ funcInterface [ 'typeParameters' ] = `<${ item . typeParameters . map ( processType ) . sort ( ) . join ( ', ' ) } >` ;
502
516
}
503
- exports [ name ] = { ... funcInterface , returnVal } ;
517
+ exports [ name ] = funcInterface ;
504
518
} else if ( item . type === 'interface' ) {
505
519
let funcInterface = { } ;
506
520
Object . entries ( item . properties ) . sort ( ( ( [ keyA ] , [ keyB ] ) => keyA > keyB ? 1 : - 1 ) ) . forEach ( ( [ , property ] ) => {
@@ -515,8 +529,8 @@ function rebuildInterfaces(json) {
515
529
funcInterface [ name ] = { optional, defaultVal, value} ;
516
530
} ) ;
517
531
let name = item . name ?? key ;
518
- if ( item . typeParameters . length > 0 ) {
519
- name = name + `<${ item . typeParameters . map ( processType ) . sort ( ) . join ( ', ' ) } >` ;
532
+ if ( item . typeParameters ? .length > 0 ) {
533
+ funcInterface [ 'typeParameters' ] = `<${ item . typeParameters . map ( processType ) . sort ( ) . join ( ', ' ) } >` ;
520
534
}
521
535
exports [ name ] = funcInterface ;
522
536
} else if ( item . type === 'link' ) {
@@ -532,7 +546,8 @@ function rebuildInterfaces(json) {
532
546
exports [ name ] = { isType, optional, defaultVal, value} ;
533
547
}
534
548
} else {
535
- console . log ( 'unknown top level export' , item ) ;
549
+ exports [ key ] = 'UNTYPED' ;
550
+ // console.log('unknown top level export', key, item);
536
551
}
537
552
} ) ;
538
553
return exports ;
@@ -544,10 +559,24 @@ function formatProp([name, prop]) {
544
559
545
560
function formatInterfaces ( interfaces , allInterfaces ) {
546
561
return allInterfaces . map ( name => {
547
- if ( interfaces [ name ] ) {
548
- let output = `${ name } {\n` ;
549
- output += interfaces [ name ] . isType ? formatProp ( name , interfaces [ name ] ) : Object . entries ( interfaces [ name ] ) . map ( formatProp ) . join ( '\n' ) ;
562
+ let interfaceO = interfaces [ name ] ;
563
+ if ( interfaceO && interfaceO !== 'UNTYPED' ) {
564
+ let output = `${ name } ` ;
565
+ if ( interfaceO . typeParameters ) {
566
+ output += ` ${ interfaceO . typeParameters } ` ;
567
+ delete interfaceO . typeParameters ;
568
+ }
569
+ if ( interfaceO . extend ) {
570
+ output += ` ${ interfaceO . extend } ` ;
571
+ delete interfaceO . extend ;
572
+ }
573
+ // include extra newline so that the names of the interface are always compared
574
+ output += ' {\n\n' ;
575
+ output += interfaces [ name ] . isType ? formatProp ( name , interfaceO ) : Object . entries ( interfaceO ) . map ( formatProp ) . join ( '\n' ) ;
550
576
return `${ output } \n}\n` ;
577
+ } else if ( interfaceO === 'UNTYPED' ) {
578
+ // include extra newline so that the names of the interface are always compared
579
+ return `${ name } {\n\n UNTYPED\n}\n` ;
551
580
} else {
552
581
return '\n' ;
553
582
}
0 commit comments