diff --git a/.env.testing b/.env.testing index bc293a0f019b..fb650e118031 100644 --- a/.env.testing +++ b/.env.testing @@ -34,3 +34,5 @@ BUILD_ALWAYS_ALLOW_ROBOTS=true REACT_APP_ENABLE_PLUS=true REACT_APP_FXA_SIGNIN_URL=/users/fxa/login/authenticate/ + +REACT_APP_BCD_BASE_URL = "" 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 d3a9df3ff70b..353f92ae9cc8 100644 --- a/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx +++ b/client/src/document/ingredients/browser-compatibility-table/feature-row.tsx @@ -10,14 +10,13 @@ import { isNotSupportedAtAll, isTruthy, versionIsPreview, - SupportStatementExtended, bugURLToString, } from "./utils"; import { LEGEND_LABELS } from "./legend"; import { DEFAULT_LOCALE } from "../../../../../libs/constants"; function getSupportClassName( - support: SupportStatementExtended | undefined, + support: BCD.SupportStatement | undefined, browser: BCD.BrowserStatement ): "no" | "yes" | "partial" | "preview" | "removed-partial" | "unknown" { if (!support) { @@ -48,12 +47,17 @@ function getSupportClassName( } function getSupportBrowserReleaseDate( - support: SupportStatementExtended | undefined + currentSupport: BCD.SimpleSupportStatement | undefined, + browser: BCD.BrowserStatement ): string | undefined { - if (!support) { + if (!currentSupport) { return undefined; } - return getCurrentSupport(support)!.release_date; + const version = currentSupport.version_added; + if (typeof version !== "string" || version === "preview") { + return undefined; + } + return browser.releases[version].release_date; } function StatusIcons({ status }: { status: BCD.StatusBlock }) { @@ -138,7 +142,10 @@ const CellText = React.memo( const added = currentSupport?.version_added ?? null; const lastVersion = currentSupport?.version_last ?? null; - const browserReleaseDate = getSupportBrowserReleaseDate(support); + const browserReleaseDate = getSupportBrowserReleaseDate( + currentSupport, + browser + ); const supportClassName = getSupportClassName(support, browser); let status: diff --git a/client/src/document/ingredients/browser-compatibility-table/utils.ts b/client/src/document/ingredients/browser-compatibility-table/utils.ts index 6cbd5e773d62..063a0ab16e79 100644 --- a/client/src/document/ingredients/browser-compatibility-table/utils.ts +++ b/client/src/document/ingredients/browser-compatibility-table/utils.ts @@ -1,20 +1,5 @@ import type BCD from "@mdn/browser-compat-data/types"; -// Extended for the fields, beyond the bcd types, that are extra-added -// exclusively in Yari. -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 = - | SimpleSupportStatementExtended - | SimpleSupportStatementExtended[]; - export function getFirst(a: T | T[]): T; export function getFirst(a: T | T[] | undefined): T | undefined { return Array.isArray(a) ? a[0] : a; @@ -160,8 +145,8 @@ function isFullySupportedWithoutMajorLimitation( // Prioritizes support items export function getCurrentSupport( - support: SupportStatementExtended | undefined -): SimpleSupportStatementExtended | undefined { + support: BCD.SupportStatement | undefined +): BCD.SimpleSupportStatement | undefined { if (!support) return undefined; // Full support without limitation diff --git a/package.json b/package.json index 0e5ccef8480d..bd4b6a37520e 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,6 @@ "@codemirror/state": "^6.4.1", "@codemirror/theme-one-dark": "^6.1.2", "@fast-csv/parse": "^5.0.0", - "@mdn/bcd-utils-api": "^0.0.6", "@mdn/browser-compat-data": "^5.5.16", "@mozilla/glean": "4.0.0", "@sentry/integrations": "^7.107.0", diff --git a/scripts/ai-help-macros.ts b/scripts/ai-help-macros.ts index d601a21b2d76..8957f647bbbf 100644 --- a/scripts/ai-help-macros.ts +++ b/scripts/ai-help-macros.ts @@ -10,11 +10,8 @@ import { load as cheerio } from "cheerio"; import { DocMetadata } from "../libs/types/document.js"; import { BUILD_OUT_ROOT, OPENAI_KEY, PG_URI } from "../libs/env/index.js"; -import { - getBCDDataForPath, - SimpleSupportStatementExtended, -} from "@mdn/bcd-utils-api"; import path from "node:path"; +import bcd from "@mdn/browser-compat-data" assert { type: "json" }; import { BrowserStatement, SimpleSupportStatement, @@ -351,19 +348,27 @@ async function* builtDocs(directory: string) { } function buildBCDTable(query: string) { - const bcdData = getBCDDataForPath(query); - if (!bcdData) return ""; - const { browsers, data } = bcdData; + const bcdPathParts = query.split("."); + + let data: any = bcd; + for (const part of bcdPathParts) { + if (!(part in data)) { + return ""; + } + data = data[part]; + } + if (!data) return ""; + return data.__compat?.support ? ` -${Object.entries(data.__compat?.support) +${Object.entries(data.__compat.support) .map( ([browser, support]) => - `` ) .join("\n")} @@ -374,10 +379,13 @@ ${Object.entries(data.__compat?.support) function buildBCDSupportString( browser: BrowserStatement, - support: (SimpleSupportStatement & SimpleSupportStatementExtended)[] + support: SimpleSupportStatement[] ) { return support .flatMap((item) => { + const releaseDate = + typeof item.version_added === "string" && + browser.releases[item.version_added]?.release_date; return [ item.version_removed && !support.some( @@ -405,7 +413,7 @@ function buildBCDSupportString( isFullySupportedWithoutLimitation(item) && !versionIsPreview(item.version_added, browser) ? `Full support since version ${item.version_added}${ - item.release_date ? ` (released ${item.release_date})` : "" + releaseDate ? ` (released ${releaseDate})` : "" }` : isNotSupportedAtAll(item) ? "No support" diff --git a/server/index.ts b/server/index.ts index b2454bcf17cd..a0d6e5585e1a 100644 --- a/server/index.ts +++ b/server/index.ts @@ -9,9 +9,10 @@ import send from "send"; import { createProxyMiddleware } from "http-proxy-middleware"; import cookieParser from "cookie-parser"; import openEditor from "open-editor"; -import { getBCDDataForPath } from "@mdn/bcd-utils-api"; import sanitizeFilename from "sanitize-filename"; +import bcd from "@mdn/browser-compat-data" assert { type: "json" }; + import { buildDocument, buildLiveSamplePageFromURL, @@ -79,8 +80,22 @@ const bcdRouter = express.Router({ caseSensitive: true }); // Note that this route will only get hit if .env has this: REACT_APP_BCD_BASE_URL="" bcdRouter.get("/api/v0/current/:path.json", async (req, res) => { - const data = getBCDDataForPath(req.params.path); - return data ? res.json(data) : res.status(404).send("BCD path not found"); + const bcdPath = req.params.path; + const bcdPathParts = bcdPath.split("."); + + let data = bcd; + + for (const part of bcdPathParts) { + if (part in data) { + data = data[part]; + } else { + res.status(404).send("BCD path not found"); + } + } + + return data + ? res.json({ browsers: bcd.browsers, data, query: bcdPath }) + : res.status(404).send("BCD path not found"); }); bcdRouter.use( diff --git a/yarn.lock b/yarn.lock index 2420f27e8599..ef7982157312 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2276,11 +2276,6 @@ dependencies: call-bind "^1.0.7" -"@mdn/bcd-utils-api@^0.0.6": - version "0.0.6" - resolved "https://registry.yarnpkg.com/@mdn/bcd-utils-api/-/bcd-utils-api-0.0.6.tgz#166fd6c431702af3c84133013f337b028476e7bc" - integrity sha512-aT0tumSuqi8RbD2ownK9f84pygC/m9/NlXh6IAWcSxj4YtFv14ohH95KcVLiLnTFx1reokVagYvC7P9611EU2A== - "@mdn/browser-compat-data@^5.5.16": version "5.5.16" resolved "https://registry.yarnpkg.com/@mdn/browser-compat-data/-/browser-compat-data-5.5.16.tgz#3fe64c7497c56191094f57e159ff50097452be4f"
BrowserSupport
${browsers[browser].name}${buildBCDSupportString( - browsers[browser], - support + `
${bcd.browsers[browser].name}${buildBCDSupportString( + bcd.browsers[browser], + support as SimpleSupportStatement[] )}