Skip to content

Instantly share code, notes, and snippets.

@ushironoko
Created August 26, 2020 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ushironoko/10031c26662a086202dfb59fd9525d77 to your computer and use it in GitHub Desktop.
Save ushironoko/10031c26662a086202dfb59fd9525d77 to your computer and use it in GitHub Desktop.
get tsconfig compiler options
function getCompilerOptions(rootDir: string, configName = 'tsconfig.json') {
const parseConfigHost: ts.ParseConfigHost = {
fileExists: ts.sys.fileExists,
readFile: ts.sys.readFile,
readDirectory: ts.sys.readDirectory,
useCaseSensitiveFileNames: true,
}
const configFileName = ts.findConfigFile(
rootDir,
ts.sys.fileExists,
configName,
)
if (!configFileName) {
return
}
const configFile = ts.readConfigFile(configFileName, ts.sys.readFile)
const compilerOptions = ts.parseJsonConfigFileContent(
configFile.config,
parseConfigHost,
rootDir,
)
return compilerOptions
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment