Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browserslist #3

Merged
merged 4 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
- name: Run CLI Command (expected to fail)
run: |
set +e
browser-compatibility-checker -f sample_project
browser-compatibility-checker -f sample_projects/sample_project
if [ $? -eq 0 ]; then
echo "Command succeeded unexpectedly"
exit 1
fi
echo "Command failed as expected"
- name: Run CLI Command (expected to pass)
run: browser-compatibility-checker -f sample_project_2
run: browser-compatibility-checker -f sample_projects/sample_project_2
- name: Run unit tests
run: npm test
- name: Run extension tests
Expand All @@ -48,11 +48,11 @@ jobs:
- name: Run CLI Command (expected to fail)
run: |
set +e
npx browser-compatibility-checker -f sample_project
npx browser-compatibility-checker -f sample_projects/sample_project
if [ $? -eq 0 ]; then
echo "Command succeeded unexpectedly"
exit 1
fi
echo "Command failed as expected"
- name: Run CLI Command (expected to pass)
run: npx browser-compatibility-checker -f sample_project_2
run: npx browser-compatibility-checker -f sample_projects/sample_project_2
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sample_project/
sample_project_2/
sample_projects/
*.test.*
*.spec.*
src/
Expand Down
5 changes: 4 additions & 1 deletion .vscode-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import path, { dirname } from "path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const testFolderPath = path.resolve(__dirname, "./sample_project");
const testFolderPath = path.resolve(
__dirname,
"./sample_projects/sample_project",
);

export default defineConfig({
files: "out/test/**/*.test.js",
Expand Down
3 changes: 1 addition & 2 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sample_project/
sample_project_2/
sample_projects/
*.test.*
*.spec.*
**/test/**
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ All notable changes to the "browser-compatibility-checker" extension will be doc

- Only generate JSON on compile
- Update keywords

## [1.1.0] - 2024-02-12

- Add browserslist support
100 changes: 97 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Checks compatibility of your HTML/CSS/JS with modern browsers. Uses MDN compatibility data to check for deprecated/mixed-support features.",
"publisher": "benandrew",
"icon": "icon.png",
"version": "1.0.4",
"version": "1.1.0",
"repository": {
"type": "git",
"url": "git+https://github.com/BenAAndrew/browser-compatibility-checker.git"
Expand Down Expand Up @@ -123,6 +123,7 @@
},
"dependencies": {
"@mdn/browser-compat-data": "^5.5.8",
"browserslist": "^4.22.3",
"commander": "^12.0.0",
"kleur": "^4.1.5",
"minimatch": "^9.0.3"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions sample_projects/sample_project_3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"browserslist": [
"> 0%"
]
}
27 changes: 27 additions & 0 deletions src/browser-compatibility-checker/browserslist.ts
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;

Check warning on line 20 in src/browser-compatibility-checker/browserslist.ts

View workflow job for this annotation

GitHub Actions / test

Expected { after 'if' condition
const browsersList = browserslist(browserQuery);
if (browsersList.length === 0) return;

Check warning on line 22 in src/browser-compatibility-checker/browserslist.ts

View workflow job for this annotation

GitHub Actions / test

Expected { after 'if' condition
const browsers = Array.from(
new Set(browsersList.map((b) => b.split(" ")[0])),
);
return browsers.map((b) => BROWSERLIST_TO_MDN_MAP[b]).filter((b) => b);
}
2 changes: 1 addition & 1 deletion src/browser-compatibility-checker/compat-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function createCompatFile() {
const jsonString = JSON.stringify(processCompatData(), null, 2);
const filePath = path.join(__filename, "../compat-issues.json");
fs.writeFileSync(filePath, jsonString, "utf-8");
fs.chmodSync(filePath, '644');
fs.chmodSync(filePath, "644");
}

createCompatFile();
1 change: 1 addition & 0 deletions src/browser-compatibility-checker/index.ts
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 src/browser-compatibility-checker/test/browserslist.spec.ts
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);
});
});
12 changes: 6 additions & 6 deletions src/browser-compatibility-checker/test/check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { readFileSync } from "fs";
describe("Find Issues", function () {
it("Find CSS issues", function () {
const issues = findIssues(
readFileSync("sample_project/style.css", "utf8"),
readFileSync("sample_projects/sample_project/style.css", "utf8"),
{
"-webkit-mask-repeat-y:": {
deprecated: false,
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("Find Issues", function () {
});
it("Find HTML issues", function () {
const issues = findIssues(
readFileSync("sample_project/index.html", "utf8"),
readFileSync("sample_projects/sample_project/index.html", "utf8"),
{
"<center": { deprecated: true, browserIssues: [] },
"is=": { deprecated: false, browserIssues: ["chrome"] },
Expand All @@ -68,7 +68,7 @@ describe("Find Issues", function () {
});
it("Find JS issues", function () {
const issues = findIssues(
readFileSync("sample_project/script.js", "utf8"),
readFileSync("sample_projects/sample_project/script.js", "utf8"),
{
"VideoEncoder\\(": { deprecated: true, browserIssues: ["firefox"] },
"InternalError\\(": { deprecated: false, browserIssues: ["chrome"] },
Expand All @@ -90,7 +90,7 @@ describe("Find Issues", function () {
});
it("Warning issue", function () {
const issues = findIssues(
readFileSync("sample_project/style.css", "utf8"),
readFileSync("sample_projects/sample_project/style.css", "utf8"),
{
"-webkit-mask-repeat-y:": { deprecated: false, browserIssues: ["ie"] },
},
Expand All @@ -108,7 +108,7 @@ describe("Find Issues", function () {
});
it("Ignore excluded browsers", function () {
const issues = findIssues(
readFileSync("sample_project/style.css", "utf8"),
readFileSync("sample_projects/sample_project/style.css", "utf8"),
{
"-webkit-mask-repeat-y:": { deprecated: false, browserIssues: ["ie"] },
},
Expand All @@ -119,7 +119,7 @@ describe("Find Issues", function () {
});
it("Include MDN Url", function () {
const issues = findIssues(
readFileSync("sample_project/style.css", "utf8"),
readFileSync("sample_projects/sample_project/style.css", "utf8"),
{
"-webkit-mask-repeat-y:": {
deprecated: false,
Expand Down
Loading
Loading