diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/resolver/package_json.zig | 14 | ||||
| -rw-r--r-- | src/resolver/resolver.zig | 24 | 
2 files changed, 26 insertions, 12 deletions
| diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index b6faa19be..d98784c2b 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -686,6 +686,7 @@ pub const ExportsMap = struct {                  .e_object => |e_obj| {                      var map_data = Entry.Data.Map.List{};                      map_data.ensureTotalCapacity(this.allocator, e_obj.*.properties.len) catch unreachable; +                    map_data.len = map_data.capacity;                      var expansion_keys = this.allocator.alloc(Entry.Data.Map.MapEntry, e_obj.*.properties.len) catch unreachable;                      var expansion_key_i: usize = 0;                      var map_data_slices = map_data.slice(); @@ -916,9 +917,9 @@ pub const ESModule = struct {              if (strings.startsWith(package.name, ".") or strings.indexAnyComptime(package.name, "\\%") != null)                  return null; -            std.mem.copy(u8, subpath_buf[1..], package.subpath); +            std.mem.copy(u8, subpath_buf[1..], specifier[package.name.len..]);              subpath_buf[0] = '.'; -            package.subpath = subpath_buf[0 .. package.subpath.len + 1]; +            package.subpath = subpath_buf[0 .. specifier[package.name.len..].len + 1];              return package;          }      }; @@ -948,7 +949,12 @@ pub const ESModule = struct {          const PercentEncoding = @import("../query_string_map.zig").PercentEncoding;          var fbs = std.io.fixedBufferStream(&resolved_path_buf_percent);          var writer = fbs.writer(); -        const len = PercentEncoding.decode(@TypeOf(&writer), &writer, result.path) catch return Resolution{ .status = .InvalidModuleSpecifier, .path = result.path, .debug = result.debug }; +        const len = PercentEncoding.decode(@TypeOf(&writer), &writer, result.path) catch return Resolution{ +            .status = .InvalidModuleSpecifier, +            .path = result.path, +            .debug = result.debug, +        }; +          const resolved_path = resolved_path_buf_percent[0..len];          var found: string = ""; @@ -1192,7 +1198,7 @@ pub const ESModule = struct {                              log.addNoteFmt("The key \"{s}\" matched", .{key}) catch unreachable;                          } -                        var result = r.resolveTarget(package_url, target, subpath, pattern); +                        var result = r.resolveTarget(package_url, slice.items(.value)[i], subpath, pattern);                          if (result.status.isUndefined()) {                              did_find_map_entry = true;                              last_map_entry_i = i; 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, | 
