From b493ff28fa2e931c004e4229ee89574b5eede017 Mon Sep 17 00:00:00 2001 From: Leo McArdle Date: Tue, 30 Jul 2024 11:48:06 +0100 Subject: [PATCH] fix(baseline): hide when feature status differs from BCD key status (#11547) https://mozilla-hub.atlassian.net/browse/MP-874 --- build/index.ts | 50 +------------------------------------------ build/web-features.ts | 37 +++++++++++++++++++++++++------- package.json | 1 + yarn.lock | 31 +++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/build/index.ts b/build/index.ts index 4942aae71dfb..34946c41cc07 100644 --- a/build/index.ts +++ b/build/index.ts @@ -43,7 +43,7 @@ import { postProcessExternalLinks, postProcessSmallerHeadingIDs, } from "./utils.js"; -import { getWebFeatureStatus } from "./web-features.js"; +import { addBaseline } from "./web-features.js"; export { default as SearchIndex } from "./search-index.js"; export { gather as gatherGitHistory } from "./git-history.js"; export { buildSPAs } from "./spas.js"; @@ -550,54 +550,6 @@ export async function buildDocument( return { doc: doc as Doc, liveSamples, fileAttachmentMap, plainHTML }; } -function addBaseline(doc: Partial) { - if (doc.browserCompat && !doc.mdn_url?.includes("/docs/MDN/")) { - const filteredBrowserCompat = doc.browserCompat.filter( - (query) => - // temporary blocklist while we wait for per-key baseline statuses - // or another solution to the baseline/bcd table discrepancy problem - ![ - // https://github.com/web-platform-dx/web-features/blob/cf718ad/feature-group-definitions/async-clipboard.yml - "api.Clipboard.read", - "api.Clipboard.readText", - "api.Clipboard.write", - "api.Clipboard.writeText", - "api.ClipboardEvent", - "api.ClipboardEvent.ClipboardEvent", - "api.ClipboardEvent.clipboardData", - "api.ClipboardItem", - "api.ClipboardItem.ClipboardItem", - "api.ClipboardItem.getType", - "api.ClipboardItem.presentationStyle", - "api.ClipboardItem.types", - "api.Navigator.clipboard", - "api.Permissions.permission_clipboard-read", - // https://github.com/web-platform-dx/web-features/blob/cf718ad/feature-group-definitions/custom-elements.yml - "api.CustomElementRegistry", - "api.CustomElementRegistry.builtin_element_support", - "api.CustomElementRegistry.define", - "api.Window.customElements", - "css.selectors.defined", - "css.selectors.host", - "css.selectors.host-context", - "css.selectors.part", - // https://github.com/web-platform-dx/web-features/blob/cf718ad/feature-group-definitions/input-event.yml - "api.Element.input_event", - "api.InputEvent.InputEvent", - "api.InputEvent.data", - "api.InputEvent.dataTransfer", - "api.InputEvent.getTargetRanges", - "api.InputEvent.inputType", - // https://github.com/web-platform-dx/web-features/issues/1038 - // https://github.com/web-platform-dx/web-features/blob/64d2cfd/features/screen-orientation-lock.dist.yml - "api.ScreenOrientation.lock", - "api.ScreenOrientation.unlock", - ].includes(query) - ); - return getWebFeatureStatus(...filteredBrowserCompat); - } -} - interface BuiltLiveSamplePage { id: string; html: string | null; diff --git a/build/web-features.ts b/build/web-features.ts index c9fca37f3735..286e1c25a827 100644 --- a/build/web-features.ts +++ b/build/web-features.ts @@ -1,16 +1,37 @@ import { features } from "web-features"; +import { computeBaseline } from "compute-baseline"; -export function getWebFeatureStatus(...bcdKeys: string[]) { - if (bcdKeys.length === 0) { - return; +import type { Doc } from "../libs/types/document.js"; + +export function addBaseline(doc: Partial) { + if ( + doc.browserCompat && + doc.browserCompat.length == 1 && + !doc.mdn_url?.includes("/docs/MDN/") + ) { + const bcdKey = doc.browserCompat[0]; + const { featureStatus, keyStatus } = getStatuses(bcdKey); + + if (!featureStatus) { + return; + } + + if (featureStatus.baseline !== keyStatus.baseline) { + return; + } + + return featureStatus; } +} +function getStatuses(bcdKey: string) { for (const feature of Object.values(features)) { - if ( - feature.status && - feature.compat_features?.some((feature) => bcdKeys.includes(feature)) - ) { - return feature.status; + if (feature.status && feature.compat_features?.includes(bcdKey)) { + return { + featureStatus: feature.status, + keyStatus: computeBaseline({ compatKeys: [bcdKey] }), + }; } } + return {}; } diff --git a/package.json b/package.json index 248f8bc2c7bf..52242fb7aeac 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "cli-progress": "^3.12.0", "codemirror": "^6.0.1", "compression": "^1.7.4", + "compute-baseline": "^0.1.1", "cookie": "^0.6.0", "cookie-parser": "^1.4.6", "css-tree": "^2.3.1", diff --git a/yarn.lock b/yarn.lock index 5b2ca26ebfc2..23e01988db96 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2443,6 +2443,14 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" +"@js-temporal/polyfill@^0.4.4": + version "0.4.4" + resolved "https://registry.yarnpkg.com/@js-temporal/polyfill/-/polyfill-0.4.4.tgz#4c26b4a1a68c19155808363f520204712cfc2558" + integrity sha512-2X6bvghJ/JAoZO52lbgyAPFj8uCflhTo2g7nkFzEQdXd/D8rEeD4HtmTEpmtGCva260fcd66YNXBOYdnmHqSOg== + dependencies: + jsbi "^4.3.0" + tslib "^2.4.1" + "@leichtgewicht/ip-codec@^2.0.1": version "2.0.4" resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b" @@ -5507,6 +5515,11 @@ common-path-prefix@^3.0.0: resolved "https://registry.yarnpkg.com/common-path-prefix/-/common-path-prefix-3.0.0.tgz#7d007a7e07c58c4b4d5f433131a19141b29f11e0" integrity sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w== +compare-versions@^6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-6.1.0.tgz#3f2131e3ae93577df111dba133e6db876ffe127a" + integrity sha512-LNZQXhqUvqUTotpZ00qLSaify3b4VFD588aRr8MKFw4CMUr98ytzCW5wDH5qx/DEY5kCDXcbcRuCqL0szEf2tg== + compressible@~2.0.16: version "2.0.18" resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba" @@ -5527,6 +5540,14 @@ compression@^1.7.4: safe-buffer "5.1.2" vary "~1.1.2" +compute-baseline@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/compute-baseline/-/compute-baseline-0.1.1.tgz#26139c562a6609825dfde30ad9f5707619975216" + integrity sha512-1JWSHeDUwlWBnhnCUDEgKSgXb3UWtCkV8FPTV6YwNGHxLqA/SNfOcTsY74IXv19EqbuMsKBClhh+OPNjMnOZDQ== + dependencies: + "@js-temporal/polyfill" "^0.4.4" + compare-versions "^6.1.0" + compute-scroll-into-view@^2.0.4: version "2.0.4" resolved "https://registry.yarnpkg.com/compute-scroll-into-view/-/compute-scroll-into-view-2.0.4.tgz#2b444b2b9e4724819d2531efacb7ac094155fdf6" @@ -10169,6 +10190,11 @@ js-yaml@^4.1.0: dependencies: argparse "^2.0.1" +jsbi@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/jsbi/-/jsbi-4.3.0.tgz#b54ee074fb6fcbc00619559305c8f7e912b04741" + integrity sha512-SnZNcinB4RIcnEyZqFPdGPVgrg2AcnykiBy0sHVJQKHYeaLUvi3Exj+iaPpLnFVkDPZIV4U0yvgC9/R4uEAZ9g== + jsdom@^20.0.0: version "20.0.3" resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-20.0.3.tgz#886a41ba1d4726f67a8858028c99489fed6ad4db" @@ -15331,6 +15357,11 @@ tslib@^2.0.0, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.3.1, tslib@^2.6 resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae" integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q== +tslib@^2.4.1: + version "2.6.3" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0" + integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ== + tsutils@^3.21.0: version "3.21.0" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"