Skip to content

Commit

Permalink
fix(baseline): support ranged dates, use upstream types (#11536)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA authored Jul 25, 2024
1 parent 8914a11 commit 2782f97
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 77 deletions.
10 changes: 5 additions & 5 deletions build/web-features.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import webFeatures from "web-features";
import { features } from "web-features";

export function getWebFeatureStatus(...features: string[]) {
if (features.length === 0) {
export function getWebFeatureStatus(...bcdKeys: string[]) {
if (bcdKeys.length === 0) {
return;
}

for (const feature of Object.values(webFeatures)) {
for (const feature of Object.values(features)) {
if (
feature.status &&
feature.compat_features?.some((feature) => features.includes(feature))
feature.compat_features?.some((feature) => bcdKeys.includes(feature))
) {
return feature.status;
}
Expand Down
15 changes: 9 additions & 6 deletions client/src/document/baseline-indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { useLocation } from "react-router";

import "./baseline-indicator.scss";

import type {
SupportStatus,
browserIdentifier,
} from "../../../libs/types/web-features";
// web-features doesn't export these types directly so we need to do a little typescript magic:
import type { features } from "web-features";
type SupportStatus = (typeof features)[keyof typeof features]["status"];
type BrowserIdentifier =
keyof (typeof features)[keyof typeof features]["status"]["support"];

interface BrowserGroup {
name: string;
ids: browserIdentifier[];
ids: BrowserIdentifier[];
}

const ENGINES: {
Expand Down Expand Up @@ -62,9 +63,11 @@ export function BaselineIndicator({ status }: { status: SupportStatus }) {
LOCALIZED_BCD_IDS[locale] || LOCALIZED_BCD_IDS[DEFAULT_LOCALE]
}`;

const low_date_range = status.baseline_low_date?.match(/^([^0-9])/)?.[0];
const low_date = status.baseline_low_date
? new Date(status.baseline_low_date)
? new Date(status.baseline_low_date.slice(low_date_range ? 1 : 0))
: undefined;

const level = status.baseline
? status.baseline
: status.baseline === false
Expand Down
5 changes: 4 additions & 1 deletion libs/types/document.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type Locale } from "./core.js";
import type { SupportStatus } from "./web-features.js";

// web-features doesn't export this type directly so we need to do a little typescript magic:
import type { features } from "web-features";
type SupportStatus = (typeof features)[keyof typeof features]["status"];

export interface Source {
folder: string;
Expand Down
53 changes: 0 additions & 53 deletions libs/types/web-features.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"unified": "^11.0.5",
"unist-builder": "^4.0.0",
"unist-util-visit": "^5.0.0",
"web-features": "^0.9.0",
"web-features": "^1.0.0",
"web-specs": "^3.13.1"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"front-matter": ["./type-fixes/front-matter.js"],
"@mdn/browser-compat-data/types": [
"./node_modules/@mdn/browser-compat-data/types.d.ts"
],
"web-features": ["./type-fixes/web-features.js"]
]
},
"preserveWatchOutput": true,
"resolveJsonModule": true,
Expand Down
5 changes: 0 additions & 5 deletions type-fixes/web-features.ts

This file was deleted.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15824,10 +15824,10 @@ wbuf@^1.1.0, wbuf@^1.7.3:
dependencies:
minimalistic-assert "^1.0.0"

web-features@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/web-features/-/web-features-0.9.0.tgz#f46748e1cffe50e03a3331e44fcd85844cbc47d5"
integrity sha512-Y1SZbw8yt762LBfdDgD0Qe2XHpsmjcKnUKNi5HH/Y/uqJYST06ua+VFatwxvS/NIBPPuRwI0KbJl0VG606jNpg==
web-features@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/web-features/-/web-features-1.0.0.tgz#c40f74bd38a09ef9ba7b7769521a336686b5811b"
integrity sha512-U/ppX0h851Fr8LbOVMybiuH3iGWGlPi+DYXoj6VkOvXJc6VgYpSdGDosduYl/4qvW6YNlZ4IaczLgqHqbaU25A==

web-namespaces@^2.0.0:
version "2.0.1"
Expand Down

0 comments on commit 2782f97

Please sign in to comment.