diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-05-22 16:01:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 16:01:00 +0200 |
commit | f9e45114b9c423b72e9c44c4a8aef90f5c3b44d6 (patch) | |
tree | b8e4c4f8586b116f1a1bb04cd10ceb6e2cd1cdeb /cli/js | |
parent | ee710994925e8840ea387e1853d9c15f3eb73149 (diff) |
fix: redirects handling in module analysis (#5726)
This commit fixes a bug introduced in #5029 that caused bad
handling of redirects during module analysis.
Also ensured that duplicate modules are not downloaded.
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/compiler.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index a1189dc20..06117413a 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -585,7 +585,6 @@ function buildSourceFileCache( sourceFileMap: Record<string, SourceFileMapEntry> ): void { for (const entry of Object.values(sourceFileMap)) { - assert(entry.sourceCode.length > 0); SourceFile.addToCache({ url: entry.url, filename: entry.url, @@ -596,7 +595,15 @@ function buildSourceFileCache( for (const importDesc of entry.imports) { let mappedUrl = importDesc.resolvedSpecifier; const importedFile = sourceFileMap[importDesc.resolvedSpecifier]; + // IMPORTANT: due to HTTP redirects we might end up in situation + // where URL points to a file with completely different URL. + // In that case we take value of `redirect` field and cache + // resolved specifier pointing to the value of the redirect. + // It's not very elegant solution and should be rethinked. assert(importedFile); + if (importedFile.redirect) { + mappedUrl = importedFile.redirect; + } const isJsOrJsx = importedFile.mediaType === MediaType.JavaScript || importedFile.mediaType === MediaType.JSX; @@ -1032,6 +1039,7 @@ interface SourceFileMapEntry { url: string; sourceCode: string; mediaType: MediaType; + redirect?: string; imports: ImportDescriptor[]; referencedFiles: ReferenceDescriptor[]; libDirectives: ReferenceDescriptor[]; |