aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-07-31 17:31:16 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-07-31 17:31:16 -0700
commit47a0479bbf10a316c6e41c69f4ae14b978afa989 (patch)
treebf0b5253a0e97f1a9fe3a39f1c72fdf72f90994e /src
parent8589ba2f1712d68199fbef14f5a4ba9005df3065 (diff)
downloadbun-47a0479bbf10a316c6e41c69f4ae14b978afa989.tar.gz
bun-47a0479bbf10a316c6e41c69f4ae14b978afa989.tar.zst
bun-47a0479bbf10a316c6e41c69f4ae14b978afa989.zip
prefer `module` in `exports`dylan/fix-module-field-in-exports
Diffstat (limited to 'src')
-rw-r--r--src/resolver/package_json.zig21
-rw-r--r--src/resolver/resolver.zig3
2 files changed, 24 insertions, 0 deletions
diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig
index 75e6a7c98..902829d3a 100644
--- a/src/resolver/package_json.zig
+++ b/src/resolver/package_json.zig
@@ -1248,6 +1248,7 @@ pub const ESModule = struct {
conditions: ConditionsMap,
allocator: std.mem.Allocator,
module_type: *options.ModuleType = undefined,
+ prefer_module_field_in_exports: bool,
pub const Resolution = struct {
status: Status = Status.Undefined,
@@ -1767,6 +1768,8 @@ pub const ESModule = struct {
var did_find_map_entry = false;
var last_map_entry_i: usize = 0;
+ var module_resolution: ?Resolution = null;
+
const slice = object.list.slice();
const keys = slice.items(.key);
for (keys, 0..) |key, i| {
@@ -1792,6 +1795,19 @@ pub const ESModule = struct {
r.module_type.* = .cjs;
}
+ if (strings.eqlComptime(key, "module")) {
+ if (r.prefer_module_field_in_exports) {
+ r.module_type.* = .esm;
+ return result;
+ }
+
+ // Node will not choose the "module" field in "exports". If it's not preferred, bun will
+ // use the "module" field if no other conditions match. This behavior is similar to
+ // the top-level "module" field.
+ module_resolution = result;
+ continue;
+ }
+
return result;
}
@@ -1800,6 +1816,11 @@ pub const ESModule = struct {
}
}
+ if (module_resolution) |result| {
+ r.module_type.* = .esm;
+ return result;
+ }
+
if (r.debug_logs) |log| {
log.addNoteFmt("No keys matched", .{});
}
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index 49ce9ec11..b7044a625 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -1610,6 +1610,7 @@ pub const Resolver = struct {
.allocator = r.allocator,
.debug_logs = if (r.debug_logs) |*debug| debug else null,
.module_type = &module_type,
+ .prefer_module_field_in_exports = r.prefer_module_field,
};
// Resolve against the path "/", then join it with the absolute
@@ -1875,6 +1876,7 @@ pub const Resolver = struct {
debug
else
null,
+ .prefer_module_field_in_exports = r.prefer_module_field,
};
// Resolve against the path "/", then join it with the absolute
@@ -2853,6 +2855,7 @@ pub const Resolver = struct {
.allocator = r.allocator,
.debug_logs = if (r.debug_logs) |*debug| debug else null,
.module_type = &module_type,
+ .prefer_module_field_in_exports = r.prefer_module_field,
};
const esm_resolution = esmodule.resolveImports(import_path, imports_map.root);