-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
resolve-targets.js
35 lines (29 loc) 路 1.1 KB
/
resolve-targets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// @flow
import typeof * as browserType from "./resolve-targets-browser";
import typeof * as nodeType from "./resolve-targets";
// Kind of gross, but essentially asserting that the exports of this module are the same as the
// exports of index-browser, since this file may be replaced at bundle time with index-browser.
((({}: any): $Exact<browserType>): $Exact<nodeType>);
import type { ValidatedOptions } from "./validation/options";
import path from "path";
import getTargets, { type Targets } from "@babel/helper-compilation-targets";
export function resolveTargets(
options: ValidatedOptions,
root: string,
filename: string | void,
): Targets {
let { targets } = options;
if (typeof targets === "string" || Array.isArray(targets)) {
targets = { browsers: targets };
}
let config;
if (typeof options.browserslistConfigFile === "string") {
config = path.resolve(root, options.browserslistConfigFile);
}
return getTargets((targets: any), {
ignoreBrowserslistConfig: options.browserslistConfigFile === false,
config,
path: filename ?? root,
env: options.browserslistEnv,
});
}