1 |
|
2 |
|
3 | import typeof * as browserType from "./resolve-targets-browser";
|
4 | import typeof * as nodeType from "./resolve-targets";
|
5 |
|
6 |
|
7 |
|
8 | ((({}: any): $Exact<browserType>): $Exact<nodeType>);
|
9 |
|
10 | import type { ValidatedOptions } from "./validation/options";
|
11 | import path from "path";
|
12 | import getTargets, { type Targets } from "@babel/helper-compilation-targets";
|
13 |
|
14 | export function resolveTargets(
|
15 | options: ValidatedOptions,
|
16 | root: string,
|
17 | filename: string | void,
|
18 | ): Targets {
|
19 | let { targets } = options;
|
20 | if (typeof targets === "string" || Array.isArray(targets)) {
|
21 | targets = { browsers: targets };
|
22 | }
|
23 |
|
24 | if (targets && targets.esmodules) {
|
25 | targets = { ...targets, esmodules: "intersect" };
|
26 | }
|
27 |
|
28 | let configFile;
|
29 | if (typeof options.browserslistConfigFile === "string") {
|
30 | configFile = path.resolve(root, options.browserslistConfigFile);
|
31 | }
|
32 |
|
33 | return getTargets((targets: any), {
|
34 | ignoreBrowserslistConfig: options.browserslistConfigFile === false,
|
35 | configFile,
|
36 | configPath: filename ?? root,
|
37 | browserslistEnv: options.browserslistEnv,
|
38 | });
|
39 | }
|