diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-02-28 03:27:00 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-27 11:27:00 -0500 |
commit | 1d26da6a478d96a03b08b5bf1ff93a277b69f550 (patch) | |
tree | f780097553003735d3ba622db78b1858c1be9b59 /cli/js/compiler_util.ts | |
parent | daf7617f42e2e7520344ec98db3d60016b85fd73 (diff) |
feat: Support types compiler option in compiler APIs (#4155)
Handles `types` in the compiler APIs to make it easier to supply
external type libraries.
Diffstat (limited to 'cli/js/compiler_util.ts')
-rw-r--r-- | cli/js/compiler_util.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts index 9dd245413..379099f79 100644 --- a/cli/js/compiler_util.ts +++ b/cli/js/compiler_util.ts @@ -182,12 +182,20 @@ export function createWriteFile(state: WriteFileState): WriteFileCallback { }; } +export interface ConvertCompilerOptionsResult { + files?: string[]; + options: ts.CompilerOptions; +} + /** Take a runtime set of compiler options as stringified JSON and convert it * to a set of TypeScript compiler options. */ -export function convertCompilerOptions(str: string): ts.CompilerOptions { +export function convertCompilerOptions( + str: string +): ConvertCompilerOptionsResult { const options: CompilerOptions = JSON.parse(str); const out: Record<string, unknown> = {}; const keys = Object.keys(options) as Array<keyof CompilerOptions>; + const files: string[] = []; for (const key of keys) { switch (key) { case "jsx": @@ -261,11 +269,20 @@ export function convertCompilerOptions(str: string): ts.CompilerOptions { default: throw new TypeError("Unexpected emit target."); } + break; + case "types": + const types = options[key]; + assert(types); + files.push(...types); + break; default: out[key] = options[key]; } } - return out as ts.CompilerOptions; + return { + options: out as ts.CompilerOptions, + files: files.length ? files : undefined + }; } /** An array of TypeScript diagnostic types we ignore. */ |