Skip to content

Commit

Permalink
Allow use of ranges (≤) before the Baseline low date
Browse files Browse the repository at this point in the history
The `use_ranges_before_baseline_low_date` field controls when generating
the status, but it could also be done in overrides.

Closes web-platform-dx#1018.
  • Loading branch information
foolip committed Jun 10, 2024
1 parent f74abec commit 0c89948
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions features/search-input-type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ group: forms
caniuse: input-search
# TODO: investigate minor differences in the early support of the feature
# between https://caniuse.com/input-search and our generated status.
use_ranges_before_baseline_low_date: true
8 changes: 4 additions & 4 deletions features/search-input-type.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ status:
baseline_low_date: 2015-07-29
baseline_high_date: 2018-01-29
support:
chrome: "5"
chrome: ≤5
chrome_android: "18"
edge: "12"
firefox: "4"
firefox: ≤4
firefox_android: "4"
safari: "5"
safari_ios: "4.2"
safari: ≤5
safari_ios: 4.2
compat_features:
- html.elements.input.type_search
18 changes: 16 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ const nameMaxLength = 80;
// The longest description allowed, to avoid them growing into documentation.
const descriptionMaxLength = 300;

// The earliest possible Baseline low date, the release date of Edge 12.
const earliestBaselineLowDate = '2015-07-29';

// Internal symbol to mark draft entries, so that using the draft field outside
// of a draft directory doesn't work.
const draft = Symbol('draft');

// Some FeatureData keys aren't (and may never) be ready for publishing.
// They're not part of the public schema (yet).
const omittables = [
"group",
"snapshot",
"group"
]
"use_ranges_before_baseline_low_date",
];

function scrub(data: any) {
for (const key of omittables) {
Expand Down Expand Up @@ -168,6 +172,16 @@ for (const [key, data] of yamlEntries('features')) {
}
}

// Ensure that version ranges are only used for prehistoric features.
if (data.status?.support) {
const versions: string[] = Object.values(data.status.support);
if (versions.some((v) => v.startsWith('≤'))) {
if (data.status.baseline_low_date !== earliestBaselineLowDate) {
throw new Error(`Ranges (≤) used in ${key}.yml(.dist) but can only be used when the baseline_low_date is ${earliestBaselineLowDate}`);
}
}
}

// Check that no BCD key is used twice until the meaning is made clear in
// https://github.com/web-platform-dx/web-features/issues/1173.
if (data.compat_features) {
Expand Down
2 changes: 1 addition & 1 deletion schemas/defs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"support": {
"additionalProperties": false,
"description": "Browser versions that most-recently introduced the feature",
"description": "Browser versions that most-recently introduced the feature. A \"\" prefix indicates that support before this point is uncertain and the feature may have been supported earlier.",
"properties": {
"chrome": {
"type": "string"
Expand Down
22 changes: 21 additions & 1 deletion scripts/dist.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computeBaseline, setLogger } from "compute-baseline";
import { Compat, Feature } from "compute-baseline/browser-compat-data";
import { Temporal } from '@js-temporal/polyfill';
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
Expand Down Expand Up @@ -123,7 +124,26 @@ function toDist(sourcePath: string): YAML.Document {
`${id}: contains at least one deprecated compat feature and can never be Baseline. Was this intentional?`,
);
}
insertStatus(dist, JSON.parse(status.toJSON()));

// Add ranges to releases before the Baseline low date. It's not possible
// to use ranges more selectively than this.
if (yaml.get("use_ranges_before_baseline_low_date")) {
const lowDate = Temporal.PlainDate.from(status.baseline_low_date);
const statusWithRanges = JSON.parse(status.toJSON());
const support = statusWithRanges.support;
for (const [browser, release] of status.support.entries()) {
if (release.releaseIndex === 0) {
continue;
}
const date = Temporal.PlainDate.from(release.date);
if (Temporal.PlainDate.compare(date, lowDate) === -1) {
support[browser.id] = `≤${support[browser.id]}`;
}
}
insertStatus(dist, statusWithRanges);
} else {
insertStatus(dist, JSON.parse(status.toJSON()));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface SupportStatus {
baseline_low_date?: string;
/** Date the feature achieved Baseline high status */
baseline_high_date?: string;
/** Browser versions that most-recently introduced the feature */
/** Browser versions that most-recently introduced the feature. A "≤" prefix indicates that support before this point is uncertain and the feature may have been supported earlier. */
support: {
[K in browserIdentifier]?: string;
};
Expand Down

0 comments on commit 0c89948

Please sign in to comment.