Skip to content

Instantly share code, notes, and snippets.

@zthxxx
Created September 30, 2021 06:35
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 zthxxx/32efc2ffafb14ba011aa39f92b98ddd0 to your computer and use it in GitHub Desktop.
Save zthxxx/32efc2ffafb14ba011aa39f92b98ddd0 to your computer and use it in GitHub Desktop.
import typescript from 'typescript'
/**
* let { tsconfig, projectReferences, compilerOptions } = parseTsconfigFile()
*
* console.debug(tsconfig, projectReferences, compilerOptions)
*/
const parseTsconfigFile = (tsconfigFile = './tsconfig.json') => {
const { config: tsconfigRaw } = typescript.readConfigFile(tsconfigFile, typescript.sys.readFile)
const parsed = typescript.parseJsonConfigFileContent(
tsconfigRaw,
typescript.sys,
path.dirname(tsconfigFile),
tsconfigRaw.compilerOptions,
tsconfigFile,
)
const { options: compilerOptions } = typescript.convertCompilerOptionsFromJson(
parsed.options,
path.dirname(tsconfigFile),
tsconfigFile,
)
return {
tsconfig: parsed.options,
projectReferences: parsed.projectReferences,
compilerOptions,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment