-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgetTSConfigCompilerOptions.ts
More file actions
40 lines (31 loc) · 1.17 KB
/
getTSConfigCompilerOptions.ts
File metadata and controls
40 lines (31 loc) · 1.17 KB
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
36
37
38
39
40
import path from 'node:path';
import ts from 'typescript';
import { getLogger } from '../../helpers';
import type { CommonLogger } from '../../models';
export function getTSConfigCompilerOptions(
tsconfigFileNameOrPath: string,
logger: CommonLogger = getLogger(),
): ts.CompilerOptions {
const tsconfigPath = path.resolve(tsconfigFileNameOrPath);
if (!tsconfigPath) {
logger.error('ERROR: Could not find a valid tsconfig.json');
process.exit(1);
}
logger.log('tsc compiler version:', ts.version);
const [major, minor] = ts.version.split('.').map(Number);
const isTs54OrNewer = major > 5 || (major === 5 && minor >= 4);
if (isTs54OrNewer) {
const tsconfigJsonFile = ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile);
const parsedConfig = ts.parseJsonSourceFileConfigFileContent(
tsconfigJsonFile,
ts.sys,
path.dirname(tsconfigPath),
);
logger.groupCollapsed('Parsed tsconfig compiler options for TypeScript >= 5.4');
logger.log(parsedConfig.options);
logger.groupEnd();
return parsedConfig.options;
}
const { allowJs, ...compilerOptions } = require(tsconfigPath).compilerOptions;
return compilerOptions;
}