feat: Support types compiler option in compiler APIs (#4155)

Handles `types` in the compiler APIs to make it easier to supply
external type libraries.
This commit is contained in:
Kitson Kelly 2020-02-28 03:27:00 +11:00 committed by GitHub
parent daf7617f42
commit 1d26da6a47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 7 deletions

View file

@ -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;