Skip to content

fix browserslist support queries #1042

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugin-packs/postcss-preset-env/.tape.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ postcssTape(plugin)({
stage: 0
}
},
'basic:supports-query': {
message: 'supports { browsers: "defaults and supports css-variables" } usage',
options: {
browsers: 'defaults and supports css-variables'
}
},
'basic:stage0': {
message: 'supports { stage: 0 } usage',
options: {
Expand Down
1 change: 1 addition & 0 deletions plugin-packs/postcss-preset-env/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Unreleased (minor)

- Added `env` option to control which [browserslist environment](https://github.com/browserslist/browserslist#configuring-for-different-environments) to target
- Fix [browserslist supports queries](https://github.com/browserslist/browserslist#full-list)

### 9.0.0

Expand Down
2 changes: 1 addition & 1 deletion plugin-packs/postcss-preset-env/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin-packs/postcss-preset-env/dist/index.mjs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Matches the browsers that have support stats in cssdb.
export const browsersWithSupportStats = [
'and_chr',
'and_ff',
'android',
'chrome',
'edge',
'firefox',
'ie',
'ios_saf',
'op_mini',
'op_mob',
'opera',
'safari',
'samsung',
];
Comment on lines +2 to +16
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this includes something that we don't have data for, like baidu and the browserslist query of the user also includes one of these then the internal logic in postcss-preset-env will always transpile everything.

I've moved this to a separate file and I am not using this a filter consistently throughout the codebase.

2 changes: 1 addition & 1 deletion plugin-packs/postcss-preset-env/src/lib/format-feature.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import getOptionsForBrowsersByFeature from './get-options-for-browsers-by-feature.mjs';
import getUnsupportedBrowsersByFeature from './get-unsupported-browsers-by-feature.mjs';
import { getUnsupportedBrowsersByFeature } from './get-unsupported-browsers-by-feature.mjs';
import { OUT_OF_RANGE_STAGE } from './stage.mjs';
import { insertAfterKey, insertBeforeKey, pluginKey } from '../own-keys/keys.mjs';
import { pluginsById } from '../plugins/plugins-by-id.mjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import browserslist from 'browserslist';
import getUnsupportedBrowsersByFeature from './get-unsupported-browsers-by-feature.mjs';
import { getUnsupportedBrowsersByFeature } from './get-unsupported-browsers-by-feature.mjs';

// add extra options for certain browsers by feature
export default function getOptionsForBrowsersByFeature(browsers, feature, cssdbList, options, logger) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
const browsers = [
'and_chr',
'and_ff',
'and_qq',
'and_uc',
'android',
'baidu',
'chrome',
'edge',
'firefox',
'ie',
'ie_mob',
'ios_saf',
'kaios',
'op_mini',
'op_mob',
'opera',
'safari',
'samsung',
];
import { browsersWithSupportStats } from './browsers-with-supports-stats.mjs';

// return a list of browsers that do not support the feature
export default function getUnsupportedBrowsersByFeature(feature) {
export function getUnsupportedBrowsersByFeature(feature) {
if (!feature) {
return [];
}
Expand All @@ -32,7 +13,7 @@ export default function getUnsupportedBrowsersByFeature(feature) {

const query = [];

browsers.forEach(browser => {
browsersWithSupportStats.forEach(browser => {
if (browser === 'op_mini' && (typeof feature.browser_support[browser] === 'undefined')) {
// Opera Mini is always "op_mini all"
query.push('op_mini all');
Expand Down
5 changes: 4 additions & 1 deletion plugin-packs/postcss-preset-env/src/lib/list-features.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { formatPolyfillableFeature, formatStagedFeature } from './format-feature
import { clamp } from '../util/clamp.mjs';
import { intOrZero } from '../util/int-or-zero.mjs';
import { insertAfterKey, insertBeforeKey } from '../own-keys/keys.mjs';
import { browsersWithSupportStats } from './browsers-with-supports-stats.mjs';

export function listFeatures(cssdbList, options, sharedOptions, logger) {
// initialize options
Expand Down Expand Up @@ -84,7 +85,9 @@ export function listFeatures(cssdbList, options, sharedOptions, logger) {
});

// browsers supported by the configuration
const supportedBrowsers = browserslist(browsers, { env: env, ignoreUnknownVersions: true });
const supportedBrowsers = browserslist(browsers, { env: env, ignoreUnknownVersions: true }).filter((x) => {
return browsersWithSupportStats.includes(x.split(' ')[0]);
});

// - features supported by the stage
// - features with `true` or with options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import getUnsupportedBrowsersByFeature from '../../lib/get-unsupported-browsers-by-feature.mjs';
import { getUnsupportedBrowsersByFeature } from '../../lib/get-unsupported-browsers-by-feature.mjs';
import { strict as assert } from 'assert';

assert.deepStrictEqual(
Expand All @@ -15,143 +15,77 @@ assert.deepStrictEqual(
assert.deepStrictEqual(
getUnsupportedBrowsersByFeature({ browser_support: { firefox: 30 }}),
[
'and_chr >= 1',
'and_ff >= 1',
'and_qq >= 1',
'and_uc >= 1',
'android >= 1',
'baidu >= 1',
'chrome >= 1',
'edge >= 1',
'firefox >= 1',
'ie >= 1',
'ie_mob >= 1',
'ios_saf >= 1',
'kaios >= 1',
'op_mini all',
'op_mob >= 1',
'opera >= 1',
'safari >= 1',
'and_chr >= 1', 'and_ff >= 1',
'android >= 1', 'chrome >= 1',
'edge >= 1', 'firefox >= 1',
'ie >= 1', 'ios_saf >= 1',
'op_mini all', 'op_mob >= 1',
'opera >= 1', 'safari >= 1',
'samsung >= 1',
],
);

assert.deepStrictEqual(
getUnsupportedBrowsersByFeature({ browser_support: { firefox: 'Beta' }}),
[
'and_chr >= 1',
'and_ff >= 1',
'and_qq >= 1',
'and_uc >= 1',
'android >= 1',
'baidu >= 1',
'chrome >= 1',
'edge >= 1',
'firefox >= 1',
'ie >= 1',
'ie_mob >= 1',
'ios_saf >= 1',
'kaios >= 1',
'op_mini all',
'op_mob >= 1',
'opera >= 1',
'safari >= 1',
'and_chr >= 1', 'and_ff >= 1',
'android >= 1', 'chrome >= 1',
'edge >= 1', 'firefox >= 1',
'ie >= 1', 'ios_saf >= 1',
'op_mini all', 'op_mob >= 1',
'opera >= 1', 'safari >= 1',
'samsung >= 1',
],
);

assert.deepStrictEqual(
getUnsupportedBrowsersByFeature({ browser_support: { firefox: 'Beta 5' }}),
[
'and_chr >= 1',
'and_ff >= 1',
'and_qq >= 1',
'and_uc >= 1',
'android >= 1',
'baidu >= 1',
'chrome >= 1',
'edge >= 1',
'firefox >= 1',
'ie >= 1',
'ie_mob >= 1',
'ios_saf >= 1',
'kaios >= 1',
'op_mini all',
'op_mob >= 1',
'opera >= 1',
'safari >= 1',
'and_chr >= 1', 'and_ff >= 1',
'android >= 1', 'chrome >= 1',
'edge >= 1', 'firefox >= 1',
'ie >= 1', 'ios_saf >= 1',
'op_mini all', 'op_mob >= 1',
'opera >= 1', 'safari >= 1',
'samsung >= 1',
],
);

assert.deepStrictEqual(
getUnsupportedBrowsersByFeature({ browser_support: { firefox: '5 Beta' }}),
[
'and_chr >= 1',
'and_ff >= 1',
'and_qq >= 1',
'and_uc >= 1',
'android >= 1',
'baidu >= 1',
'chrome >= 1',
'edge >= 1',
'firefox >= 1',
'ie >= 1',
'ie_mob >= 1',
'ios_saf >= 1',
'kaios >= 1',
'op_mini all',
'op_mob >= 1',
'opera >= 1',
'safari >= 1',
'and_chr >= 1', 'and_ff >= 1',
'android >= 1', 'chrome >= 1',
'edge >= 1', 'firefox >= 1',
'ie >= 1', 'ios_saf >= 1',
'op_mini all', 'op_mob >= 1',
'opera >= 1', 'safari >= 1',
'samsung >= 1',
],
);

assert.deepStrictEqual(
getUnsupportedBrowsersByFeature({ browser_support: { unknown: 30 }}),
[
'and_chr >= 1',
'and_ff >= 1',
'and_qq >= 1',
'and_uc >= 1',
'android >= 1',
'baidu >= 1',
'chrome >= 1',
'edge >= 1',
'firefox >= 1',
'ie >= 1',
'ie_mob >= 1',
'ios_saf >= 1',
'kaios >= 1',
'op_mini all',
'op_mob >= 1',
'opera >= 1',
'safari >= 1',
'and_chr >= 1', 'and_ff >= 1',
'android >= 1', 'chrome >= 1',
'edge >= 1', 'firefox >= 1',
'ie >= 1', 'ios_saf >= 1',
'op_mini all', 'op_mob >= 1',
'opera >= 1', 'safari >= 1',
'samsung >= 1',
],
);

assert.deepStrictEqual(
getUnsupportedBrowsersByFeature({ browser_support: { firefox: '30' }}),
[
'and_chr >= 1',
'and_ff >= 1',
'and_qq >= 1',
'and_uc >= 1',
'android >= 1',
'baidu >= 1',
'chrome >= 1',
'edge >= 1',
'firefox < 30',
'ie >= 1',
'ie_mob >= 1',
'ios_saf >= 1',
'kaios >= 1',
'op_mini all',
'op_mob >= 1',
'opera >= 1',
'safari >= 1',
'and_chr >= 1', 'and_ff >= 1',
'android >= 1', 'chrome >= 1',
'edge >= 1', 'firefox < 30',
'ie >= 1', 'ios_saf >= 1',
'op_mini all', 'op_mob >= 1',
'opera >= 1', 'safari >= 1',
'samsung >= 1',
],
);
Expand All @@ -172,23 +106,12 @@ assert.deepStrictEqual(
'samsung': '15',
}}),
[
'and_chr < 97',
'and_ff < 95',
'and_qq >= 1',
'and_uc >= 1',
'android < 97',
'baidu >= 1',
'chrome < 89',
'edge < 89',
'firefox < 66',
'ie >= 1',
'ie_mob >= 1',
'ios_saf < 15',
'kaios >= 1',
'op_mini all',
'op_mob < 64',
'opera < 76',
'safari < 15',
'and_chr < 97', 'and_ff < 95',
'android < 97', 'chrome < 89',
'edge < 89', 'firefox < 66',
'ie >= 1', 'ios_saf < 15',
'op_mini all', 'op_mob < 64',
'opera < 76', 'safari < 15',
'samsung < 15',
],
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ assert.deepStrictEqual(
{
browsers: [
'and_chr < 18', 'and_ff < 4',
'and_qq >= 1', 'and_uc >= 1',
'android < 65', 'baidu >= 1',
'chrome < 1', 'edge < 79',
'firefox < 1', 'ie >= 1',
'ie_mob >= 1', 'ios_saf < 1',
'kaios >= 1', 'op_mini all',
'op_mob < 14', 'opera < 15',
'safari < 3', 'samsung < 1.0',
'android < 65', 'chrome < 1',
'edge < 79', 'firefox < 1',
'ie >= 1', 'ios_saf < 1',
'op_mini all', 'op_mob < 14',
'opera < 15', 'safari < 3',
'samsung < 1.0',
],
pluginOptions: {
subFeatures: {
Expand Down Expand Up @@ -50,14 +48,12 @@ assert.deepStrictEqual(
{
browsers: [
'and_chr < 18', 'and_ff < 4',
'and_qq >= 1', 'and_uc >= 1',
'android < 65', 'baidu >= 1',
'chrome < 1', 'edge < 79',
'firefox < 1', 'ie >= 1',
'ie_mob >= 1', 'ios_saf < 1',
'kaios >= 1', 'op_mini all',
'op_mob < 14', 'opera < 15',
'safari < 3', 'samsung < 1.0',
'android < 65', 'chrome < 1',
'edge < 79', 'firefox < 1',
'ie >= 1', 'ios_saf < 1',
'op_mini all', 'op_mob < 14',
'opera < 15', 'safari < 3',
'samsung < 1.0',
],
vendors_implementations: 3,
pluginOptions: {
Expand All @@ -69,14 +65,12 @@ assert.deepStrictEqual(
{
browsers: [
'and_chr >= 1', 'and_ff >= 1',
'and_qq >= 1', 'and_uc >= 1',
'android >= 1', 'baidu >= 1',
'chrome >= 1', 'edge >= 1',
'firefox >= 1', 'ie >= 1',
'ie_mob >= 1', 'ios_saf >= 1',
'kaios >= 1', 'op_mini all',
'op_mob >= 1', 'opera >= 1',
'safari >= 1', 'samsung >= 1',
'android >= 1', 'chrome >= 1',
'edge >= 1', 'firefox >= 1',
'ie >= 1', 'ios_saf >= 1',
'op_mini all', 'op_mob >= 1',
'opera >= 1', 'safari >= 1',
'samsung >= 1',
],
vendors_implementations: 0,
pluginOptions: { enableProgressiveCustomProperties: false },
Expand Down
Loading