Skip to content

Commit 1e0a3f6

Browse files
authored
Merge data.extended.json into data.json (#3341)
1 parent d48dba4 commit 1e0a3f6

File tree

8 files changed

+23
-47
lines changed

8 files changed

+23
-47
lines changed

.github/workflows/publish_next_web-features.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ jobs:
5151
- run: npm ci
5252

5353
- run: npm run build
54-
- run: npm run build:extended
5554

5655
- name: Get package.json version
5756
id: version
@@ -108,4 +107,3 @@ jobs:
108107
ARTIFACTS: >
109108
schemas/data.schema.json
110109
${{ env.package_dir }}/data.json
111-
data.extended.json

.github/workflows/publish_web-features.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ jobs:
3333
registry-url: "https://registry.npmjs.org"
3434
- run: npm ci
3535
- run: npm run build
36-
- run: npm run build:extended
37-
- run: gh release upload ${{ github.ref_name }} packages/web-features/data.json schemas/data.schema.json data.extended.json
36+
- run: gh release upload ${{ github.ref_name }} packages/web-features/data.json data.extended.json schemas/data.schema.json
3837
env:
3938
GH_TOKEN: ${{ github.token }}
4039
publish:

index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import YAML from 'yaml';
77
import { convertMarkdown } from "./text";
88
import { GroupData, SnapshotData, WebFeaturesData } from './types';
99

10-
import { BASELINE_LOW_TO_HIGH_DURATION, coreBrowserSet, parseRangedDateString } from 'compute-baseline';
10+
import { BASELINE_LOW_TO_HIGH_DURATION, coreBrowserSet, parseRangedDateString, getStatus } from 'compute-baseline';
1111
import { Compat } from 'compute-baseline/browser-compat-data';
1212
import { assertValidFeatureReference } from './assertions';
1313
import { isMoved, isSplit } from './type-guards';
@@ -209,6 +209,14 @@ for (const [key, data] of yamlEntries('features')) {
209209
bcdToFeatureId.set(bcdKey, key);
210210
}
211211
}
212+
213+
// Generate by_compat_key data.
214+
if (data.status) {
215+
data.status.by_compat_key = {};
216+
for (const bcdKey of data.compat_features) {
217+
data.status.by_compat_key[bcdKey] = getStatus(key, bcdKey);
218+
}
219+
}
212220
}
213221

214222
features[key] = data;

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
},
1818
"scripts": {
1919
"audit-consumers": "tsx scripts/audit-consumers.ts",
20-
"build:extended": "tsx scripts/build.ts extended-json",
2120
"build": "tsx scripts/build.ts package",
2221
"dist": "tsx scripts/dist.ts",
2322
"undist": "tsx scripts/undist.ts",

packages/web-features/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ Most values are ordinary feature objects with names, descriptions, and other dat
6666
Some features contain redirects to other features.
6767
You can distinguish between ordinary feature objects and redirects by using the `kind` property:
6868

69-
* `"feature"` — ordinary features
70-
* `"moved"` — the feature has a redirect to a new key
71-
* `"split"` — the feature has a redirect to two or more keys
69+
- `"feature"` — ordinary features
70+
- `"moved"` — the feature has a redirect to a new key
71+
- `"split"` — the feature has a redirect to two or more keys
7272

7373
### Feature objects
7474

@@ -82,14 +82,16 @@ It has the following properties:
8282
- `spec` (type: `string[]`): A specification URL or an array of them
8383
- `status`: Support status data.
8484
It has the following properties:
85-
8685
- `baseline` (type: `"high" | "low" | false`): Whether the feature Baseline widely available, Baseline newly available, or not Baseline
8786
- `baseline_low_date` (optional, type: `string`): When the feature reached Baseline newly available status
8887
- `baseline_high_date` (optional, type: `string`): When the feature reached Baseline widely available status
8988
- `support`: An object representing per-browser support information, showing the version number where each browser first started to support that feature.
9089
All keys are optional.
9190
Keys are one of: `"chrome"`, `"chrome_android"`, `"edge"`, `"firefox"`, `"firefox"`, `"firefox_android"`, `"safari"`, `"safari_ios"`.
9291
Each value is a `string` containing the version number.
92+
- `by_compat_key` (optional, type: `object`): An object mapping each compat key from the feature's `compat_features` array to its individual support status data.
93+
Each value follows the same structure as the main `status` object, with `baseline`, `baseline_low_date`, `baseline_high_date`, and `support` properties.
94+
Only present for features that have `compat_features`.
9395

9496
- `group` (optional, type: `string[]`): A `groups` key or an array of them
9597
- `snapshot` (optional, type: `string[]`): A `snapshots` key or an array of them
@@ -98,7 +100,6 @@ It has the following properties:
98100
- `compat_features` (optional, type: `string[]`): An array of `@mdn/browser-compat-data` feature key strings.
99101
- `discouraged` (optional): An object indicating that web developers should avoid using the feature.
100102
It has the following properties:
101-
102103
- `according_to` (type: `string[]`): One or more links to a formal discouragement notice, such as specification text or an intent-to-unship
103104
- `alternatives` (optional, type: `string[]`): One or more feature IDs (as in `features[alternatives[0]]`) that substitute some or all of this feature's utility
104105

schemas/data.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@
298298
"baseline_low_date": {},
299299
"support": {},
300300
"by_compat_key": {
301-
"description": "Statuses for each key in the feature's compat_features list, if applicable. Not available to the npm release of web-features.",
301+
"description": "Statuses for each key in the feature's compat_features list, if applicable.",
302302
"type": "object",
303303
"additionalProperties": {
304304
"$ref": "#/definitions/Status"

scripts/build.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { DefinedError } from "ajv";
2-
import { getStatus } from "compute-baseline";
32
import stringify from "fast-json-stable-stringify";
43
import { execSync } from "node:child_process";
54
import fs from "node:fs";
65
import { basename } from "node:path";
76
import winston from "winston";
87
import yargs from "yargs";
98
import * as data from "../index.js";
10-
import { isOrdinaryFeatureData } from "../type-guards.js";
119
import { validate } from "./validate.js";
1210

1311
const logger = winston.createLogger({
@@ -27,11 +25,6 @@ yargs(process.argv.slice(2))
2725
describe: "Generate the web-features npm package",
2826
handler: buildPackage,
2927
})
30-
.command({
31-
command: "extended-json",
32-
describe: "Generate a web-features JSON file with BCD per-key statuses",
33-
handler: buildExtendedJSON,
34-
})
3528
.parseSync();
3629

3730
function buildPackage() {
@@ -51,6 +44,11 @@ function buildPackage() {
5144
const json = stringify(data);
5245
const path = new URL("data.json", packageDir);
5346
fs.writeFileSync(path, json);
47+
48+
// TODO: Remove the extended data artifact in the next major release.
49+
const extendedPath = new URL("data.extended.json", rootDir);
50+
fs.writeFileSync(extendedPath, json);
51+
5452
for (const file of filesToCopy) {
5553
fs.copyFileSync(
5654
new URL(file, rootDir),
@@ -67,32 +65,6 @@ function buildPackage() {
6765
});
6866
}
6967

70-
function buildExtendedJSON() {
71-
for (const [id, featureData] of Object.entries(data.features)) {
72-
if (!isOrdinaryFeatureData(featureData)) {
73-
continue;
74-
}
75-
76-
if (
77-
Array.isArray(featureData.compat_features) &&
78-
featureData.compat_features.length &&
79-
featureData.status
80-
) {
81-
featureData.status.by_compat_key = {};
82-
for (const key of featureData.compat_features) {
83-
featureData.status.by_compat_key[key] = getStatus(id, key);
84-
}
85-
}
86-
}
87-
88-
if (!valid(data)) {
89-
logger.error("Data failed schema validation. No JSON file written.");
90-
process.exit(1);
91-
}
92-
93-
fs.writeFileSync(new URL("./data.extended.json", rootDir), stringify(data));
94-
}
95-
9668
function valid(data: any): boolean {
9769
const valid = validate(data);
9870
if (!valid) {

types.quicktype.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ export interface StatusHeadline {
153153
*/
154154
baseline_low_date?: string;
155155
/**
156-
* Statuses for each key in the feature's compat_features list, if applicable. Not available
157-
* to the npm release of web-features.
156+
* Statuses for each key in the feature's compat_features list, if applicable.
158157
*/
159158
by_compat_key?: { [key: string]: Status };
160159
/**

0 commit comments

Comments
 (0)