diff options
-rw-r--r-- | src/bun.js/javascript.zig | 14 | ||||
-rw-r--r-- | test/bun.js/resolve.test.js | 8 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index f87c58e83..6300ae32a 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -1225,7 +1225,8 @@ pub const VirtualMachine = struct { source else jsc_vm.bundler.fs.top_level_dir, - specifier, + // TODO: do we need to handle things like query string params? + if (strings.hasPrefixComptime(specifier, "file://")) specifier["file://".len..] else specifier, .stmt, ); @@ -1347,12 +1348,10 @@ pub const VirtualMachine = struct { var slice = slice_; if (slice.len == 0) return slice; var was_http = false; - if (strings.hasPrefix(slice, "https://")) { + if (strings.hasPrefixComptime(slice, "https://")) { slice = slice["https://".len..]; was_http = true; - } - - if (strings.hasPrefix(slice, "http://")) { + } else if (strings.hasPrefixComptime(slice, "http://")) { slice = slice["http://".len..]; was_http = true; } @@ -2781,12 +2780,17 @@ pub const HardcodedModule = enum { .{ "node:fs/promises", "node:fs/promises" }, .{ "node:module", "node:module" }, .{ "node:path", "node:path" }, + .{ "node:path/posix", "node:path" }, + .{ "node:path/win32", "node:path" }, + .{ "node:perf_hooks", "node:perf_hooks" }, .{ "node:streams/consumer", "node:streams/consumer" }, .{ "node:streams/web", "node:streams/web" }, .{ "node:timers", "node:timers" }, .{ "node:timers/promises", "node:timers/promises" }, .{ "node:url", "node:url" }, .{ "path", "node:path" }, + .{ "path/posix", "node:path" }, + .{ "path/win32", "node:path" }, .{ "perf_hooks", "node:perf_hooks" }, .{ "streams/consumer", "node:streams/consumer" }, .{ "streams/web", "node:streams/web" }, diff --git a/test/bun.js/resolve.test.js b/test/bun.js/resolve.test.js index 4f1e3935b..d081823e6 100644 --- a/test/bun.js/resolve.test.js +++ b/test/bun.js/resolve.test.js @@ -105,6 +105,14 @@ it("self-referencing imports works", async () => { var b = import.meta.require(namespace); expect(a.bar).toBe(1); expect(b.bar).toBe(1); + + // test that file:// works + Loader.registry.delete(baz); + Loader.registry.delete(namespace); + var a = import.meta.require("file://" + baz); + var b = import.meta.require("file://" + namespace); + expect(a.bar).toBe(1); + expect(b.bar).toBe(1); }); function writePackageJSONExportsFixture() { |