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

[core-js-compat] Filter available modules without using an intermediate set #590

Merged
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
4 changes: 2 additions & 2 deletions packages/core-js-compat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { coerce, lt, lte } = require('semver');
const browserslist = require('browserslist');
const data = require('./data');
const getModulesListForTargetVersion = require('./get-modules-list-for-target-version');
const intersection = require('core-js-pure/features/set/intersection');
const has = Function.call.bind({}.hasOwnProperty);

const mapping = new Map([
Expand Down Expand Up @@ -86,7 +85,8 @@ function compat({ targets, filter, version }) {
else if (typeof filter == 'string') modules = modules.filter(it => it.startsWith(filter));

if (version) {
modules = [...intersection(new Set(getModulesListForTargetVersion(version)), new Set(modules))];
const availableModules = new Set(getModulesListForTargetVersion(version));
modules = modules.filter(name => availableModules.has(name));
}

modules.forEach(key => {
Expand Down
1 change: 0 additions & 1 deletion packages/core-js-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"main": "index.js",
"dependencies": {
"browserslist": "^4.6.3",
"core-js-pure": "3.1.4",
"semver": "^6.1.3"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core-js-compat/src/build-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ const { readFileSync, writeFileSync } = require('fs');
const { dirname, resolve } = require('path');
const detective = require('detective');
const { sync: glob } = require('glob');
const intersection = require('core-js-pure/features/set/intersection');
const data = require('./data');
const order = new Set(Object.keys(data));
const order = Object.keys(data);

function getModulesForEntryPoint(entry) {
const match = entry.match(/\/modules\/([^/]+)$/);
Expand All @@ -19,7 +18,8 @@ function getModulesForEntryPoint(entry) {
const relative = resolve(dir, dependency);
result.push(...getModulesForEntryPoint(relative));
}
return [...intersection(new Set(result), order)];
const resultSet = new Set(result);
return order.filter(it => resultSet.has(it));
}

const entries = {};
Expand Down