Correctly handle relative browserslistConfigFile paths (#13031)

* Correctly handle relative `browserslistConfigFile`

* Fix flow
This commit is contained in:
Nicolò Ribaudo
2021-03-26 20:07:28 +01:00
committed by GitHub
parent 16d83002de
commit e68f2ce195
5 changed files with 53 additions and 24 deletions

View File

@@ -100,19 +100,6 @@ describe("browserslist", () => {
).toEqual({ chrome: "80.0.0" });
});
// TODO: browserslistConfig is currently resolved starting from the root
// rather than from the config file.
// eslint-disable-next-line jest/no-disabled-tests
it.skip("loads nested .browserslistrc files if explicitly specified", () => {
expect(
loadOptions({
cwd: join(cwd, "fixtures", "targets"),
filename: "./node_modules/dep/test.js",
babelrcRoots: ["./node_modules/dep/"],
}).targets,
).toEqual({ edge: "14.0.0" });
});
describe("browserslistConfigFile", () => {
it("can disable config loading", () => {
expect(
@@ -132,16 +119,26 @@ describe("browserslist", () => {
).toEqual({ firefox: "74.0.0" });
});
it("is relative to the project root", () => {
it("is relative to the cwd even if specifying 'root'", () => {
expect(
loadOptions({
cwd: join(cwd, "fixtures", "targets"),
root: "..",
filename: "./nested/test.js",
browserslistConfigFile: "./targets/.browserslistrc-firefox",
browserslistConfigFile: "./.browserslistrc-firefox",
}).targets,
).toEqual({ firefox: "74.0.0" });
});
it("is relative to the config files that defines it", () => {
expect(
loadOptions({
cwd: join(cwd, "fixtures", "targets"),
filename: "./node_modules/dep/test.js",
babelrcRoots: ["./node_modules/dep/"],
}).targets,
).toEqual({ edge: "14.0.0" });
});
});
describe("browserslistEnv", () => {