fix: add default value for browserslist config path (#13159)
This commit is contained in:
parent
cbfcee59c7
commit
5d55055537
@ -179,6 +179,7 @@ export default function getTargets(
|
|||||||
options: GetTargetsOption = {},
|
options: GetTargetsOption = {},
|
||||||
): Targets {
|
): Targets {
|
||||||
let { browsers, esmodules } = inputTargets;
|
let { browsers, esmodules } = inputTargets;
|
||||||
|
const { configPath = "." } = options;
|
||||||
|
|
||||||
validateBrowsers(browsers);
|
validateBrowsers(browsers);
|
||||||
|
|
||||||
@ -193,7 +194,7 @@ export default function getTargets(
|
|||||||
if (!browsers && shouldSearchForConfig) {
|
if (!browsers && shouldSearchForConfig) {
|
||||||
browsers = browserslist.loadConfig({
|
browsers = browserslist.loadConfig({
|
||||||
config: options.configFile,
|
config: options.configFile,
|
||||||
path: options.configPath,
|
path: configPath,
|
||||||
env: options.browserslistEnv,
|
env: options.browserslistEnv,
|
||||||
});
|
});
|
||||||
if (browsers == null) {
|
if (browsers == null) {
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
import getTargets from "../..";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
const oldCwd = process.cwd();
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
process.chdir(path.dirname(fileURLToPath(import.meta.url)));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
process.chdir(oldCwd);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("loads packageJson.browserslist", () => {
|
||||||
|
const actual = getTargets({}, {});
|
||||||
|
|
||||||
|
expect(actual).toEqual({ chrome: "4.0.0" });
|
||||||
|
});
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"browserslist": "chrome 4"
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
chrome 4
|
||||||
|
|
||||||
|
[development]
|
||||||
|
chrome 88
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
import getTargets from "../..";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
const oldCwd = process.cwd();
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
process.chdir(path.dirname(fileURLToPath(import.meta.url)));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
process.chdir(oldCwd);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("loads browserslistrc", () => {
|
||||||
|
const actual = getTargets({}, {});
|
||||||
|
|
||||||
|
expect(actual).toEqual({ chrome: "4.0.0" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("loads browserslistrc and respects browserslistEnv", () => {
|
||||||
|
const actual = getTargets(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
browserslistEnv: "development",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(actual).toEqual({ chrome: "88.0.0" });
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user