Skip to content

Commit

Permalink
Tweak preset-env corejs/useBuiltIns warning and error messages (#9716)
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Mar 21, 2019
1 parent bf94bb9 commit 7f8ded9
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 10 deletions.
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

0 comments on commit 7f8ded9

Please sign in to comment.