trim correctly (#8388)

Co-authored-by: dave caruso <me@paperdave.net>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
Dylan Conway
2024-01-22 19:57:20 -08:00
committed by GitHub
parent c52e7c57d2
commit 2d1e0dc240
3 changed files with 7 additions and 2 deletions

View File

@@ -1135,6 +1135,7 @@ pub const ExportsMap = struct {
map_data_ranges[i] = key_range;
map_data_entries[i] = this.visit(prop.value.?);
// safe to use "/" on windows. exports in package.json does not use "\\"
if (strings.endsWithComptime(key, "/") or strings.containsChar(key, '*')) {
expansion_keys[expansion_key_i] = Entry.Data.Map.MapEntry{
.value = map_data_entries[i],

View File

@@ -2251,13 +2251,13 @@ pub const Resolver = struct {
fn handleESMResolution(r: *ThisResolver, esm_resolution_: ESModule.Resolution, abs_package_path: string, kind: ast.ImportKind, package_json: *PackageJSON, package_subpath: string) ?MatchResult {
var esm_resolution = esm_resolution_;
if (!((esm_resolution.status == .Inexact or esm_resolution.status == .Exact or esm_resolution.status == .ExactEndsWithStar) and
esm_resolution.path.len > 0 and esm_resolution.path[0] == '/'))
esm_resolution.path.len > 0 and esm_resolution.path[0] == std.fs.path.sep))
return null;
const abs_esm_path: string = brk: {
var parts = [_]string{
abs_package_path,
strings.withoutLeadingSlash(esm_resolution.path),
strings.withoutLeadingPathSeparator(esm_resolution.path),
};
break :brk r.fs.absBuf(&parts, bufs(.esm_absolute_package_path_joined));
};

View File

@@ -698,6 +698,10 @@ pub fn withoutLeadingSlash(this: string) []const u8 {
return std.mem.trimLeft(u8, this, "/");
}
pub fn withoutLeadingPathSeparator(this: string) []const u8 {
return std.mem.trimLeft(u8, this, &.{std.fs.path.sep});
}
pub fn endsWithAny(self: string, str: string) bool {
const end = self[self.len - 1];
for (str) |char| {