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

Tweak preset-env corejs/useBuiltIns warning and error messages #9716

Merged
merged 2 commits into from
Mar 21, 2019
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
21 changes: 18 additions & 3 deletions packages/babel-preset-env/src/normalize-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,17 @@ export function normalizeCoreJSOption(
if (useBuiltIns && corejs === undefined) {
rawVersion = 2;
console.log(
"\nWith `useBuiltIns` option, required direct setting of `corejs` option\n",
"\nWe noticed you're using the `useBuiltIns` option without declaring a " +
"core-js version. Currently, we assume version 2.x when no version " +
"is passed. Since this default version will likely change in future " +
"versions of Babel, we recommend explicitly setting the core-js version " +
"you are using via the `corejs` option.\n" +
"\nYou should also be sure that the version you pass to the `corejs` " +
"option matches the version specified in your `package.json`'s " +
"`dependencies` section. If it doesn't, you need to run one of the " +
"following commands:\n\n" +
" npm install --save core-js@2 npm install --save core-js@3\n" +
" yarn add core-js@2 yarn add core-js@3\n",
);
} else if (typeof corejs === "object" && corejs !== null) {
rawVersion = corejs.version;
Expand All @@ -216,11 +226,16 @@ export function normalizeCoreJSOption(
const version = rawVersion ? coerce(String(rawVersion)) : false;

if (!useBuiltIns && version) {
console.log("\n`corejs` option required only with `useBuiltIns` option\n");
console.log(
"\nThe `corejs` option only has an effect when the `useBuiltIns` option is not `false`\n",
);
}

if (useBuiltIns && (!version || version.major < 2 || version.major > 3)) {
throw new RangeError("Supported only core-js@2 and core-js@3.");
throw new RangeError(
"Invalid Option: The version passed to `corejs` is invalid. Currently, " +
"only core-js@2 and core-js@3 are supported.",
);
}

return { version, proposals };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`corejs` option required only with `useBuiltIns` option
The `corejs` option only has an effect when the `useBuiltIns` option is not `false`

@babel/preset-env: `DEBUG` option

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
With `useBuiltIns` option, required direct setting of `corejs` option
We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

npm install --save core-js@2 npm install --save core-js@3
yarn add core-js@2 yarn add core-js@3

@babel/preset-env: `DEBUG` option

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
With `useBuiltIns` option, required direct setting of `corejs` option
We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

npm install --save core-js@2 npm install --save core-js@3
yarn add core-js@2 yarn add core-js@3

@babel/preset-env: `DEBUG` option

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
With `useBuiltIns` option, required direct setting of `corejs` option
We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

npm install --save core-js@2 npm install --save core-js@3
yarn add core-js@2 yarn add core-js@3


The uglify target has been deprecated. Set the top level
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
With `useBuiltIns` option, required direct setting of `corejs` option
We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

npm install --save core-js@2 npm install --save core-js@3
yarn add core-js@2 yarn add core-js@3

@babel/preset-env: `DEBUG` option

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
With `useBuiltIns` option, required direct setting of `corejs` option
We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

npm install --save core-js@2 npm install --save core-js@3
yarn add core-js@2 yarn add core-js@3

@babel/preset-env: `DEBUG` option

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
With `useBuiltIns` option, required direct setting of `corejs` option
We noticed you're using the `useBuiltIns` option without declaring a core-js version. Currently, we assume version 2.x when no version is passed. Since this default version will likely change in future versions of Babel, we recommend explicitly setting the core-js version you are using via the `corejs` option.

You should also be sure that the version you pass to the `corejs` option matches the version specified in your `package.json`'s `dependencies` section. If it doesn't, you need to run one of the following commands:

npm install --save core-js@2 npm install --save core-js@3
yarn add core-js@2 yarn add core-js@3

@babel/preset-env: `DEBUG` option

Expand Down
20 changes: 20 additions & 0 deletions packages/babel-preset-env/test/normalize-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ describe("normalize-options", () => {
).toThrowError(/were found in both/);
},
);

it("should not throw if corejs version is valid", () => {
[2, 2.1, 3, 3.5].forEach(corejs => {
["entry", "usage"].forEach(useBuiltIns => {
expect(() =>
normalizeOptions.default({ useBuiltIns, corejs }),
).not.toThrowError();
});
});
});

it("should throw if corejs version is invalid", () => {
[1, 1.2, 4, 4.5].forEach(corejs => {
["entry", "usage"].forEach(useBuiltIns => {
expect(() =>
normalizeOptions.default({ useBuiltIns, corejs }),
).toThrowError(/The version passed to `corejs` is invalid./);
});
});
});
});

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