Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(externals): exclude external child paths from the bundle #186

Merged
merged 1 commit into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions internal/bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
floydspace marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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
}

Expand Down