Skip to content

Commit

Permalink
Allow using preset-env with newer versions of compat-data (#11201)
Browse files Browse the repository at this point in the history
* Use ~ for preset-env's @babel/compat-data dependency

* Revert "Use ~ for preset-env's @babel/compat-data dependency"

This reverts commit e7d57c7.

* Allow using `preset-env` with newer versions of `compat-data`
  • Loading branch information
nicolo-ribaudo authored Mar 5, 2020
1 parent a12001a commit 7127330
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/babel-preset-env/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getOptionSpecificExcludesFor from "./get-option-specific-excludes";
import { removeUnnecessaryItems } from "./filter-items";
import moduleTransformations from "./module-transformations";
import normalizeOptions from "./normalize-options";
import pluginList from "@babel/compat-data/plugins";
import pluginList from "./plugins-compat-data";
import { proposalPlugins, pluginSyntaxMap } from "../data/shipped-proposals";
import overlappingPlugins from "@babel/compat-data/overlapping-plugins";

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-env/src/normalize-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import findSuggestion from "levenary";
import invariant from "invariant";
import { coerce, SemVer } from "semver";
import corejs2Polyfills from "@babel/compat-data/corejs2-built-ins";
import pluginsList from "@babel/compat-data/plugins";
import pluginsList from "./plugins-compat-data";
import moduleTransformations from "./module-transformations";
import { TopLevelOptions, ModulesOption, UseBuiltInsOption } from "./options";
import { defaultWebIncludes } from "./polyfills/corejs2/get-platform-specific-default";
Expand Down
13 changes: 13 additions & 0 deletions packages/babel-preset-env/src/plugins-compat-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @flow

import plugins from "@babel/compat-data/plugins";
import availablePlugins from "./available-plugins";

const filtered = {};
for (const plugin of Object.keys(plugins)) {
if (Object.hasOwnProperty.call(availablePlugins, plugin)) {
filtered[plugin] = plugins[plugin];
}
}

export { filtered as default };
10 changes: 10 additions & 0 deletions packages/babel-preset-env/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const removeRegeneratorEntryPlugin = require("../lib/polyfills/regenerator/entry
.default;
const transformations = require("../lib/module-transformations").default;

const compatData = require("@babel/compat-data/plugins");
const availablePlugins = require("../lib/available-plugins").default;

describe("babel-preset-env", () => {
describe("transformIncludesAndExcludes", () => {
it("should return in transforms array", () => {
Expand Down Expand Up @@ -248,4 +251,11 @@ describe("babel-preset-env", () => {
});
});
});

it("available-plugins is in sync with @babel/compat-data", () => {
const arrAvailablePlugins = Object.keys(availablePlugins).sort();
const arrCompatData = Object.keys(compatData).sort();

expect(arrAvailablePlugins).toEqual(expect.arrayContaining(arrCompatData));
});
});

0 comments on commit 7127330

Please sign in to comment.