This repository has been archived by the owner. It is now read-only.

Adds `browsers` property to use browserslist's queries #19

Merged
merged 12 commits into from Oct 13, 2016

Conversation

Projects
None yet
4 participants
@yavorsky
Member

yavorsky commented Oct 7, 2016

This PR allows us to use browsers property with query like autoprefixer does.

For example, babelrc:

{
  presets: [
    ["env", {
      "targets": {
        "chrome": 52,
        "browsers": ["safari > 7"]
      },
      "loose": true
    }]
  ]
}

will include chrome 52 and safari 8, 9, 10.

ios_saf, ie11 and others unsupported browsers will be ignored.

@yavorsky yavorsky changed the title from Adds browsers property to use browserslist to Adds `browsers` property to use browserslist's queries Oct 7, 2016

@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Oct 7, 2016

Member

awesome!

If you can make test for this as well with a few cases that would be great

Member

hzoo commented Oct 7, 2016

awesome!

If you can make test for this as well with a few cases that would be great

Show outdated Hide outdated package.json
Show outdated Hide outdated src/index.js
@yavorsky

This comment has been minimized.

Show comment
Hide comment
@yavorsky

yavorsky Oct 8, 2016

Member

I think, browsers defined in targets' root must have higher priority than items we receiving in browsers query.
So,

{
  targets: {
    chrome: 50,
    safari: 10,
    browsers: ['last 2 chrome versions', 'last 2 safari versions'] // chrome 52, safari 9
  }
}

will output {chrome: 50, safari: 10}.

Member

yavorsky commented Oct 8, 2016

I think, browsers defined in targets' root must have higher priority than items we receiving in browsers query.
So,

{
  targets: {
    chrome: 50,
    safari: 10,
    browsers: ['last 2 chrome versions', 'last 2 safari versions'] // chrome 52, safari 9
  }
}

will output {chrome: 50, safari: 10}.

@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Oct 8, 2016

Member

Yep I think so to, we should update the doc/comment to say that explicit targets will override what's in browsers

Member

hzoo commented Oct 8, 2016

Yep I think so to, we should update the doc/comment to say that explicit targets will override what's in browsers

Show outdated Hide outdated src/index.js
@@ -39,6 +40,10 @@ export const MODULE_TRANSFORMATIONS = {
* @return {Boolean} Whether or not the transformation is required
*/
export const isPluginRequired = (supportedEnvironments, plugin) => {
if (supportedEnvironments.browsers) {

This comment has been minimized.

@hzoo

hzoo Oct 13, 2016

Member

Is this necessary?

The code that calls this does

 const targets = getTargets(opts.targets);
isPluginRequired(targets, pluginList[pluginName]));
@hzoo

hzoo Oct 13, 2016

Member

Is this necessary?

The code that calls this does

 const targets = getTargets(opts.targets);
isPluginRequired(targets, pluginList[pluginName]));

This comment has been minimized.

@yavorsky

yavorsky Oct 13, 2016

Member

@hzoo It's just for usage from a separate module. When options are not handled yet.

@yavorsky

yavorsky Oct 13, 2016

Member

@hzoo It's just for usage from a separate module. When options are not handled yet.

This comment has been minimized.

@yavorsky

yavorsky Oct 13, 2016

Member

I left it in buildPreset to prevent running getTargets method for each item from pluginList

@yavorsky

yavorsky Oct 13, 2016

Member

I left it in buildPreset to prevent running getTargets method for each item from pluginList

@hzoo hzoo merged commit d3d63e8 into babel:master Oct 13, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Oct 13, 2016

Member

Ok great, looks good!! 🎉

Member

hzoo commented Oct 13, 2016

Ok great, looks good!! 🎉

@hzoo hzoo added the i: enhancement label Oct 13, 2016

@chicoxyzzy

This comment has been minimized.

Show comment
Hide comment
@chicoxyzzy

chicoxyzzy Nov 2, 2016

Member

Do we really need possibility to mention browsers directly in targets? AFAIK browserlist can handle this.

Result of

{
  targets: {
    chrome: 50,
    safari: 10,
    browsers: ['last 2 chrome versions', 'last 2 safari versions']
  }
}

is equal to result of

{
  targets: {
    browsers: ['chrome 50', 'safari 10']
  }
}

Example: http://browserl.ist/?q=last+2+versions%2C+not+ie+%3C+11%2C+chrome+5
Do we need this only for Node.js?

Member

chicoxyzzy commented Nov 2, 2016

Do we really need possibility to mention browsers directly in targets? AFAIK browserlist can handle this.

Result of

{
  targets: {
    chrome: 50,
    safari: 10,
    browsers: ['last 2 chrome versions', 'last 2 safari versions']
  }
}

is equal to result of

{
  targets: {
    browsers: ['chrome 50', 'safari 10']
  }
}

Example: http://browserl.ist/?q=last+2+versions%2C+not+ie+%3C+11%2C+chrome+5
Do we need this only for Node.js?

@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Nov 2, 2016

Member

I guess it depends on what browserlist supports compared to the compat-table - yeah node?

Member

hzoo commented Nov 2, 2016

I guess it depends on what browserlist supports compared to the compat-table - yeah node?

@ianwremmel

This comment has been minimized.

Show comment
Hide comment
@ianwremmel

ianwremmel Nov 5, 2016

It looks like autoprefixer is now recommending a browserlist file in the project root rather than configure tools directly. Does this support that?

ianwremmel commented Nov 5, 2016

It looks like autoprefixer is now recommending a browserlist file in the project root rather than configure tools directly. Does this support that?

@hzoo

This comment has been minimized.

Show comment
Hide comment
@hzoo

hzoo Nov 5, 2016

Member

Nope it's just a string atm - there #26 open though!

Member

hzoo commented Nov 5, 2016

Nope it's just a string atm - there #26 open though!

@ianwremmel

This comment has been minimized.

Show comment
Hide comment
@ianwremmel

ianwremmel Nov 11, 2016

gotcha. thanks @hzoo!

ianwremmel commented Nov 11, 2016

gotcha. thanks @hzoo!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.