Skip to content

Commit aca050d

Browse files
authored
Prepackage data into a single script file for easier imports (#81)
* Refactors methodology for including `web-features`, `@mdn/browser-compat-data` and `downstream-browsers.json` data away from using direct dependencies and imports and towards dev dependencies and a regularly updated data file which is compressed down substantially to improve speed. Should result in fewer PRs needing approval and easier automation of data updates. * Adds support for loading in browser contexts. * Adds support for CommonJS using the `/legacy` export path. * Adds tests using Jasmine * Simplifies GitHub actions and removes Dependabot. * Issues a warning if module hasn't been updated in >2 months. * Use @notpushkin 's simplified compareVersions from #68 * README updates for new import options * Updates `web-features` to 2.41.0 and `@mdn/browser-compat-data` to 6.0.29. --------- Co-authored-by: @notpushkin
1 parent ca6aa36 commit aca050d

21 files changed

+9129
-261
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/publish_on_tag.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
- name: Install environment
2323
run: npm ci
2424

25-
- name: Prepare for release
26-
run: npm run prepare
25+
- name: Build for release
26+
run: npm run build
2727

2828
- name: Publish new version to NPM
2929
id: publish-to-npm

.github/workflows/refresh_data.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Refresh downstream-browsers.json
2+
3+
on:
4+
schedule:
5+
- cron: "0 14 * * *"
6+
workflow_dispatch:
7+
8+
env:
9+
package_dir: "/"
10+
11+
jobs:
12+
refresh-downstream-browsers-json:
13+
runs-on: ubuntu-latest
14+
15+
permissions:
16+
contents: write
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: actions/setup-node@v2
21+
with:
22+
node-version: "22"
23+
registry-url: "https://registry.npmjs.org"
24+
25+
- name: Install environment
26+
run: npm ci
27+
28+
- name: check for BCD and web-features updates
29+
id: update-bcd-and-web-features
30+
run: npm run update-data-dependencies
31+
32+
- name: Run refresh-downstream.ts
33+
if: steps.update-bcd-and-web-features.outcome == 'success'
34+
id: refresh-downstream-script
35+
run: npm run refresh-downstream ${{ secrets.USERAGENTSIOKEY }}
36+
37+
- name: Attempt to update data.js file
38+
if: steps.refresh-downstream-script.outcome == 'success'
39+
id: update-data-file
40+
run: |
41+
npm run update-data-file
42+
prettier ./src/data/data.js --write
43+
44+
- name: Check for changes to ./src/data/data.js
45+
if: steps.update-data-file.outcome == 'success'
46+
id: check-data-changes
47+
run: npm run check-data-changes -s >> $GITHUB_OUTPUT
48+
49+
- name: Run tests and linting
50+
if: steps.check-data-changes.outputs.changes-available == 'TRUE'
51+
id: lint-and-test
52+
run: npm run test
53+
54+
- name: Push changes to main
55+
if: steps.lint-and-test.outcome == 'success'
56+
id: push-to-branch
57+
run: |
58+
echo "Data changes have occured, committing to main"
59+
git config --global user.name 'github-actions[bot]'
60+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
61+
git add .
62+
git commit -m "Browser or feature data changed"
63+
git push origin
64+
65+
- name: Tag release for publishing
66+
if: steps.push-to-branch.outcome == 'success'
67+
id: tag-release
68+
run: |
69+
npm version patch -m "Patch to %s because browser or feature data changed"
70+
git push && git push --tags

.github/workflows/refresh_downstream.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/refresh_static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Refresh static resources
22

33
on:
44
schedule:
5-
- cron: "0 16 * * *"
5+
- cron: "0 15 * * *"
66
workflow_dispatch:
77

88
env:

.github/workflows/tag_when_downstream_or_deps_change.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

README.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,56 @@
22

33
By the [W3C WebDX Community Group](https://www.w3.org/community/webdx/) and contributors.
44

5-
`baseline-browser-mapping` exposes arrays of browsers compatible with Baseline Widely available and specified Baseline year feature sets.
6-
You can use `baseline-browser-mapping` to help you determine minimum browser version support for your chosen Baseline feature set.
5+
`baseline-browser-mapping` provides:
76

8-
## Prerequisites
7+
- An `Array` of browsers compatible with Baseline Widely available and Baseline year feature sets via the [`getCompatibleVersions()` function](#get-baseline-widely-available-browser-versions-or-baseline-year-browser-versions).
8+
- An `Array`, `Object` or `CSV` as a string describing the Baseline feature set support of all browser versions included in the module's data set via the [`getAllVersions()` function](#get-data-for-all-browser-versions).
99

10-
To use this package, you'll need:
10+
You can use `baseline-browser-mapping` to help you determine minimum browser version support for your chosen Baseline feature set; or to analyse the level of support for different Baseline feature sets in your site's traffic by joining the data with your analytics data.
1111

12-
- Node.js (a supported [current, active LTS, or maintenance LTS release](https://nodejs.org/en/about/previous-releases))
13-
14-
## Install
12+
## Install for local development
1513

1614
To install the package, run:
1715

18-
`npm install --save baseline-browser-mapping`
16+
`npm install --save-dev baseline-browser-mapping`
1917

20-
`baseline-browser-mapping` depends on `web-features` and `@mdn/browser-compat-data` for version selection. This package uses dependabot to automatically update both modules on all minor and patch version releases and is updated frequently. Consider adding a script to your `package.json` to update `basesline-browser-mapping` and using it as a build step:
18+
`baseline-browser-mapping` depends on `web-features` and `@mdn/browser-compat-data` for core browser version selection, but the data is pre-packaged and minified. This package checks for updates to those modules and the supported [downstream browsers](#downstream-browsers) on a daily basis and is updated frequently. Consider adding a script to your `package.json` to update `basesline-browser-mapping` and using it as part of your build process to ensure your data is as up to date as possible:
2119

2220
```javascript
2321
"scripts": [
24-
"refresh-baseline-browser-mapping": "npm i --save baseline-browser-mapping@latest"
22+
"refresh-baseline-browser-mapping": "npm i --save-dev baseline-browser-mapping@latest"
2523
]
2624
```
2725

26+
If your installed version of `baseline-browser-mapping` is greater than 2 months old, you will receive a console warning advising you to update to the latest version.
27+
28+
## Importing `baseline-browser-mapping`
29+
30+
This module exposes two functions: `getCompatibleVersions()` and `getAllVersions()`, both which can be imported directly from `baseline-browser-mapping`:
31+
32+
```javascript
33+
import { getCompatibleVersions, getAllVersions } from "baseline-browser-mapping";
34+
```
35+
36+
If you want to load the script and data directly in a web page without hosting it yourself, consider using a CDN:
37+
38+
```html
39+
<script type="module">
40+
import { getCompatibleVersions, getAllVersions } from "https://cdn.jsdelivr.net/npm/baseline-browser-mapping";
41+
</script>
42+
```
43+
44+
`baseline-browser-mapping` is packaged as an ES module by default. If you need to run it in a legacy environment that doesn't support ES modules, use the `/legacy` version:
45+
46+
```javascript
47+
const { getCompatibleVersions, getAllVersions } = require("baseline-browser-mapping/legacy");
48+
```
49+
2850
## Get Baseline Widely available browser versions or Baseline year browser versions
2951

3052
To get the current list of minimum browser versions compatible with Baseline Widely available features from the core browser set, call the `getCompatibleVersions()` function:
3153

3254
```javascript
33-
import { getCompatibleVersions } from "baseline-browser-mapping";
34-
3555
getCompatibleVersions();
3656
```
3757

@@ -62,7 +82,7 @@ Executed on 7th March 2025, the above code returns the following browser version
6282
```
6383

6484
> [!NOTE]
65-
> The minimum versions of each browser are not strictly the final release before the Widely available cutoff date of `TODAY - 30 MONTHS`. Some earlier versions will have supported the full Widely available feature set.
85+
> The minimum versions of each browser are not necessarily the final release before the Widely available cutoff date of `TODAY - 30 MONTHS`. Some earlier versions will have supported the full Widely available feature set.
6686
6787
### `getCompatibleVersions()` configuration options
6888

eslint.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import newWithError from "eslint-plugin-new-with-error";
2+
import tseslint from "typescript-eslint";
3+
4+
export default tseslint.config(tseslint.configs.base, {
5+
plugins: { newWithError },
6+
rules: {
7+
"@typescript-eslint/no-unused-vars": [
8+
"error",
9+
{
10+
caughtErrors: "none",
11+
},
12+
],
13+
"newWithError/new-with-error": "error",
14+
"no-duplicate-imports": "error",
15+
"no-throw-literal": "error",
16+
},
17+
files: ["**/*.ts"],
18+
});

0 commit comments

Comments
 (0)