From 0078ac08dd3fb78898b75dd8e774ab0e157b1603 Mon Sep 17 00:00:00 2001 From: Florian Scholz Date: Fri, 24 Jan 2025 11:52:41 +0100 Subject: [PATCH] Order tagged features properly and not with fix linter (#25761) --- package.json | 2 +- scripts/tag-web-features.ts | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 464a66937eb6d9..5c2117293d397e 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,6 @@ "traverse": "tsx scripts/traverse.ts", "update-browser-releases": "tsx scripts/update-browser-releases/index.ts", "bcd": "tsx scripts/bulk-editor/index.ts", - "tag-web-features": "tsx scripts/tag-web-features.ts && npm run fix" + "tag-web-features": "tsx scripts/tag-web-features.ts" } } diff --git a/scripts/tag-web-features.ts b/scripts/tag-web-features.ts index 2e1aa93260c200..05985a0b2ab9e3 100644 --- a/scripts/tag-web-features.ts +++ b/scripts/tag-web-features.ts @@ -9,6 +9,8 @@ import esMain from 'es-main'; import { fdir } from 'fdir'; import { features } from 'web-features'; +import stringifyAndOrderProperties from '../scripts/lib/stringify-and-order-properties.js'; + const dirname = fileURLToPath(new URL('.', import.meta.url)); // Map from api.CoolThing.something to cool-thing @@ -29,6 +31,9 @@ for (const [feature, { compat_features }] of Object.entries(features)) { // FixMe: The idea of scripts/bulk-editor is to have utilities for bulk updating BCD files programmatically. It also features an implementation to update tags which is not used here as the bulk-editor scripts aren't used and/or maintained properly at the moment. +/** + * Add web-feature tags to BCD keys + */ const main = async () => { const bcdJsons = new fdir() .withBasePath() @@ -42,6 +47,12 @@ const main = async () => { .crawl(path.resolve(dirname, '..')) .sync(); + /** + * Lookup data at a specified key + * @param root JSON object + * @param key BCD key + * @returns BCD data at the specified key + */ const lookup = (root, key) => { const parts = key.split('.'); let node = root; @@ -99,8 +110,9 @@ const main = async () => { updated = true; } if (updated) { - const src = JSON.stringify(data, null, ' ') + '\n'; - await fs.writeFile(fp, src, { encoding: 'utf-8' }); + await fs.writeFile(fp, stringifyAndOrderProperties(data) + '\n', { + encoding: 'utf-8', + }); } }