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: pass browserslistEnv to resolveTargets #13697

Merged
merged 1 commit into from Aug 30, 2021
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
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions packages/babel-helper-compilation-targets/src/index.ts
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)) {
Expand Down
@@ -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" });
});
@@ -0,0 +1,4 @@
module.exports = {
custom: ["firefox >= 75"],
defaults: ["chrome >= 5"],
};