Skip to content

Commit

Permalink
refactor(core-js-builder): change blacklist term
Browse files Browse the repository at this point in the history
  • Loading branch information
Rivaldo Junior committed Nov 9, 2020
1 parent af4472e commit bbf0280
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -321,7 +321,7 @@ It does not work with some features. Also, if you change the default behaviour,

### Custom build

For some cases could be useful adding a blacklist of features or generation a polyfill for target engines. You could use [`core-js-builder`](/packages/core-js-builder) package for that.
For some cases could be useful adding a _exclude_ of features or generation a polyfill for target engines. You could use [`core-js-builder`](/packages/core-js-builder) package for that.

### Compatibility data

Expand Down
15 changes: 9 additions & 6 deletions packages/core-js-builder/README.md
@@ -1,12 +1,15 @@
For some cases could be useful adding a blacklist of features or generation a polyfill for target engines. This API helps conditionally include or exclude certain parts of [`core-js`](https://github.com/zloirock/core-js), use `browserslist` queries from [`core-js-compat`](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat) package.
For some cases could be useful adding a _exclude_ list of features or generation a polyfill for target engines. This API helps conditionally include or exclude certain parts of [`core-js`](https://github.com/zloirock/core-js), use `browserslist` queries from [`core-js-compat`](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat) package.

> **NOTE:**
> `blacklist` parameter is now deprecated in favor of `exclude`. And will be removed in the next major version. You can't use both parameters since `blacklist` has precedence.
```js
require('core-js-builder')({
modules: ['es', 'esnext.reflect', 'web'], // modules / namespaces, by default - all `core-js` modules
blacklist: ['es.math', 'es.number.constructor'], // blacklist of modules / namespaces, by default - empty list
targets: '> 0.5%', // optional browserslist query
filename: './my-core-js-bundle.js', // optional target filename, if it's missed a file will not be created
}).then(code => { // code of result polyfill
modules: ['es', 'esnext.reflect', 'web'], // modules / namespaces, by default - all `core-js` modules
exclude: ['es.math', 'es.number.constructor'], // exclude of modules / namespaces, by default - empty list
targets: '> 0.5%', // optional browserslist query
filename: './my-core-js-bundle.js', // optional target filename, if it's missed a file will not be created
}).then(code => { // code of result polyfill
// ...
}).catch(error => {
// ...
Expand Down
10 changes: 8 additions & 2 deletions packages/core-js-builder/index.js
Expand Up @@ -14,7 +14,13 @@ const compat = require('core-js-compat/compat');
const modulesList = require('core-js-compat/modules');
const { banner } = require('./config');

module.exports = async function ({ blacklist = [], modules = modulesList.slice(), targets, filename } = {}) {
module.exports = async function ({
blacklist, // TODO: Remove from `core-js@4`
exclude = [],
modules = modulesList.slice(),
targets,
filename,
} = {}) {
const set = new Set();

function filter(method, list) {
Expand All @@ -28,7 +34,7 @@ module.exports = async function ({ blacklist = [], modules = modulesList.slice()
}

filter('add', modules);
filter('delete', blacklist);
filter('delete', blacklist || exclude);

modules = modulesList.filter(it => set.has(it));

Expand Down

0 comments on commit bbf0280

Please sign in to comment.