Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions scripts/caniuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ const mapping = new Map<string, string | null>(
Object.keys(lite.features).sort().map(id => [id, null])
);

// Fix missing key-value in @types/caniuse-lite
// TODO: remove this declaration when https://github.com/DefinitelyTyped/DefinitelyTyped/pull/67330 lands
declare module 'caniuse-lite' {
interface Feature {
shown: boolean;
}
}

const hiddenCaniuseItems = new Set<string>();
for (const [id, data] of Object.entries(lite.features)) {
if (!lite.feature(data).shown) {
hiddenCaniuseItems.add(id);
}
}

for (const [id, data] of Object.entries(features)) {
if (!('caniuse' in data)) {
continue;
Expand All @@ -28,22 +43,34 @@ for (const [id, data] of Object.entries(features)) {
if (!mapping.has(caniuseId)) {
throw new Error(`Invalid caniuse ID used for ${id}: ${caniuseId}`);
}
if (hiddenCaniuseItems.has(caniuseId)) {
throw new Error(`The caniuse ID used for "${id}" ("${caniuseId}") is hidden on caniuse.com`);
}

mapping.set(caniuseId, id);
}

let matched = 0;

for (const [caniuseId, id] of mapping.entries()) {
let checkbox = '[ ]';
let details = '';
if (id) {
checkbox = '[x]';
if (id !== caniuseId) {
details = ` (as ${id})`;
}
const isHidden = hiddenCaniuseItems.has(caniuseId);
const isComplete = id || isHidden;

if (isComplete) {
matched++;
}
logger.verbose(`- ${checkbox} ${caniuseId}${details}`);

const checkbox = isComplete ? "[x]" : "[ ]";
let details = '';
if (id && id !== caniuseId) {
details = ` (as ${id})`;
}
if (isHidden) {
details = " (hidden on caniuse.com 🤫)";
}

const strike = isHidden ? "~~" : "";
logger.verbose(`- ${checkbox} ${strike}${caniuseId}${strike}${details}`);
}

logger.verbose("");
Expand Down