From 1d26da6a478d96a03b08b5bf1ff93a277b69f550 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Fri, 28 Feb 2020 03:27:00 +1100 Subject: feat: Support types compiler option in compiler APIs (#4155) Handles `types` in the compiler APIs to make it easier to supply external type libraries. --- cli/js/compiler_util.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'cli/js/compiler_util.ts') 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 = {}; const keys = Object.keys(options) as Array; + 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. */ -- cgit v1.2.3