-
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.
Add browserslist support (version 1.1.0) (#3)
- Loading branch information
1 parent
e84a4af
commit 401f83a
Showing
21 changed files
with
225 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
sample_project/ | ||
sample_project_2/ | ||
sample_projects/ | ||
*.test.* | ||
*.spec.* | ||
src/ | ||
|
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,5 +1,4 @@ | ||
sample_project/ | ||
sample_project_2/ | ||
sample_projects/ | ||
*.test.* | ||
*.spec.* | ||
**/test/** | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"browserslist": [ | ||
"> 0%" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import browserslist from "browserslist"; | ||
|
||
const BROWSERLIST_TO_MDN_MAP: { [key: string]: string } = { | ||
chrome: "chrome", | ||
edge: "edge", | ||
firefox: "firefox", | ||
opera: "opera", | ||
safari: "safari", | ||
ie: "ie", | ||
and_chr: "chrome_android", | ||
and_ff: "firefox_android", | ||
op_mob: "opera_android", | ||
ios_saf: "safari_ios", | ||
samsung: "samsunginternet_android", | ||
android: "webview_android", | ||
}; | ||
|
||
export function getBrowsersList(path: string) { | ||
const browserQuery = browserslist.findConfig(path)?.defaults; | ||
if (!browserQuery || browserQuery.length === 0) return; | ||
const browsersList = browserslist(browserQuery); | ||
if (browsersList.length === 0) return; | ||
const browsers = Array.from( | ||
new Set(browsersList.map((b) => b.split(" ")[0])), | ||
); | ||
return browsers.map((b) => BROWSERLIST_TO_MDN_MAP[b]).filter((b) => b); | ||
} |
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,2 +1,3 @@ | ||
export { findIssues } from "./check"; | ||
export { CompatIssue } from "./compat-issues"; | ||
export { getBrowsersList } from "./browserslist"; |
26 changes: 26 additions & 0 deletions
26
src/browser-compatibility-checker/test/browserslist.spec.ts
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as assert from "assert"; | ||
import { getBrowsersList } from "../"; | ||
|
||
describe("Browserslist", function () { | ||
it("Get browserslist", function () { | ||
const browsersList = getBrowsersList("sample_projects/sample_project_3"); | ||
assert.deepStrictEqual(browsersList, [ | ||
"chrome_android", | ||
"firefox_android", | ||
"webview_android", | ||
"chrome", | ||
"edge", | ||
"firefox", | ||
"ie", | ||
"safari_ios", | ||
"opera_android", | ||
"opera", | ||
"safari", | ||
"samsunginternet_android", | ||
]); | ||
}); | ||
it("No browserslist", function () { | ||
const browsersList = getBrowsersList("sample_projects/sample_project"); | ||
assert.equal(browsersList, undefined); | ||
}); | ||
}); |
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.