From a6e88f864837c64cd0f98f900c78524a7738c77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20J=C3=A4genstedt?= Date: Mon, 3 Jun 2024 17:02:49 +0200 Subject: [PATCH] Ensure that BCD keys are only used once (#1174) This prevents a problem like in https://github.com/web-platform-dx/web-features/issues/1164 from happening before we have a way to handle it. --- index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.ts b/index.ts index 70dc5d96e2..984378ecec 100644 --- a/index.ts +++ b/index.ts @@ -110,6 +110,9 @@ function convertMarkdown(markdown: string) { return { text, html }; } +// Map from BCD keys/paths to web-features identifiers. +const bcdToFeatureId: Map = new Map(); + const features: { [key: string]: FeatureData } = {}; for (const [key, data] of yamlEntries('features')) { // Draft features reserve an identifier but aren't complete yet. Skip them. @@ -155,6 +158,19 @@ for (const [key, data] of yamlEntries('features')) { } } + // Check that no BCD key is used twice until the meaning is made clear in + // https://github.com/web-platform-dx/web-features/issues/1173. + if (data.compat_features) { + for (const bcdKey of data.compat_features) { + const otherKey = bcdToFeatureId.get(bcdKey); + if (otherKey) { + throw new Error(`BCD key ${bcdKey} is used in both ${otherKey} and ${key}, which creates ambiguity for some consumers. Please see https://github.com/web-platform-dx/web-features/issues/1173 and help us find a good solution to allow this.`); + } else { + bcdToFeatureId.set(bcdKey, key); + } + } + } + features[key] = scrub(data); }