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.ts";
|
---|
9 | import path from "path";
|
---|
10 | import getTargets, {
|
---|
11 | type InputTargets,
|
---|
12 | } from "@babel/helper-compilation-targets";
|
---|
13 |
|
---|
14 | import type { Targets } from "@babel/helper-compilation-targets";
|
---|
15 |
|
---|
16 | export function resolveBrowserslistConfigFile(
|
---|
17 | browserslistConfigFile: string,
|
---|
18 | configFileDir: string,
|
---|
19 | ): string | undefined {
|
---|
20 | return path.resolve(configFileDir, browserslistConfigFile);
|
---|
21 | }
|
---|
22 |
|
---|
23 | export function resolveTargets(
|
---|
24 | options: ValidatedOptions,
|
---|
25 | root: string,
|
---|
26 | ): Targets {
|
---|
27 | const optTargets = options.targets;
|
---|
28 | let targets: InputTargets;
|
---|
29 |
|
---|
30 | if (typeof optTargets === "string" || Array.isArray(optTargets)) {
|
---|
31 | targets = { browsers: optTargets };
|
---|
32 | } else if (optTargets) {
|
---|
33 | if ("esmodules" in optTargets) {
|
---|
34 | targets = { ...optTargets, esmodules: "intersect" };
|
---|
35 | } else {
|
---|
36 | // https://github.com/microsoft/TypeScript/issues/17002
|
---|
37 | targets = optTargets as InputTargets;
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | const { browserslistConfigFile } = options;
|
---|
42 | let configFile;
|
---|
43 | let ignoreBrowserslistConfig = false;
|
---|
44 | if (typeof browserslistConfigFile === "string") {
|
---|
45 | configFile = browserslistConfigFile;
|
---|
46 | } else {
|
---|
47 | ignoreBrowserslistConfig = browserslistConfigFile === false;
|
---|
48 | }
|
---|
49 |
|
---|
50 | return getTargets(targets, {
|
---|
51 | ignoreBrowserslistConfig,
|
---|
52 | configFile,
|
---|
53 | configPath: root,
|
---|
54 | browserslistEnv: options.browserslistEnv,
|
---|
55 | });
|
---|
56 | }
|
---|