Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Overhaul code to handle "false" but BCD set to newer version
Browse files Browse the repository at this point in the history
Fixes #15.
  • Loading branch information
queengooborg authored and foolip committed Jan 4, 2023
1 parent 358ecbb commit 2a2f12d
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions update-bcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,38 +462,46 @@ export const update = (
continue;
}

let dataIsOlder = false;
// If we infer no support but BCD currently has a version number, check to make sure
// our data is not older than BCD (ex. BCD says 79 but we have results for 40-78)
if (
inferredStatement.version_added === false &&
typeof simpleStatement.version_added === 'string'
typeof simpleStatement.version_added === 'string' &&
simpleStatement.version_added !== 'preview'
) {
// Make sure not to update BCD if it is set to a version newer than we have in our data
let latestNonNullVersion = '';

for (const [version, result] of Array.from(
versionMap.entries()
).reverse()) {
if (result === null) {
// Ignore null values
continue;
}

if (
result !== null &&
simpleStatement.version_added !== 'preview' &&
compareVersions(
version,
simpleStatement.version_added.replace('≤', ''),
'<='
)
!latestNonNullVersion ||
compareVersions(version, latestNonNullVersion, '>')
) {
// A version we have data for is the same or newer than the version in BCD
dataIsOlder = true;
break;
latestNonNullVersion = version;
}
}

if (
compareVersions(
latestNonNullVersion,
simpleStatement.version_added.replace('≤', ''),
'<'
)
) {
logger.warn(
`${path} skipped for ${browser}; BCD says support was added in a version newer than there are results for`
);
continue;
}
}

if (dataIsOlder) {
logger.warn(
`${path} skipped for ${browser} because results are older than BCD`
);
continue;
} else if (
if (
typeof simpleStatement.version_added === 'string' &&
typeof inferredStatement.version_added === 'string' &&
inferredStatement.version_added.includes('≤')
Expand Down

0 comments on commit 2a2f12d

Please sign in to comment.