forked from mdn/browser-compat-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.ts
More file actions
56 lines (46 loc) · 1.51 KB
/
status.ts
File metadata and controls
56 lines (46 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */
import fs from 'node:fs';
import { Identifier } from '../../types/types.js';
import { checkExperimental } from '../../test/linter/test-status.js';
import { IS_WINDOWS } from '../../test/utils.js';
/**
* Fix the status values
*
* @param {value} key The key of the object
* @param {Identifier} value The value to update
* @returns {Identifier} The updated value
*/
const fixStatus = (key: string, value: Identifier): Identifier => {
const compat = value?.__compat;
if (compat?.status) {
if (compat.status.experimental && compat.status.deprecated) {
compat.status.experimental = false;
}
if (compat.spec_url && compat.status.standard_track === false) {
compat.status.standard_track = true;
}
if (!checkExperimental(compat)) {
compat.status.experimental = false;
}
}
return value;
};
/**
* Fix feature statuses throughout the BCD files
*
* @param {string} filename The name of the file to fix
*/
const fixStatusFromFile = (filename: string): void => {
let actual = fs.readFileSync(filename, 'utf-8').trim();
let expected = JSON.stringify(JSON.parse(actual, fixStatus), null, 2);
if (IS_WINDOWS) {
// prevent false positives from git.core.autocrlf on Windows
actual = actual.replace(/\r/g, '');
expected = expected.replace(/\r/g, '');
}
if (actual !== expected) {
fs.writeFileSync(filename, expected + '\n', 'utf-8');
}
};
export default fixStatusFromFile;