UNPKG

1.32 kBJavaScriptView Raw
1// @flow
2
3import typeof * as browserType from "./resolve-targets-browser";
4import typeof * as nodeType from "./resolve-targets";
5
6// Kind of gross, but essentially asserting that the exports of this module are the same as the
7// exports of index-browser, since this file may be replaced at bundle time with index-browser.
8((({}: any): $Exact<browserType>): $Exact<nodeType>);
9
10import type { ValidatedOptions } from "./validation/options";
11import path from "path";
12import getTargets, { type Targets } from "@babel/helper-compilation-targets";
13
14export 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 // $FlowIgnore it thinks that targets.esmodules doesn't exist.
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}