-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19081ed
commit f29b844
Showing
7 changed files
with
325 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,84 @@ | ||
import bcd, { Identifier } from "@mdn/browser-compat-data"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const CSS_GLOB = "**/*.{css,scss}"; | ||
const HTML_GLOB = "**/*.html"; | ||
const JS_GLOB = "**/*.{ts,js}"; | ||
|
||
export type CompatIssue = { | ||
deprecated: boolean; | ||
browserIssues: string[]; | ||
mdn_url?: string; | ||
}; | ||
|
||
export function processCompatDataObject( | ||
data: Identifier, | ||
prefix: string = "", | ||
suffix: string = "", | ||
) { | ||
const compatIssues: { [name: string]: CompatIssue } = {}; | ||
for (const prop of Object.keys(data)) { | ||
let hasIssue = false; | ||
if (!data[prop].__compat) { | ||
continue; | ||
} | ||
const { status, support, mdn_url } = data[prop].__compat!; | ||
const itemCompatIssues: CompatIssue = { | ||
deprecated: false, | ||
browserIssues: [], | ||
mdn_url, | ||
}; | ||
if (status?.deprecated) { | ||
itemCompatIssues.deprecated = true; | ||
hasIssue = true; | ||
} else { | ||
for (const [name, data] of Object.entries(support)) { | ||
const isSupported = !Array.isArray(data) | ||
? data.version_added && !data.version_last && !data.flags | ||
: data.some( | ||
(obj) => obj.version_added && !obj.version_last && !obj.flags, | ||
); | ||
if (!isSupported) { | ||
itemCompatIssues.browserIssues = [ | ||
...itemCompatIssues.browserIssues, | ||
name, | ||
]; | ||
hasIssue = true; | ||
} | ||
} | ||
} | ||
if (hasIssue) { | ||
compatIssues[`${prefix}${prop}${suffix}`] = itemCompatIssues; | ||
} | ||
} | ||
return compatIssues; | ||
} | ||
|
||
export function processCompatData() { | ||
const cssCompatIssues = { | ||
...processCompatDataObject(bcd.css["at-rules"], "@"), | ||
...processCompatDataObject(bcd.css.properties, "", ":"), | ||
...processCompatDataObject(bcd.css.selectors, ":"), | ||
...processCompatDataObject(bcd.css.types, "", "\\("), | ||
}; | ||
const htmlCompatIssues = { | ||
...processCompatDataObject(bcd.html.elements, "<"), | ||
...processCompatDataObject(bcd.html.global_attributes, "", "="), | ||
}; | ||
const jsCompatIssues = { | ||
...processCompatDataObject(bcd.javascript.builtins, "", "\\("), | ||
...processCompatDataObject(bcd.api, "", "\\("), | ||
}; | ||
return { | ||
[CSS_GLOB]: cssCompatIssues, | ||
[HTML_GLOB]: htmlCompatIssues, | ||
[JS_GLOB]: jsCompatIssues, | ||
}; | ||
} | ||
|
||
export function createCompatFile() { | ||
const jsonString = JSON.stringify(processCompatData(), null, 2); | ||
const filePath = path.join(__filename, '../compat-issues.json'); | ||
fs.writeFileSync(filePath, jsonString, 'utf-8'); | ||
} | ||
import bcd, { Identifier } from "@mdn/browser-compat-data"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const CSS_GLOB = "**/*.{css,scss}"; | ||
const HTML_GLOB = "**/*.html"; | ||
const JS_GLOB = "**/*.{ts,js}"; | ||
|
||
export type CompatIssue = { | ||
deprecated: boolean; | ||
browserIssues: string[]; | ||
mdn_url?: string; | ||
}; | ||
|
||
export function processCompatDataObject( | ||
data: Identifier, | ||
prefix: string = "", | ||
suffix: string = "", | ||
) { | ||
const compatIssues: { [name: string]: CompatIssue } = {}; | ||
for (const prop of Object.keys(data)) { | ||
let hasIssue = false; | ||
if (!data[prop].__compat) { | ||
continue; | ||
} | ||
const { status, support, mdn_url } = data[prop].__compat!; | ||
const itemCompatIssues: CompatIssue = { | ||
deprecated: false, | ||
browserIssues: [], | ||
mdn_url, | ||
}; | ||
if (status?.deprecated) { | ||
itemCompatIssues.deprecated = true; | ||
hasIssue = true; | ||
} else { | ||
for (const [name, data] of Object.entries(support)) { | ||
const isSupported = !Array.isArray(data) | ||
? data.version_added && !data.version_last && !data.flags | ||
: data.some( | ||
(obj) => obj.version_added && !obj.version_last && !obj.flags, | ||
); | ||
if (!isSupported) { | ||
itemCompatIssues.browserIssues = [ | ||
...itemCompatIssues.browserIssues, | ||
name, | ||
]; | ||
hasIssue = true; | ||
} | ||
} | ||
} | ||
if (hasIssue) { | ||
compatIssues[`${prefix}${prop}${suffix}`] = itemCompatIssues; | ||
} | ||
} | ||
return compatIssues; | ||
} | ||
|
||
export function processCompatData() { | ||
const cssCompatIssues = { | ||
...processCompatDataObject(bcd.css["at-rules"], "@"), | ||
...processCompatDataObject(bcd.css.properties, "", ":"), | ||
...processCompatDataObject(bcd.css.selectors, ":"), | ||
...processCompatDataObject(bcd.css.types, "", "\\("), | ||
}; | ||
const htmlCompatIssues = { | ||
...processCompatDataObject(bcd.html.elements, "<"), | ||
...processCompatDataObject(bcd.html.global_attributes, "", "="), | ||
}; | ||
const jsCompatIssues = { | ||
...processCompatDataObject(bcd.javascript.builtins, "", "\\("), | ||
...processCompatDataObject(bcd.api, "", "\\("), | ||
}; | ||
return { | ||
[CSS_GLOB]: cssCompatIssues, | ||
[HTML_GLOB]: htmlCompatIssues, | ||
[JS_GLOB]: jsCompatIssues, | ||
}; | ||
} | ||
|
||
export function createCompatFile() { | ||
const jsonString = JSON.stringify(processCompatData(), null, 2); | ||
const filePath = path.join(__filename, "../compat-issues.json"); | ||
fs.writeFileSync(filePath, jsonString, "utf-8"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.