From edec98d23f8e54d0243a26811bd3257cbf3ea9c9 Mon Sep 17 00:00:00 2001 From: Victor Korzunin Date: Thu, 18 Jun 2020 22:25:52 +0200 Subject: [PATCH] fix(externals): exclude external child paths from the bundle as an example if aws-sdk is external, imports from aws-sdk/clients/dynamodb must be excluded from bundle as well --- internal/bundler/bundler_test.go | 38 ++++++++++++++++++++++++++++++++ internal/resolver/resolver.go | 3 ++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/internal/bundler/bundler_test.go b/internal/bundler/bundler_test.go index d6dbcb7579a..e89a192f99a 100644 --- a/internal/bundler/bundler_test.go +++ b/internal/bundler/bundler_test.go @@ -4846,6 +4846,44 @@ render(h(App, null), document.getElementById("app")); }) } +func TestExternalModuleExclusion(t *testing.T) { + expectBundled(t, bundled{ + files: map[string]string{ + "/index.js": ` + import { S3 } from 'aws-sdk'; + import { DocumentClient } from 'aws-sdk/clients/dynamodb'; + export const s3 = new S3(); + export const dynamodb = new DocumentClient(); + `, + }, + entryPaths: []string{"/index.js"}, + parseOptions: parser.ParseOptions{ + IsBundling: true, + }, + bundleOptions: BundleOptions{ + IsBundling: true, + AbsOutputFile: "/out.js", + }, + resolveOptions: resolver.ResolveOptions{ + ExternalModules: map[string]bool{ + "aws-sdk": true, + }, + }, + expected: map[string]string{ + "/out.js": `// /index.js +import {S3} from "aws-sdk"; +import {DocumentClient} from "aws-sdk/clients/dynamodb"; +const s3 = new S3(); +const dynamodb2 = new DocumentClient(); +export { + dynamodb2 as dynamodb, + s3 +}; +`, + }, + }) +} + // This test case makes sure many entry points don't cause a crash func TestManyEntryPoints(t *testing.T) { expectBundled(t, bundled{ diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index fcf02a31680..2b021d1ddee 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -128,7 +128,8 @@ func (r *resolver) resolveWithoutSymlinks(sourcePath string, importPath string) } } else { // Check for external modules first - if r.options.ExternalModules != nil && r.options.ExternalModules[importPath] { + importPathRoot := strings.Split(importPath, "/")[0] + if r.options.ExternalModules != nil && r.options.ExternalModules[importPathRoot] { return "", ResolveExternal }