diff options
author | 2023-07-28 17:40:05 -0700 | |
---|---|---|
committer | 2023-07-28 17:40:05 -0700 | |
commit | 1490cdc4ffd587ce3c0d5091ab2a8851f2a3b419 (patch) | |
tree | b328830f8b9515109e762b28feb0a568ac33e519 | |
parent | 97009a49bddd32a1b6875666739445fd05a8fddf (diff) | |
download | bun-1490cdc4ffd587ce3c0d5091ab2a8851f2a3b419.tar.gz bun-1490cdc4ffd587ce3c0d5091ab2a8851f2a3b419.tar.zst bun-1490cdc4ffd587ce3c0d5091ab2a8851f2a3b419.zip |
Fix assertion failure and possible infinite loop when printing as yarn lock files
-rw-r--r-- | src/install/dependency.zig | 13 | ||||
-rw-r--r-- | src/install/lockfile.zig | 6 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/install/dependency.zig b/src/install/dependency.zig index 8578e998a..3a9ee6b54 100644 --- a/src/install/dependency.zig +++ b/src/install/dependency.zig @@ -257,6 +257,14 @@ pub const Version = struct { return strings.cmpStringsAsc({}, lhs.literal.slice(string_buf), rhs.literal.slice(string_buf)); } + pub fn isLessThanWithTag(string_buf: []const u8, lhs: Dependency.Version, rhs: Dependency.Version) bool { + const tag_order = lhs.tag.cmp(rhs.tag); + if (tag_order != .eq) + return tag_order == .lt; + + return strings.cmpStringsAsc({}, lhs.literal.slice(string_buf), rhs.literal.slice(string_buf)); + } + pub const External = [9]u8; pub fn toVersion( @@ -338,6 +346,11 @@ pub const Version = struct { /// GitHub Repository (via REST API) github = 8, + pub fn cmp(this: Tag, other: Tag) std.math.Order { + // TODO: align with yarn + return std.math.order(@intFromEnum(this), @intFromEnum(other)); + } + pub inline fn isNPM(this: Tag) bool { return @intFromEnum(this) < 3; } diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index c224cc765..dbbb22300 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -942,8 +942,8 @@ pub const Printer = struct { Global.crash(); }, .not_found => { - Output.prettyErrorln("<r><red>lockfile not found:<r> {s}", .{ - std.mem.sliceAsBytes(lockfile_path), + Output.prettyErrorln("<r><red>lockfile not found:<r> {}", .{ + strings.QuotedFormatter{ .text = std.mem.sliceAsBytes(lockfile_path) }, }); Global.crash(); }, @@ -1234,7 +1234,7 @@ pub const Printer = struct { } var dependency_versions = requested_version_start[0..j]; - if (dependency_versions.len > 1) std.sort.insertion(Dependency.Version, dependency_versions, string_buf, Dependency.Version.isLessThan); + if (dependency_versions.len > 1) std.sort.insertion(Dependency.Version, dependency_versions, string_buf, Dependency.Version.isLessThanWithTag); try requested_versions.put(i, dependency_versions); } } |