1 | type browserType = typeof import("./resolve-targets-browser");
|
---|
2 | type nodeType = typeof import("./resolve-targets");
|
---|
3 |
|
---|
4 | // Kind of gross, but essentially asserting that the exports of this module are the same as the
|
---|
5 | // exports of index-browser, since this file may be replaced at bundle time with index-browser.
|
---|
6 | ({} as any as browserType as nodeType);
|
---|
7 |
|
---|
8 | import type { ValidatedOptions } from "./validation/options";
|
---|
9 | import path from "path";
|
---|
10 | import getTargets from "@babel/helper-compilation-targets";
|
---|
11 |
|
---|
12 | import type { Targets } from "@babel/helper-compilation-targets";
|
---|
13 |
|
---|
14 | export function resolveBrowserslistConfigFile(
|
---|
15 | browserslistConfigFile: string,
|
---|
16 | configFileDir: string,
|
---|
17 | ): string | undefined {
|
---|
18 | return path.resolve(configFileDir, browserslistConfigFile);
|
---|
19 | }
|
---|
20 |
|
---|
21 | export function resolveTargets(
|
---|
22 | options: ValidatedOptions,
|
---|
23 | root: string,
|
---|
24 | ): Targets {
|
---|
25 | // todo(flow->ts) remove any and refactor to not assign different types into same variable
|
---|
26 | let targets: any = options.targets;
|
---|
27 | if (typeof targets === "string" || Array.isArray(targets)) {
|
---|
28 | targets = { browsers: targets };
|
---|
29 | }
|
---|
30 | if (targets && targets.esmodules) {
|
---|
31 | targets = { ...targets, esmodules: "intersect" };
|
---|
32 | }
|
---|
33 |
|
---|
34 | const { browserslistConfigFile } = options;
|
---|
35 | let configFile;
|
---|
36 | let ignoreBrowserslistConfig = false;
|
---|
37 | if (typeof browserslistConfigFile === "string") {
|
---|
38 | configFile = browserslistConfigFile;
|
---|
39 | } else {
|
---|
40 | ignoreBrowserslistConfig = browserslistConfigFile === false;
|
---|
41 | }
|
---|
42 |
|
---|
43 | return getTargets(targets, {
|
---|
44 | ignoreBrowserslistConfig,
|
---|
45 | configFile,
|
---|
46 | configPath: root,
|
---|
47 | browserslistEnv: options.browserslistEnv,
|
---|
48 | });
|
---|
49 | }
|
---|