1 | import { isWithin, normalizePath, toAbsolutePath } from "./fs/path-utils";
|
2 | export default function normalizeOptions(options) {
|
3 | const workingPath = toAbsolutePath(options.workingPath === undefined ? process.cwd() : options.workingPath);
|
4 | const rootPath = options.rootPath === undefined
|
5 | ? workingPath
|
6 | : toAbsolutePath(options.rootPath, workingPath);
|
7 | const projectPath = options.projectPath === undefined
|
8 | ? rootPath
|
9 | : toAbsolutePath(options.projectPath, workingPath);
|
10 | const buildPath = options.buildPath === undefined
|
11 | ? undefined
|
12 | : toAbsolutePath(options.buildPath, workingPath);
|
13 | const tsconfig = options.tsconfig;
|
14 | if (buildPath !== undefined &&
|
15 | !(rootPath === buildPath || isWithin(rootPath, buildPath))) {
|
16 | throw new Error(`buildPath "${buildPath}" must be at or within rootPath "${rootPath}"`);
|
17 | }
|
18 | let configFileName;
|
19 | let rawConfig;
|
20 | if (typeof tsconfig === "object") {
|
21 | configFileName = undefined;
|
22 | rawConfig = tsconfig;
|
23 | }
|
24 | else if (tsconfig) {
|
25 | configFileName = normalizePath(tsconfig);
|
26 | rawConfig = undefined;
|
27 | }
|
28 | let throwOnError = options.throwOnError;
|
29 | if (throwOnError === undefined) {
|
30 | throwOnError = process.env.NODE_ENV === "production";
|
31 | }
|
32 | return {
|
33 | buildPath,
|
34 | compilerOptions: options.compilerOptions,
|
35 | configFileName,
|
36 | projectPath,
|
37 | rawConfig,
|
38 | rootPath,
|
39 | throwOnError,
|
40 | workingPath,
|
41 | };
|
42 | }
|
43 |
|
\ | No newline at end of file |