Skip to content

Commit 57ecd64

Browse files
Jaybhadejayesh-keychain
authored andcommitted
fix: support "including kaios" without downstream
1 parent 093a0f6 commit 57ecd64

4 files changed

Lines changed: 66 additions & 37 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ You can specify the browser and Node.js versions by queries (case insensitive):
231231
- `baseline widely available on YYYY-MM-DD`: selects browser versions that supported the Widely available feature set on the specified date.
232232
- `baseline 2022`: selects browser versions that are compatible with all features that were Baseline Newly available at the end of the specified year.
233233
- `… with downstream`: includes browsers outside the core browser set that support the requested Baseline feature set based on their Chromium or Gecko version. See [`baseline-browser-mapping`](https://github.com/web-platform-dx/baseline-browser-mapping#downstream-browsers).
234-
- `with downstream including kaios`: same output as the previous query plus KaiOS.
234+
- `… including kaios`: adds KaiOS, with or without `with downstream`.
235235
- Last versions:
236236
- `last 2 versions`: the last 2 versions for _each_ browser.
237237
- `last 2 Chrome versions`: the last 2 versions of Chrome browser.

grammar.w3c-ebnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Years ::= 'last' Space+ Numeric Space+ 'year' 's'?
5454

5555
Since ::= 'since' Space Digit+ ('-' Digit+ ('-' Digit+)?)?
5656

57-
Baseline ::= 'baseline' Space (Digit+ | ('newly' | 'widely') Space 'available' (Space 'on' Space Digit+ ('-' Digit+ ('-' Digit+)?)?)? (' with downstream')? (' including kaios')?)
57+
Baseline ::= 'baseline' Space (Digit+ | ('newly' | 'widely') Space 'available' (Space 'on' Space Digit+ ('-' Digit+ ('-' Digit+)?)?)?) (Space 'with' Space 'downstream')? (Space 'including' Space 'kaios')?
5858

5959
Region ::= ('alt-' [a-z][a-z] | [A-Z][A-Z])
6060

index.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -834,43 +834,44 @@ var QUERIES = {
834834
regexp:
835835
/^baseline\s+(?!\s)(?:(\d+)|(newly|widely)\s+(?!\s)available(?:\s+(?!\s)on\s+(?!\s)(\d{4}-\d{2}-\d{2}))?)?(\s+(?!\s)with\s+(?!\s)downstream)?(\s+(?!\s)including\s+(?!\s)kaios)?$/i,
836836
select: function (context, node) {
837-
var baselineVersions
838-
var includeDownstream = !!node.downstream
839-
var includeKaiOS = !!node.kaios
840837
var availability = node.availability && node.availability.toLowerCase()
841838
if (availability === 'newly' && node.date) {
842839
throw new BrowserslistError(
843840
'Using newly available with a date is not supported, please use "widely available on YYYY-MM-DD" and add 30 months to the date you specified.'
844841
)
845842
}
843+
844+
var options = {
845+
includeDownstreamBrowsers: !!node.downstream,
846+
includeKaiOS: !!node.kaios,
847+
suppressWarnings: true
848+
}
846849
if (node.year) {
847-
baselineVersions = bbm.getCompatibleVersions({
848-
targetYear: node.year,
849-
includeDownstreamBrowsers: includeDownstream,
850-
includeKaiOS: includeKaiOS,
851-
suppressWarnings: true
852-
})
850+
options.targetYear = node.year
853851
} else if (node.date) {
854-
baselineVersions = bbm.getCompatibleVersions({
855-
widelyAvailableOnDate: node.date,
856-
includeDownstreamBrowsers: includeDownstream,
857-
includeKaiOS: includeKaiOS,
858-
suppressWarnings: true
859-
})
852+
options.widelyAvailableOnDate = node.date
860853
} else if (availability === 'newly') {
861-
var future30months = new Date().setMonth(new Date().getMonth() + 30)
862-
baselineVersions = bbm.getCompatibleVersions({
863-
widelyAvailableOnDate: future30months,
864-
includeDownstreamBrowsers: includeDownstream,
865-
includeKaiOS: includeKaiOS,
866-
suppressWarnings: true
867-
})
854+
options.widelyAvailableOnDate = new Date().setMonth(
855+
new Date().getMonth() + 30
856+
)
857+
}
858+
859+
var baselineVersions
860+
if (options.includeKaiOS && !options.includeDownstreamBrowsers) {
861+
// baseline-browser-mapping counts KaiOS as a downstream browser and
862+
// refuses to return it alone, so take KaiOS from the downstream list
863+
// and everything else from the core one
864+
options.includeDownstreamBrowsers = true
865+
var downstream = bbm.getCompatibleVersions(options)
866+
options.includeDownstreamBrowsers = false
867+
options.includeKaiOS = false
868+
baselineVersions = bbm.getCompatibleVersions(options).concat(
869+
downstream.filter(function (version) {
870+
return version.browser === 'kai_os'
871+
})
872+
)
868873
} else {
869-
baselineVersions = bbm.getCompatibleVersions({
870-
includeDownstreamBrowsers: includeDownstream,
871-
includeKaiOS: includeKaiOS,
872-
suppressWarnings: true
873-
})
874+
baselineVersions = bbm.getCompatibleVersions(options)
874875
}
875876
return resolve(bbmTransform(baselineVersions), context)
876877
}

test/baseline.test.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,40 @@ test('Selects proper downstream versions for baseline 2020', () => {
109109
)
110110
})
111111

112+
// Test KaiOS without the other downstream browsers
113+
test('Adds KaiOS and nothing else when downstream is not requested', () => {
114+
let core = browserslist('baseline 2020')
115+
let withKaiOS = browserslist('baseline 2020 including kaios')
116+
equal(
117+
withKaiOS.filter(browser => core.indexOf(browser) === -1),
118+
['kaios 3.0-3.1']
119+
)
120+
equal(
121+
core.filter(browser => withKaiOS.indexOf(browser) === -1),
122+
[]
123+
)
124+
})
125+
126+
test('Accepts "including kaios" without downstream in every baseline shape', () => {
127+
let queries = [
128+
'baseline widely available',
129+
'baseline newly available',
130+
'baseline 2020',
131+
'baseline widely available on 2022-07-01'
132+
]
133+
for (let query of queries) {
134+
let core = browserslist(query)
135+
let extra = browserslist(query + ' including kaios').filter(
136+
browser => core.indexOf(browser) === -1
137+
)
138+
is(
139+
extra.every(browser => browser.indexOf('kaios ') === 0),
140+
true,
141+
`${query} added ${extra}`
142+
)
143+
}
144+
})
145+
112146
// Test for errors
113147
test('Throws an error when "newly available on YYYY-MM-DD" is used', () => {
114148
throws(() => {
@@ -118,14 +152,8 @@ test('Throws an error when "newly available on YYYY-MM-DD" is used', () => {
118152

119153
// Test case insensitivity
120154
test('Treats "newly available" as case insensitive', () => {
121-
equal(
122-
browserslist('BASELINE NEWLY AVAILABLE'),
123-
browserslistBaselineNewly
124-
)
125-
equal(
126-
browserslist('baseline NEWLY available'),
127-
browserslistBaselineNewly
128-
)
155+
equal(browserslist('BASELINE NEWLY AVAILABLE'), browserslistBaselineNewly)
156+
equal(browserslist('baseline NEWLY available'), browserslistBaselineNewly)
129157
})
130158

131159
test.run()

0 commit comments

Comments
 (0)