diff --git a/build/web-features.ts b/build/web-features.ts index 2d07c244e679..c9fca37f3735 100644 --- a/build/web-features.ts +++ b/build/web-features.ts @@ -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; } diff --git a/client/src/document/baseline-indicator.tsx b/client/src/document/baseline-indicator.tsx index a2445868ff96..f217846188ad 100644 --- a/client/src/document/baseline-indicator.tsx +++ b/client/src/document/baseline-indicator.tsx @@ -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: { @@ -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 diff --git a/libs/types/document.ts b/libs/types/document.ts index 33bdb7a21114..8a8990dfb106 100644 --- a/libs/types/document.ts +++ b/libs/types/document.ts @@ -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; diff --git a/libs/types/web-features.ts b/libs/types/web-features.ts deleted file mode 100644 index 40802af5820f..000000000000 --- a/libs/types/web-features.ts +++ /dev/null @@ -1,53 +0,0 @@ -export type Features = { [key: string]: FeatureData }; - -// Types below copied from web-platform-dx/web-features GitHub repo: -// https://github.com/web-platform-dx/web-features/blob/5ad19b0dec722eaf6484b7d569e62e64ad7bfef0/index.ts#L8-L44 - -export interface FeatureData { - /** Alias identifier */ - alias?: string | [string, string, ...string[]]; - /** Specification */ - spec: - | specification_url - | [specification_url, specification_url, ...specification_url[]]; - /** caniuse.com identifier */ - caniuse?: string | [string, string, ...string[]]; - /** Whether a feature is considered a "baseline" web platform feature and when it achieved that status */ - status?: SupportStatus; - /** Sources of support data for this feature */ - compat_features?: string[]; - /** Usage stats */ - usage_stats?: - | usage_stats_url - | [usage_stats_url, usage_stats_url, ...usage_stats_url[]]; // A single URL or an array of two or more -} - -export type browserIdentifier = - | "chrome" - | "chrome_android" - | "edge" - | "firefox" - | "firefox_android" - | "safari" - | "safari_ios"; - -type BaselineHighLow = "high" | "low"; - -export interface SupportStatus { - /** Whether the feature is Baseline (low substatus), Baseline (high substatus), or not (false) */ - baseline?: BaselineHighLow | false; - /** Date the feature achieved Baseline low status */ - baseline_low_date?: string; - /** Browser versions that most-recently introduced the feature */ - support?: { [K in browserIdentifier]?: string }; -} - -/** Specification URL - * @format uri - */ -type specification_url = string; - -/** Usage stats URL - * @format uri - */ -type usage_stats_url = string; diff --git a/package.json b/package.json index 5b2cdc522ec3..8ed3ba859619 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tsconfig.json b/tsconfig.json index 1e145d71f752..b04b539ef81b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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, diff --git a/type-fixes/web-features.ts b/type-fixes/web-features.ts deleted file mode 100644 index 393ea95e32bb..000000000000 --- a/type-fixes/web-features.ts +++ /dev/null @@ -1,5 +0,0 @@ -import features from "../node_modules/web-features/index.js"; - -import type { Features } from "../libs/types/web-features.js"; - -export default features as Features; diff --git a/yarn.lock b/yarn.lock index 4184110fd51d..f20d05d07b3f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"