From bff37539b9b493b101ab01e2fdfa5b71a7a3d165 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 4 Aug 2021 12:29:31 -0700 Subject: [PATCH] Fix incorrect module chosen Former-commit-id: 2cb2628ff3be77ca42db8e40fe94dd6e42891533 --- src/linker.zig | 12 +++++++++++- src/node_module_bundle.zig | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/linker.zig b/src/linker.zig index 4e90d0072c..9afb6af604 100644 --- a/src/linker.zig +++ b/src/linker.zig @@ -252,7 +252,7 @@ pub fn NewLinker(comptime BundlerType: type) type { const package = &node_modules_bundle.bundle.packages[pkg_id]; - if (isDebug) { + if (comptime isDebug) { std.debug.assert(strings.eql(node_modules_bundle.str(package.name), package_json.name)); } @@ -275,6 +275,16 @@ pub fn NewLinker(comptime BundlerType: type) type { return error.RebuildJSB; }; + if (comptime isDebug) { + const module_path = node_modules_bundle.str(found_module.path); + std.debug.assert( + strings.eql( + module_path, + package_relative_path, + ), + ); + } + import_record.is_bundled = true; import_record.path.text = linker.nodeModuleBundleImportPath(); import_record.module_id = found_module.id; diff --git a/src/node_module_bundle.zig b/src/node_module_bundle.zig index 94bbe5258e..274e552de1 100644 --- a/src/node_module_bundle.zig +++ b/src/node_module_bundle.zig @@ -201,9 +201,9 @@ pub const NodeModuleBundle = struct { package: *const Api.JavascriptBundledPackage, _query: string, ) ?u32 { - for (this.bundle.modules[package.modules_offset..][0..package.modules_length]) |mod, i| { + for (modulesIn(&this.bundle, package)) |mod, i| { if (strings.eql(this.str(mod.path), _query)) { - return @truncate(u32, i); + return @truncate(u32, i + package.modules_offset); } } @@ -263,7 +263,7 @@ pub const NodeModuleBundle = struct { modules, finder, ModuleFinder.cmpAsc, - ) orelse return null); + ) orelse return null) + package.modules_offset; } pub fn init(container: Api.JavascriptBundleContainer, allocator: *std.mem.Allocator) NodeModuleBundle {