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
21 changes: 14 additions & 7 deletions scripts/remove-tagged-compat-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ const argv = yargs(process.argv.slice(2))
"$0 [paths..]",
"Remove `compat_features` from `.yml` files that have an equivalently tagged set of features in @mdn/browser-compat-data",
(yargs) =>
yargs.positional("paths", {
describe: "Directories or files to check/update.",
default: ["features"],
}),
yargs
.positional("paths", {
describe: "Directories or files to check/update.",
default: ["features"],
})
.option("f", {
alias: "force",
type: "boolean",
}),
).argv;

const logger = winston.createLogger({
Expand Down Expand Up @@ -53,7 +58,9 @@ const tagsToFeatures: Map<string, Feature[]> = (() => {
return map;
})();

function cleanup(sourcePath: string): void {
function cleanup(sourcePath: string, options?: { force?: boolean }): void {
options = { ...options };

const source = YAML.parseDocument(
fs.readFileSync(sourcePath, { encoding: "utf-8" }),
);
Expand All @@ -72,7 +79,7 @@ function cleanup(sourcePath: string): void {
if (compat_features) {
const { key: keyData, value: data } = compat_features;
const features = data.items.map((item) => item.value).sort();
if (isDeepStrictEqual(features, taggedCompatFeatures)) {
if (options.force || isDeepStrictEqual(features, taggedCompatFeatures)) {
// Preserve comments around the compat_features key
const comments = keyData.commentBefore ? [keyData.commentBefore] : [];
data.items.reduce((acc, item) => {
Expand Down Expand Up @@ -107,7 +114,7 @@ function main() {
});

for (const sourcePath of filePaths) {
cleanup(sourcePath);
cleanup(sourcePath, { force: argv.force });
}
}

Expand Down