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.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'cli/js/compiler.ts') diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index 3db0e2f52..6cd5a6590 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -202,14 +202,35 @@ async function tsCompilerOnMessage({ sources: sources ? Object.keys(sources) : undefined }); + // resolve the root name, if there are sources, the root name does not + // get resolved const resolvedRootName = sources ? rootName : resolveModules([rootName])[0]; + // recursively process imports, loading each file into memory. If there + // are sources, these files are pulled out of the there, otherwise the + // files are retrieved from the privileged side const rootNames = sources ? processLocalImports(sources, [[resolvedRootName, resolvedRootName]]) : await processImports([[resolvedRootName, resolvedRootName]]); + // if there are options, convert them into TypeScript compiler options, + // and resolve any external file references + let convertedOptions: ts.CompilerOptions | undefined; + if (options) { + const result = convertCompilerOptions(options); + convertedOptions = result.options; + if (result.files) { + // any files supplied in the configuration are resolved externally, + // even if sources are provided + const resolvedNames = resolveModules(result.files); + rootNames.push( + ...(await processImports(resolvedNames.map(rn => [rn, rn]))) + ); + } + } + const state: WriteFileState = { type: request.type, bundle, @@ -227,8 +248,8 @@ async function tsCompilerOnMessage({ writeFile })); const compilerOptions = [defaultRuntimeCompileOptions]; - if (options) { - compilerOptions.push(convertCompilerOptions(options)); + if (convertedOptions) { + compilerOptions.push(convertedOptions); } if (bundle) { compilerOptions.push(defaultBundlerOptions); @@ -278,7 +299,7 @@ async function tsCompilerOnMessage({ ? Object.assign( {}, defaultTranspileOptions, - convertCompilerOptions(options) + convertCompilerOptions(options).options ) : defaultTranspileOptions; -- cgit v1.2.3