Skip to content

Commit

Permalink
fix(bundler): ignore external rules for entrypoint (#12736)
Browse files Browse the repository at this point in the history
  • Loading branch information
zpix1 authored Jul 23, 2024
1 parent 1a702df commit 4e5d759
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/resolver/resolver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,6 @@ pub fn ResolveWatcher(comptime Context: type, comptime onWatch: anytype) type {
};
}

fn isExternalModuleLike(import_path: string) bool {
if (strings.startsWith(import_path, ".") or strings.startsWith(import_path, "/") or strings.startsWith(import_path, "..")) {
return false;
}
return true;
}

pub const Resolver = struct {
const ThisResolver = @This();
opts: options.BundleOptions,
Expand Down Expand Up @@ -632,7 +625,7 @@ pub const Resolver = struct {
}

pub fn isExternalPattern(r: *ThisResolver, import_path: string) bool {
if (r.opts.packages == .external and isExternalModuleLike(import_path)) {
if (r.opts.packages == .external and isPackagePath(import_path)) {
return true;
}
for (r.opts.external.patterns) |pattern| {
Expand Down Expand Up @@ -873,8 +866,10 @@ pub const Resolver = struct {
}
}

// Certain types of URLs default to being external for convenience
if (r.isExternalPattern(import_path) or
// Certain types of URLs default to being external for convenience,
// while these rules should not be applied to the entrypoint as it is never external (#12734)
if (kind != .entry_point and
(r.isExternalPattern(import_path) or
// "fill: url(#filter);"
(kind.isFromCSS() and strings.startsWith(import_path, "#")) or

Expand All @@ -885,7 +880,7 @@ pub const Resolver = struct {
strings.startsWith(import_path, "https://") or

// "background: url(//example.com/images/image.png);"
strings.startsWith(import_path, "//"))
strings.startsWith(import_path, "//")))
{
if (r.debug_logs) |*debug| {
debug.addNote("Marking this path as implicitly external");
Expand Down
21 changes: 21 additions & 0 deletions test/bundler/bundler_edgecase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,27 @@ describe("bundler", () => {
`,
},
});
itBundled("edgecase/EntrypointWithoutPrefixSlashOrDotIsNotConsideredExternal#12734", {
files: {
"/src/entry.ts": /* ts */ `
import { helloWorld } from "./second.ts";
console.log(helloWorld);
`,
"/src/second.ts": /* ts */ `
export const helloWorld = "Hello World";
`,
},
root: "/src",
entryPointsRaw: ["src/entry.ts"],
packages: "external",
target: "bun",
run: {
file: "/src/entry.ts",
stdout: `
Hello World
`,
},
});
itBundled("edgecase/IntegerUnderflow#12547", {
files: {
"/entry.js": `
Expand Down

0 comments on commit 4e5d759

Please sign in to comment.