aboutsummaryrefslogtreecommitdiff
path: root/src/resolver/resolver.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-22 01:03:06 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-22 01:03:06 -0700
commit204b07f46b6c8985c8928ec58b51d941903ad69b (patch)
tree88ed268250938f4c444fac9ffcf0f224efafa791 /src/resolver/resolver.zig
parenta48a02bade5079ab7c5ddd293ba8dc3b2f87ed26 (diff)
downloadbun-204b07f46b6c8985c8928ec58b51d941903ad69b.tar.gz
bun-204b07f46b6c8985c8928ec58b51d941903ad69b.tar.zst
bun-204b07f46b6c8985c8928ec58b51d941903ad69b.zip
package json exports seems to work now!!!
Diffstat (limited to 'src/resolver/resolver.zig')
-rw-r--r--src/resolver/resolver.zig24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index 5e3750aea..31c1ac1fc 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -1184,12 +1184,6 @@ pub fn NewResolver(cache_files: bool) type {
// The condition set is determined by the kind of import
- // Resolve against the path "/", then join it with the absolute
- // directory path. This is done because ESM package resolution uses
- // URLs while our path resolution uses file system paths. We don't
- // want problems due to Windows paths, which are very unlike URL
- // paths. We also want to avoid any "%" characters in the absolute
- // directory path accidentally being interpreted as URL escapes.
const esmodule = ESModule{
.conditions = switch (kind) {
ast.ImportKind.stmt, ast.ImportKind.dynamic => r.opts.conditions.import,
@@ -1200,6 +1194,12 @@ pub fn NewResolver(cache_files: bool) type {
.debug_logs = if (r.debug_logs) |*debug| debug else null,
};
+ // Resolve against the path "/", then join it with the absolute
+ // directory path. This is done because ESM package resolution uses
+ // URLs while our path resolution uses file system paths. We don't
+ // want problems due to Windows paths, which are very unlike URL
+ // paths. We also want to avoid any "%" characters in the absolute
+ // directory path accidentally being interpreted as URL escapes.
var esm_resolution = esmodule.resolve("/", esm.subpath, exports_map.root);
defer Output.debug("ESM Resolution Status {s}: {s}\n", .{ abs_package_path, esm_resolution.status });
@@ -1214,7 +1214,7 @@ pub fn NewResolver(cache_files: bool) type {
switch (esm_resolution.status) {
.Exact => {
- const resolved_dir_info = (r.dirInfoCached(abs_esm_path) catch null) orelse {
+ const resolved_dir_info = (r.dirInfoCached(std.fs.path.dirname(abs_esm_path).?) catch null) orelse {
esm_resolution.status = .ModuleNotFound;
return null;
};
@@ -1232,9 +1232,17 @@ pub fn NewResolver(cache_files: bool) type {
return null;
}
+ const absolute_out_path = brk: {
+ if (entry_query.entry.abs_path.isEmpty()) {
+ entry_query.entry.abs_path =
+ PathString.init(r.fs.dirname_store.append(@TypeOf(abs_esm_path), abs_esm_path) catch unreachable);
+ }
+ break :brk entry_query.entry.abs_path.slice();
+ };
+
return MatchResult{
.path_pair = PathPair{
- .primary = Path.initWithNamespace(esm_resolution.path, "file"),
+ .primary = Path.initWithNamespace(absolute_out_path, "file"),
},
.dirname_fd = entries.fd,
.file_fd = entry_query.entry.cache.fd,