fix(bundler): ignore external rules for entrypoint (#12736)

This commit is contained in:
Ivan Baksheev
2024-07-23 14:33:18 +07:00
committed by GitHub
parent 1a702dfdc7
commit 4e5d759c37
2 changed files with 27 additions and 11 deletions

View File

@@ -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,
@@ -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| {
@@ -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
@@ -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");

View File

@@ -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": `