Skip to content

Commit

Permalink
fix(baseline): hide when feature status differs from BCD key status (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA authored Jul 30, 2024
1 parent 3ca992d commit b493ff2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 57 deletions.
50 changes: 1 addition & 49 deletions build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -550,54 +550,6 @@ export async function buildDocument(
return { doc: doc as Doc, liveSamples, fileAttachmentMap, plainHTML };
}

function addBaseline(doc: Partial<Doc>) {
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;
Expand Down
37 changes: 29 additions & 8 deletions build/web-features.ts
Original file line number Diff line number Diff line change
@@ -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<Doc>) {
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 {};
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b493ff2

Please sign in to comment.