Tweak preset-env corejs/useBuiltIns warning and error messages (#9716)
This commit is contained in:
parent
bf94bb9d43
commit
7f8ded9851
@ -204,7 +204,17 @@ export function normalizeCoreJSOption(
|
|||||||
if (useBuiltIns && corejs === undefined) {
|
if (useBuiltIns && corejs === undefined) {
|
||||||
rawVersion = 2;
|
rawVersion = 2;
|
||||||
console.log(
|
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) {
|
} else if (typeof corejs === "object" && corejs !== null) {
|
||||||
rawVersion = corejs.version;
|
rawVersion = corejs.version;
|
||||||
@ -216,11 +226,16 @@ export function normalizeCoreJSOption(
|
|||||||
const version = rawVersion ? coerce(String(rawVersion)) : false;
|
const version = rawVersion ? coerce(String(rawVersion)) : false;
|
||||||
|
|
||||||
if (!useBuiltIns && version) {
|
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)) {
|
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 };
|
return { version, proposals };
|
||||||
|
|||||||
@ -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
|
@babel/preset-env: `DEBUG` option
|
||||||
|
|
||||||
|
|||||||
@ -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
|
@babel/preset-env: `DEBUG` option
|
||||||
|
|
||||||
|
|||||||
@ -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
|
@babel/preset-env: `DEBUG` option
|
||||||
|
|
||||||
|
|||||||
@ -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
|
The uglify target has been deprecated. Set the top level
|
||||||
|
|||||||
@ -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
|
@babel/preset-env: `DEBUG` option
|
||||||
|
|
||||||
|
|||||||
@ -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
|
@babel/preset-env: `DEBUG` option
|
||||||
|
|
||||||
|
|||||||
@ -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
|
@babel/preset-env: `DEBUG` option
|
||||||
|
|
||||||
|
|||||||
@ -64,6 +64,26 @@ describe("normalize-options", () => {
|
|||||||
).toThrowError(/were found in both/);
|
).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", () => {
|
describe("Config format validation", () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user