Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Adds browsers property to use browserslist's queries #19

Merged
merged 12 commits into from
Oct 13, 2016
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ exports.A = A;
export class A {}
```

```js
// using browserslist
{
"presets": [
["env", {
"targets": {
"chrome": 52,
"browsers": ["last 2 versions", "safari 7"]
}
}]
]
}

// ...

export class A {}
```

### Example with `debug: true`

```js
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-preset-es2015": "^6.14.0",
"babel-register": "^6.14.0",
"browserslist": "^1.4.0",
Copy link
Member

Choose a reason for hiding this comment

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

This will have to be a dependency if we are using it in src

Copy link
Member

Choose a reason for hiding this comment

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

Although it would be better if it was used as a devDependency

"compat-table": "github:hzoo/compat-table#node-fix",
"eslint": "^3.3.1",
"eslint-config-babel": "^1.0.1",
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// "es5-property-mutators",

import pluginList from "../data/plugins.json";
import browserslist from "browserslist";

export const plugins = [
"es3-member-expression-literals",
Expand Down Expand Up @@ -62,7 +63,16 @@ export const isPluginRequired = (supportedEnvironments, plugin) => {
};

const getTargets = targetOpts => {
return targetOpts || {};
const mergedOpts = targetOpts || {};
const browserOpts = targetOpts['browsers'];
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to do any validation here? (like in loose/modules we verify if boolean etc)

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see it's ignored right below

if (typeof browserOpts === 'string' || Array.isArray(browserOpts)) {
delete mergedOpts.browsers;
browserslist(browserOpts).forEach(browser => {
const [browserName, browserVer] = browser.split(' ');
if (!mergedOpts[browserName]) mergedOpts[browserName] = parseInt(browserVer);
});
}
return mergedOpts;
Copy link
Member

@hzoo hzoo Oct 8, 2016

Choose a reason for hiding this comment

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

You could also do an early return here

const browserOpts = targetOpts.browsers;
if (isBrowsersQueryValid(browserOpts)) {
  const queryBrowsers = getLowestVersions(browserslist(browserOpts));
  return mergeBrowsers(queryBrowsers, targetOpts);
}
return targetOps;

};

// TODO: Allow specifying plugins as either shortened or full name
Expand Down