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
feat: add normalizers
(byEngine and toDesktop)
#511
Open
ylemkimon
wants to merge
3
commits into
browserslist:main
Choose a base branch
from
ylemkimon:normalize
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−7
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,7 @@ | |
"JSDoc", | ||
"jspm", | ||
"KaiOS", | ||
"normalizers", | ||
"npm", | ||
"postcss", | ||
"QQ", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
let browserslist = require('../') | ||
|
||
let originData = browserslist.data | ||
let originNormalizedVersions = browserslist.normalizedVersions | ||
|
||
beforeEach(() => { | ||
browserslist.data = { | ||
samsung: { | ||
name: 'samsung', | ||
released: ['4'], | ||
versions: ['4'] | ||
}, | ||
kaios: { | ||
name: 'kaios', | ||
released: ['2.5'], | ||
versions: ['2.5'] | ||
}, | ||
android: { | ||
name: 'android', | ||
released: ['4.4', '4.4.3-4.4.4', '37'], | ||
versions: ['4.4', '4.4.3-4.4.4', '37'] | ||
}, | ||
and_chr: { | ||
name: 'and_chr', | ||
released: ['83'], | ||
versions: ['83'] | ||
} | ||
} | ||
|
||
browserslist.normalizedVersions = { | ||
'samsung 4': 44, | ||
'kaios 2': 'and_ff 48' | ||
} | ||
}) | ||
|
||
afterEach(() => { | ||
browserslist.data = originData | ||
browserslist.normalizedVersions = originNormalizedVersions | ||
}) | ||
|
||
it('normalizes mobile browsers to desktop browsers', () => { | ||
let opts = { normalizers: ['toDesktop'] } | ||
expect(browserslist('android 37', opts)).toEqual(['chrome 37']) | ||
expect(browserslist('last 1 and_chr versions', opts)).toEqual(['chrome 83']) | ||
expect(browserslist('samsung 4', opts)).toEqual(['samsung 4']) | ||
}) | ||
|
||
it('does not normalize classic Android webview versions', () => { | ||
let opts = { normalizers: ['toDesktop'] } | ||
expect(browserslist('android 4.4-37', opts)).toEqual([ | ||
'android 4.4.3-4.4.4', 'android 4.4', 'chrome 37' | ||
]) | ||
}) | ||
|
||
it('normalizes Chromium-based browsers to Chrome', () => { | ||
let opts = { normalizers: ['byEngine'] } | ||
expect(browserslist('samsung 4', opts)).toEqual(['and_chr 44']) | ||
expect(browserslist('kaios 2.5', opts)).toEqual(['and_ff 48']) | ||
expect(browserslist('and_chr 83', opts)).toEqual(['and_chr 83']) | ||
}) | ||
|
||
it('should apply each normalizer in order', () => { | ||
let opts = { normalizers: ['byEngine', 'toDesktop'] } | ||
expect(browserslist('samsung 4', opts)).toEqual(['chrome 44']) | ||
expect(browserslist('kaios 2.5', opts)).toEqual(['firefox 48']) | ||
expect(browserslist('and_chr 83', opts)).toEqual(['chrome 83']) | ||
}) | ||
|
||
it('accepts a normalizer function', () => { | ||
let opts = { normalizers: [() => 'samsung 4'] } | ||
expect(browserslist('android 37', opts)).toEqual(['samsung 4']) | ||
}) | ||
|
||
it('raises on unknown normalizer', () => { | ||
let opts1 = { normalizers: ['_'] } | ||
let opts2 = { normalizers: [{}] } | ||
expect(() => { | ||
browserslist('samsung 4', opts1) | ||
}).toThrow('Unknown normalizer _') | ||
expect(() => { | ||
browserslist('samsung 4', opts2) | ||
}).toThrow('Unknown normalizer [object Object]') | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've named it
toDesktop
instead ofmobileToDesktop
as it may be confused with the existing option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between
normalizers: ['toDesktop']
andmobileToDesktop: true
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ai See #510 and 2ca9e82.
mobileToDesktop
only resolves the version part using desktop data. For example:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JLHwung what do you think if we change
mobileToDesktop
behavior? Onlast 5 and_chr versions
we will returnchrome 78-83
instead ofand_chr 78-83
. Now it will affect Babel?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally Babel maps
and_chr
tochrome
and it seems to me this PR moves this process tobrowserslists
. I don't think it will affect Babel.Another thoughts about
mobileToDesktop
: AFAIK opera_mob is mapped to opera, this is incorrect because they are, if not always, frequently based on different chromium versions. Can we incorporate data from https://github.com/mdn/browser-compat-data/blob/master/browsers/opera_android.json ? This can helppreset-env
on supportingopera_mob
. Surely we can address it in a different PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added
'op_mob 46': 63
tonormalizedVersions
(byEngine
). I think removing it fromdesktopNames
(mobileToDesktop
) would be out of scope for this PR.