Skip to content

Commit

Permalink
Ensure that BCD keys are only used once (#1174)
Browse files Browse the repository at this point in the history
This prevents a problem like in #1164
from happening before we have a way to handle it.
  • Loading branch information
foolip committed Jun 3, 2024
1 parent 5dc4b4a commit a6e88f8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ function convertMarkdown(markdown: string) {
return { text, html };
}

// Map from BCD keys/paths to web-features identifiers.
const bcdToFeatureId: Map<string, string> = 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.
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit a6e88f8

Please # to comment.