diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-03-03 08:18:27 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-02 22:18:27 +0100 |
commit | 83d902a7803adb0c69fe2c98e692a50dae446db9 (patch) | |
tree | 75d15519f15748a0c3d016d0ed4e8f1d8389185d /cli/js/compiler.ts | |
parent | a3c3a56ff71c325ea4807548484023c95ffdcd77 (diff) |
Fix JavaScript dependencies in bundles. (#4215)
Fixes #4602
We turned off `allowJs` by default, to keep the compiler from grabbing
a bunch of files that it wouldn't actually do anything useful with. On
the other hand, this caused problems with bundles, where the compiler
needs to gather all the dependencies, including JavaScript ones. This
fixes this so that when we are bundling, we analyse JavaScript imports
in the compiler.
Diffstat (limited to 'cli/js/compiler.ts')
-rw-r--r-- | cli/js/compiler.ts | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index 6cd5a6590..79d517df2 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -140,7 +140,7 @@ async function tsCompilerOnMessage({ const resolvedRootModules = await processImports( rootNames.map(rootName => [rootName, rootName]), undefined, - host.getCompilationSettings().checkJs + bundle || host.getCompilationSettings().checkJs ); let emitSkipped = true; @@ -208,27 +208,46 @@ async function tsCompilerOnMessage({ ? 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; + let additionalFiles: string[] | 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]))) + additionalFiles = result.files; + } + + const checkJsImports = + bundle || (convertedOptions && convertedOptions.checkJs); + + // 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]], + undefined, + checkJsImports + ) + : await processImports( + [[resolvedRootName, resolvedRootName]], + undefined, + checkJsImports ); - } + + if (additionalFiles) { + // any files supplied in the configuration are resolved externally, + // even if sources are provided + const resolvedNames = resolveModules(additionalFiles); + rootNames.push( + ...(await processImports( + resolvedNames.map(rn => [rn, rn]), + undefined, + checkJsImports + )) + ); } const state: WriteFileState = { |