From f9e45114b9c423b72e9c44c4a8aef90f5c3b44d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 22 May 2020 16:01:00 +0200 Subject: 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. --- cli/js/compiler.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'cli/js') 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 ): 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[]; -- cgit v1.2.3