-
-
Notifications
You must be signed in to change notification settings - Fork 844
Expand file tree
/
Copy pathtsconfig.ts
More file actions
28 lines (25 loc) · 860 Bytes
/
Copy pathtsconfig.ts
File metadata and controls
28 lines (25 loc) · 860 Bytes
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
import type { NitroOptions } from "nitro/types";
import type { TSConfig } from "pkg-types";
import { join, resolve } from "pathe";
import { parseTsconfig } from "get-tsconfig";
const tsconfigCache = new Map<string, any>();
export async function resolveTsconfig(options: NitroOptions) {
const root = resolve(options.rootDir || ".") + "/";
if (!options.typescript.tsConfig) {
options.typescript.tsConfig = loadTsconfig(root);
}
}
function loadTsconfig(root: string): TSConfig {
const tsConfigPath = join(root, "tsconfig.json");
let tsconfig: TSConfig;
try {
tsconfig = parseTsconfig(tsConfigPath, tsconfigCache) as TSConfig;
} catch {
return {} as TSConfig;
}
tsconfig.compilerOptions ??= {};
if (!tsconfig.compilerOptions.baseUrl) {
tsconfig.compilerOptions.baseUrl = resolve(tsConfigPath, "..");
}
return tsconfig;
}