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

fix: add default value for browserslist config path #13159

Merged
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
3 changes: 2 additions & 1 deletion packages/babel-helper-compilation-targets/src/index.js
Expand Up @@ -179,6 +179,7 @@ export default function getTargets(
options: GetTargetsOption = {},
): Targets {
let { browsers, esmodules } = inputTargets;
const { configPath = "." } = options;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike browserslist, we use "." instead of path.resolve(".") here to avoid import "path" so we don't have to add a packageJson.browsers field for this package.

browserslist will use path.resolve when it is running in a Node environment:

https://github.com/browserslist/browserslist/blob/209adf9e0051fa39a2b25354cffd493300f34b02/node.js#L302


validateBrowsers(browsers);

Expand All @@ -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) {
Expand Down
@@ -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" });
});