fix: pass browserslistEnv to resolveTargets (#13697)

This commit is contained in:
meskill 2021-08-30 13:35:19 +03:00 committed by GitHub
parent c1f5ca6676
commit cb3ebde8ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 3 deletions

2
.gitignore vendored
View File

@ -70,6 +70,8 @@ packages/babel-standalone/babel.min.js
/eslint/*/LICENSE
!/packages/babel-eslint-plugin/LICENSE
/.vscode
# local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history
/.history
/dts

View File

@ -21,6 +21,7 @@ module.exports = {
"/test/helpers/",
"<rootDir>/test/warning\\.js",
"<rootDir>/build/",
"<rootDir>/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history
"_browser\\.js",
],
testEnvironment: "node",

View File

@ -154,8 +154,11 @@ function generateTargets(inputTargets: InputTargets): Targets {
return input as any as Targets;
}
function resolveTargets(queries: Browsers): Targets {
const resolved = browserslist(queries, { mobileToDesktop: true });
function resolveTargets(queries: Browsers, env?: string): Targets {
const resolved = browserslist(queries, {
mobileToDesktop: true,
env,
});
return getLowestVersions(resolved);
}
@ -217,7 +220,7 @@ export default function getTargets(
}
if (browsers) {
const queryBrowsers = resolveTargets(browsers);
const queryBrowsers = resolveTargets(browsers, options.browserslistEnv);
if (esmodules === "intersect") {
for (const browser of Object.keys(queryBrowsers)) {

View File

@ -0,0 +1,37 @@
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
import getTargets from "../../lib";
const currentDir = dirname(fileURLToPath(import.meta.url));
const oldEnv = process.env.BROWSERSLIST_DANGEROUS_EXTEND;
beforeAll(() => {
process.env.BROWSERSLIST_DANGEROUS_EXTEND = true;
});
afterAll(() => {
process.env.BROWSERSLIST_DANGEROUS_EXTEND = oldEnv;
});
it("pass env to configs used with extends", async () => {
const actual = getTargets(
{
browsers: [
`extends ${resolve(
currentDir,
"fixtures",
"@babel",
"browserslist-config-fixture.cjs",
)}`,
"chrome >= 71",
],
},
{
configPath: currentDir,
browserslistEnv: "custom",
},
);
expect(actual).toEqual({ chrome: "71.0.0", firefox: "75.0.0" });
});

View File

@ -0,0 +1,4 @@
module.exports = {
custom: ["firefox >= 75"],
defaults: ["chrome >= 5"],
};