diff --git a/build/document-extractor.ts b/build/document-extractor.ts index e19377597bcd..1b1249b9f365 100644 --- a/build/document-extractor.ts +++ b/build/document-extractor.ts @@ -14,6 +14,7 @@ import web from "../kumascript/src/api/web"; interface SimpleSupportStatementWithReleaseDate extends bcd.SimpleSupportStatement { release_date?: string; + version_last?: bcd.VersionValue; } type SectionsAndFlaws = [Section[], string[]]; @@ -464,16 +465,17 @@ function _addSingleSpecialSection( : [originalInfo]; for (const infoEntry of infos) { - const added = - typeof infoEntry.version_added === "string" && - infoEntry.version_added.startsWith("≤") - ? infoEntry.version_added.slice(1) - : infoEntry.version_added; + const added = _normalizeVersion(infoEntry.version_added); + const removed = _normalizeVersion(infoEntry.version_removed); if (browserReleaseData.has(browser)) { if (browserReleaseData.get(browser).has(added)) { infoEntry.release_date = browserReleaseData .get(browser) .get(added).release_date; + infoEntry.version_last = _getPreviousVersion( + removed, + browsers[browser] + ); } } } @@ -506,6 +508,29 @@ function _addSingleSpecialSection( ]; } + function _getPreviousVersion( + version: bcd.VersionValue, + browser: bcd.BrowserStatement + ): bcd.VersionValue { + if (browser && typeof version === "string") { + const browserVersions = Object.keys(browser["releases"]).sort( + _compareVersions + ); + const currentVersionIndex = browserVersions.indexOf(version); + if (currentVersionIndex > 0) { + return browserVersions[currentVersionIndex - 1]; + } + } + + return version; + } + + function _normalizeVersion(version: bcd.VersionValue): bcd.VersionValue { + return typeof version === "string" && version.startsWith("≤") + ? version.slice(1) + : version; + } + function _getFirstVersion(support: bcd.SimpleSupportStatement): string { if (typeof support.version_added === "string") { return support.version_added; diff --git a/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx b/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx index 8235a6a5abf2..e7e74eb2c413 100644 --- a/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx +++ b/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx @@ -4,7 +4,6 @@ import { BrowserInfoContext } from "./browser-info"; import { asList, getCurrentSupport, - getPreviousVersion, hasMore, hasNoteworthyNotes, isFullySupportedWithoutLimitation, @@ -136,10 +135,7 @@ const CellText = React.memo( const currentSupport = getCurrentSupport(support); const added = currentSupport?.version_added ?? null; - const removed = getPreviousVersion( - currentSupport?.version_removed ?? null, - browser - ); + const lastVersion = currentSupport?.version_last ?? null; const browserReleaseDate = getSupportBrowserReleaseDate(support); const supportClassName = getSupportClassName(support, browser); @@ -155,7 +151,7 @@ const CellText = React.memo( status = { isSupported: "unknown" }; break; case true: - status = { isSupported: removed ? "no" : "yes" }; + status = { isSupported: lastVersion ? "no" : "yes" }; break; case false: status = { isSupported: "no" }; @@ -166,7 +162,7 @@ const CellText = React.memo( default: status = { isSupported: supportClassName, - label: versionLabelFromSupport(added, removed, browser), + label: versionLabelFromSupport(added, lastVersion, browser), }; break; } diff --git a/client/src/document/ingredients/browser-compatibility-table/utils.ts b/client/src/document/ingredients/browser-compatibility-table/utils.ts index 5813b20ebc74..6b20a7060e19 100644 --- a/client/src/document/ingredients/browser-compatibility-table/utils.ts +++ b/client/src/document/ingredients/browser-compatibility-table/utils.ts @@ -1,5 +1,3 @@ -import { compareVersions } from "compare-versions"; - import type BCD from "@mdn/browser-compat-data/types"; // Extended for the fields, beyond the bcd types, that are extra-added @@ -8,6 +6,9 @@ interface SimpleSupportStatementExtended extends BCD.SimpleSupportStatement { // Known for some support statements where the browser *version* is known, // as opposed to just "true" and if the version release date is known. release_date?: string; + // The version before the version_removed if the *version* removed is known, + // as opposed to just "true". Otherwise the version_removed. + version_last?: BCD.VersionValue; } export type SupportStatementExtended = @@ -193,20 +194,3 @@ export function getCurrentSupport( // Default (likely never reached) return getFirst(support); } - -export function getPreviousVersion( - version: BCD.VersionValue, - browser: BCD.BrowserStatement -): BCD.VersionValue { - if (browser && typeof version === "string") { - const browserVersions = Object.keys(browser["releases"]).sort( - compareVersions - ); - const currentVersionIndex = browserVersions.indexOf(version); - if (currentVersionIndex > 0) { - return browserVersions[currentVersionIndex - 1]; - } - } - - return version; -} diff --git a/package.json b/package.json index 31dafe494e6f..630c53d84eb2 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,6 @@ "chalk": "^4.1.2", "cheerio": "^1.0.0-rc.12", "cli-progress": "^3.11.2", - "compare-versions": "^5.0.1", "compression": "^1.7.4", "cookie": "^0.5.0", "cookie-parser": "^1.4.6", diff --git a/yarn.lock b/yarn.lock index d796c4a08644..aed64bebd164 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3947,11 +3947,6 @@ commondir@^1.0.1: resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" integrity sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg== -compare-versions@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-5.0.1.tgz#14c6008436d994c3787aba38d4087fabe858555e" - integrity sha512-v8Au3l0b+Nwkp4G142JcgJFh1/TUhdxut7wzD1Nq1dyp5oa3tXaqb03EXOAB6jS4gMlalkjAUPZBMiAfKUixHQ== - compressible@~2.0.16: version "2.0.18" resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba"