Skip to content

Commit

Permalink
fix: pass browserslistEnv to resolveTargets (babel#13697)
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill authored Aug 30, 2021
1 parent c1f5ca6 commit cb3ebde
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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" });
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
custom: ["firefox >= 75"],
defaults: ["chrome >= 5"],
};

0 comments on commit cb3ebde

Please sign in to comment.