Skip to content

Commit

Permalink
fix(externals): exclude external child paths from the bundle (evanw#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
floydspace authored Jun 28, 2020
1 parent 79ee43d commit 01ed3f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions internal/bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4672,6 +4672,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{
Expand Down
3 changes: 2 additions & 1 deletion internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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
}

Expand Down

0 comments on commit 01ed3f8

Please sign in to comment.