Skip to content

Commit d8a54c8

Browse files
committed
test(types): correctly error / print stale entries that are resolved
noticed that despite ListenSource being a fresh implementation that fixed a gap between firebase-js-sdk and react-native-firebase that yarn compare:types was still green it should have failed and notified us that we had stale entries to clean up, now it will
1 parent d7992ea commit d8a54c8

3 files changed

Lines changed: 79 additions & 37 deletions

File tree

.github/scripts/compare-types/packages/firestore/config.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ const config: PackageConfig = {
140140
'Type used with setIndexConfiguration. Not implemented in RN Firebase ' +
141141
'as setIndexConfiguration is not supported.',
142142
},
143-
{
144-
name: 'ListenSource',
145-
reason:
146-
'Union type for snapshot listener source (default, server, cache). ' +
147-
'Not yet implemented in RN Firebase; listeners always use default behaviour.',
148-
},
149143
{
150144
name: 'MemoryCacheSettings',
151145
reason:
@@ -320,12 +314,6 @@ const config: PackageConfig = {
320314
'firebase-js-sdk public type. These are structural artifacts of the ' +
321315
'RN implementation.',
322316
},
323-
{
324-
name: 'SnapshotListenOptions',
325-
reason:
326-
'The firebase-js-sdk includes an optional `source` property (of type ' +
327-
'`ListenSource`) which is not yet supported in RN Firebase.',
328-
},
329317
// --- Wrapper classes (same public API, different structure: getters vs properties, readonly, toJSON/fromJSON) ---
330318
{
331319
name: 'DocumentReference',

.github/scripts/compare-types/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*
1010
* Exit codes:
1111
* 0 — all differences are documented in the package config files
12-
* 1 — undocumented differences found (or a required file is missing)
12+
* 1 — undocumented differences, stale registry entries in config (resolved
13+
* APIs still listed as missing/extra/different), or a required file missing
1314
*/
1415

1516
import fs from 'fs';

.github/scripts/compare-types/src/report.ts

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,71 @@ function printSection(
4848
}
4949
}
5050

51+
// ---------------------------------------------------------------------------
52+
// Stale registry (documented differences that no longer apply)
53+
// ---------------------------------------------------------------------------
54+
55+
function countStale(result: ComparisonResult): number {
56+
return (
57+
result.staleConfigMissing.length +
58+
result.staleConfigExtra.length +
59+
result.staleConfigDifferentShape.length
60+
);
61+
}
62+
63+
/**
64+
* Prints stale `config.ts` entries and returns how many were printed.
65+
* These must run even when there are zero live diffs, otherwise a resolved
66+
* API (e.g. an export removed from `missingInRN` in reality) would never
67+
* force updating the comparison registry.
68+
*/
69+
function printStaleRegistrySection(result: ComparisonResult): number {
70+
const totalStale = countStale(result);
71+
if (totalStale === 0) {
72+
return 0;
73+
}
74+
75+
console.log(`\n ${c(RED, `Stale registry / config entries`)} (${totalStale}):`);
76+
77+
for (const name of result.staleConfigMissing) {
78+
console.log(
79+
`${c(RED, ' ✗')} ${c(BOLD, name)}${c(RED, ' [STALE missingInRN]')}${c(
80+
DIM,
81+
` — ${name} exists in React Native Firebase but is still listed under missingInRN in config.ts; remove it or reclassify (e.g. differentShape) if types still differ.`,
82+
)}`,
83+
);
84+
}
85+
86+
for (const name of result.staleConfigExtra) {
87+
console.log(
88+
`${c(RED, ' ✗')} ${c(BOLD, name)}${c(RED, ' [STALE extraInRN]')}${c(
89+
DIM,
90+
` — ${name} is no longer an extra export in React Native Firebase but is still listed under extraInRN; remove from config.ts.`,
91+
)}`,
92+
);
93+
}
94+
95+
for (const name of result.staleConfigDifferentShape) {
96+
console.log(
97+
`${c(RED, ' ✗')} ${c(BOLD, name)}${c(RED, ' [STALE differentShape]')}${c(
98+
DIM,
99+
` — ${name} now matches the firebase-js-sdk shape; remove from differentShape in config.ts.`,
100+
)}`,
101+
);
102+
}
103+
104+
return totalStale;
105+
}
106+
51107
// ---------------------------------------------------------------------------
52108
// Public API
53109
// ---------------------------------------------------------------------------
54110

55111
/**
56112
* Print a human-readable report to stdout.
57113
*
58-
* @returns `true` if there are any undocumented differences (CI failure).
114+
* @returns `true` if there are undocumented differences or stale registry
115+
* entries (CI failure).
59116
*/
60117
export function printReport(results: ComparisonResult[]): boolean {
61118
console.log(
@@ -72,11 +129,22 @@ export function printReport(results: ComparisonResult[]): boolean {
72129
result.extra.length +
73130
result.differentShape.length;
74131

75-
if (totalDiffs === 0) {
132+
const totalStale = countStale(result);
133+
134+
if (totalDiffs === 0 && totalStale === 0) {
76135
console.log(c(GREEN, ' ✓ No differences found'));
77136
continue;
78137
}
79138

139+
if (totalDiffs === 0 && totalStale > 0) {
140+
console.log(
141+
c(
142+
GREEN,
143+
' ✓ Exported types match the firebase-js-sdk snapshot (no live diffs)',
144+
),
145+
);
146+
}
147+
80148
// --- Missing ---
81149
if (result.missing.length > 0) {
82150
printSection(
@@ -117,42 +185,27 @@ export function printReport(results: ComparisonResult[]): boolean {
117185
);
118186
}
119187

120-
// --- Stale config entries ---
121-
const totalStale =
122-
result.staleConfigMissing.length +
123-
result.staleConfigExtra.length +
124-
result.staleConfigDifferentShape.length;
125-
126-
if (totalStale > 0) {
127-
const staleNames = [
128-
...result.staleConfigMissing,
129-
...result.staleConfigExtra,
130-
...result.staleConfigDifferentShape,
131-
];
132-
console.log(`\n ${c(RED, `Stale config entries`)} (${totalStale}):`);
133-
for (const name of staleNames) {
134-
console.log(
135-
`${c(RED, ' ✗')} ${c(BOLD, name)}${c(RED, ' [STALE]')}${c(DIM, ' — now matches the firebase-js-sdk; remove from config.ts')}`,
136-
);
137-
}
138-
}
188+
const printedStale = printStaleRegistrySection(result);
139189

140190
// --- Summary ---
141191
const totalUndoc =
142192
result.undocumentedMissing.length +
143193
result.undocumentedExtra.length +
144194
result.undocumentedDifferentShape.length;
145195

146-
if (totalUndoc > 0 || totalStale > 0) {
196+
if (totalUndoc > 0 || printedStale > 0) {
147197
hasFailures = true;
148198
if (totalUndoc > 0) {
149199
console.log(
150200
`\n ${c(RED, `✗ ${totalUndoc} undocumented difference(s) — add them to config.ts with a reason`)}`,
151201
);
152202
}
153-
if (totalStale > 0) {
203+
if (printedStale > 0) {
154204
console.log(
155-
`\n ${c(RED, `✗ ${totalStale} stale config entry/entries — remove them from config.ts`)}`,
205+
`\n ${c(
206+
RED,
207+
`✗ ${printedStale} stale registry entry/entries — update packages/<name>/config.ts for the type comparison tool`,
208+
)}`,
156209
);
157210
}
158211
} else {

0 commit comments

Comments
 (0)