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

Remove lodash from babel-compat-data #13024

Merged
merged 2 commits into from Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions packages/babel-compat-data/package.json
Expand Up @@ -31,7 +31,6 @@
"devDependencies": {
"@mdn/browser-compat-data": "^3.1.1",
"core-js-compat": "^3.9.0",
"electron-to-chromium": "1.3.672",
"lodash": "^4.17.19"
"electron-to-chromium": "1.3.672"
}
}
28 changes: 19 additions & 9 deletions packages/babel-compat-data/scripts/utils-build-data.js
@@ -1,9 +1,6 @@
"use strict";

const fs = require("fs");
const flatMap = require("lodash/flatMap");
const mapValues = require("lodash/mapValues");
const findLastIndex = require("lodash/findLastIndex");
const { addElectronSupportFromChromium } = require("./chromium-to-electron");

const envs = require("../build/compat-table/environments");
Expand Down Expand Up @@ -35,6 +32,13 @@ exports.environments = [
"samsung",
];

function flatMap(array, cb) {
if (array.flatMap) return array.flatMap(cb);
return array.reduce((flattened, value) => {
return flattened.concat(value);
}, []);
}
Copy link
Member

Choose a reason for hiding this comment

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

We could just bump the Node.js version requirement for building Babel to 12 (currently it's 10 I think), and avoid the polyfill.

Copy link
Contributor

Choose a reason for hiding this comment

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

that will be a breaking change, wdyt about doing this for babel8?

Copy link
Member

Choose a reason for hiding this comment

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

It's not a breaking change, it's just the minimum Node.js versions used when building Babel (it doesn't affect the code published on npm, which is subject to semver).

Copy link
Member

Choose a reason for hiding this comment

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

Actually, the minimum Node.js version is already 12 since many scripts we use are native ES modules. We can remove the polyfill without problems.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's good, because I forgot to call cb in this polyfill….. 😅


const compatibilityTests = flatMap(compatSources, data =>
flatMap(data.tests, test => {
if (!test.subtests) return test;
Expand Down Expand Up @@ -63,13 +67,19 @@ exports.getLowestImplementedVersion = (
});

const envTests = tests.map(({ res }) => {
const lastNotImplemented = findLastIndex(
envsVersions[env],
const versions = envsVersions[env];
let i = versions.length - 1;

// Find the last not-implemented version
for (; i >= 0; i--) {
const { id } = versions[i];
// Babel assumes strict mode
({ id }) => !(res[id] === true || res[id] === "strict")
);
if (res[id] !== true && res[id] !== "strict") {
break;
}
}

return envsVersions[env][lastNotImplemented + 1];
return envsVersions[env][i + 1];
});

if (envTests.length === 0 || envTests.some(t => !t)) return null;
Expand All @@ -85,7 +95,7 @@ exports.getLowestImplementedVersion = (
};

exports.generateData = (environments, features) => {
return mapValues(features, options => {
return Object.values(features).map(options => {
if (!options.features) {
options = {
features: [options],
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Expand Up @@ -146,7 +146,6 @@ __metadata:
"@mdn/browser-compat-data": ^3.1.1
core-js-compat: ^3.9.0
electron-to-chromium: 1.3.672
lodash: ^4.17.19
languageName: unknown
linkType: soft

Expand Down