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

Fix handling scoped packages in preset-env include/exclude options #9219

Merged
merged 2 commits into from
Dec 27, 2018
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 packages/babel-preset-env/src/normalize-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const validBrowserslistTargets = [
];

export const normalizePluginName = (plugin: string): string =>
plugin.replace(/^babel-plugin-/, "");
plugin.replace(/^(@babel\/|babel-)(plugin-)?/, "");

export const checkDuplicateIncludeExcludes = (
include: Array<string> = [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Foo {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
[
"../../../../lib",
{
"targets": {
"chrome": 61
},
"include": ["@babel/plugin-transform-classes"],
"modules": false
}
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

let Foo = function Foo() {
_classCallCheck(this, Foo);
};
50 changes: 40 additions & 10 deletions packages/babel-preset-env/test/normalize-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,30 @@ describe("normalize-options", () => {
describe("normalizeOptions", () => {
it("should return normalized `include` and `exclude`", () => {
const normalized = normalizeOptions.default({
include: ["babel-plugin-transform-spread", "transform-classes"],
include: [
"babel-plugin-transform-spread",
"transform-classes",
"@babel/plugin-transform-unicode-regex",
"@babel/transform-block-scoping",
],
exclude: [
"babel-plugin-transform-for-of",
"transform-parameters",
"@babel/plugin-transform-regenerator",
"@babel/transform-new-target",
],
});
expect(normalized.include).toEqual([
"transform-spread",
"transform-classes",
"transform-unicode-regex",
"transform-block-scoping",
]);
expect(normalized.exclude).toEqual([
"transform-for-of",
"transform-parameters",
"transform-regenerator",
"transform-new-target",
]);
});

Expand All @@ -25,15 +44,26 @@ describe("normalize-options", () => {
expect(normalized).toBe("prefix-babel-plugin-postfix");
});

it("should throw if duplicate names in `include` and `exclude`", () => {
const normalizeWithSameIncludes = () => {
normalizeOptions.default({
include: ["babel-plugin-transform-spread"],
exclude: ["transform-spread"],
});
};
expect(normalizeWithSameIncludes).toThrow();
});
test.each`
include | exclude
${["babel-plugin-transform-spread"]} | ${["transform-spread"]}
${["@babel/plugin-transform-spread"]} | ${["transform-spread"]}
${["transform-spread"]} | ${["babel-plugin-transform-spread"]}
${["transform-spread"]} | ${["@babel/plugin-transform-spread"]}
${["babel-plugin-transform-spread"]} | ${["@babel/plugin-transform-spread"]}
${["@babel/plugin-transform-spread"]} | ${["babel-plugin-transform-spread"]}
${["@babel/plugin-transform-spread"]} | ${["@babel/transform-spread"]}
${["@babel/transform-spread"]} | ${["@babel/plugin-transform-spread"]}
${["babel-plugin-transform-spread"]} | ${["@babel/transform-spread"]}
${["@babel/transform-spread"]} | ${["babel-plugin-transform-spread"]}
`(
"should throw if with includes $include and excludes $exclude",
({ include, exclude }) => {
expect(() =>
normalizeOptions.default({ include, exclude }),
).toThrowError(/were found in both/);
},
);
});

describe("Config format validation", () => {
Expand Down