From 72cb84ce173f005d8c913ef62fc082f976cf951a Mon Sep 17 00:00:00 2001 From: RiskyMH Date: Sun, 14 Sep 2025 02:55:27 +1000 Subject: [PATCH] semi better --- docs/api/import-meta.md | 2 +- src/ast/P.zig | 17 +++++++++-------- test/no-validate-exceptions.txt | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/api/import-meta.md b/docs/api/import-meta.md index 56c27a75e6..8a3cf3907c 100644 --- a/docs/api/import-meta.md +++ b/docs/api/import-meta.md @@ -13,7 +13,7 @@ import.meta.main; // `true` if this file is directly executed by `bun run` import.meta.resolve("zod"); // => "file:///path/to/project/node_modules/zod/index.js" -import.meta.glob("./models/*.js"); // => { "./models/user.js": [Async Function], ... } +import.meta.glob("./dir/*.ts"); // => { "./dir/a.ts": () => import("./dir/a.ts"), ... } ``` {% table %} diff --git a/src/ast/P.zig b/src/ast/P.zig index 420db9a8d2..c678109ba7 100644 --- a/src/ast/P.zig +++ b/src/ast/P.zig @@ -6034,20 +6034,21 @@ pub fn NewParser_( } }.lessThan); - // Create properties + // Create dynamic imports var properties: []G.Property = bun.handleOom(p.allocator.alloc(G.Property, matched_files.items.len)); for (matched_files.items, 0..) |file_path, i| { - const base_import_path: []const u8 = if (base_path) |base| - bun.handleOom(std.fmt.allocPrint(p.allocator, "{s}/{s}", .{ base, file_path })) + // add the base path and/or query string to the import path + const import_path: []const u8 = if (base_path) |base| + if (query) |q| + bun.handleOom(std.fmt.allocPrint(p.allocator, "{s}/{s}{s}", .{ base, file_path, q })) + else + bun.handleOom(std.fmt.allocPrint(p.allocator, "{s}/{s}", .{ base, file_path })) + else if (query) |q| + bun.handleOom(std.fmt.allocPrint(p.allocator, "{s}{s}", .{ file_path, q })) else file_path; - const import_path = if (query) |q| - bun.handleOom(std.fmt.allocPrint(p.allocator, "{s}{s}", .{ base_import_path, q })) - else - base_import_path; - const import_record_index = p.addImportRecord(.dynamic, loc, import_path); bun.handleOom(p.import_records_for_current_part.append(p.allocator, import_record_index)); diff --git a/test/no-validate-exceptions.txt b/test/no-validate-exceptions.txt index 375f55c935..4bb2063067 100644 --- a/test/no-validate-exceptions.txt +++ b/test/no-validate-exceptions.txt @@ -316,7 +316,6 @@ test/js/node/crypto/node-crypto.test.js test/js/third_party/pg/pg.test.ts test/regression/issue/01466.test.ts test/regression/issue/21311.test.ts -test/js/bun/glob/import-meta-glob.test.ts test/regression/issue/ctrl-c.test.ts @@ -328,3 +327,5 @@ test/cli/install/bun-repl.test.ts test/bundler/esbuild/default.test.ts test/integration/vite-build/vite-build.test.ts test/cli/inspect/HTTPServerAgent.test.ts +test/js/bun/glob/import-meta-glob.test.ts +test/bundler/bundler_loader.test.ts