Skip to content
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

refactor(core-js-builder): change blacklist term #882

Merged
merged 1 commit into from Nov 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
rivajunior marked this conversation as resolved.
Show resolved Hide resolved

### 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