fix: add default value for browserslist config path (#13159)

This commit is contained in:
Huáng Jùnliàng 2021-04-15 17:05:35 -04:00 committed by GitHub
parent cbfcee59c7
commit 5d55055537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 1 deletions

View File

@ -179,6 +179,7 @@ export default function getTargets(
options: GetTargetsOption = {},
): Targets {
let { browsers, esmodules } = inputTargets;
const { configPath = "." } = options;
validateBrowsers(browsers);
@ -193,7 +194,7 @@ export default function getTargets(
if (!browsers && shouldSearchForConfig) {
browsers = browserslist.loadConfig({
config: options.configFile,
path: options.configPath,
path: configPath,
env: options.browserslistEnv,
});
if (browsers == null) {

View File

@ -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" });
});

View File

@ -0,0 +1,3 @@
{
"browserslist": "chrome 4"
}

View File

@ -0,0 +1,4 @@
chrome 4
[development]
chrome 88

View File

@ -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" });
});