aboutsummaryrefslogtreecommitdiff
path: root/src/install/resolution.zig
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/install/resolution.zig47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/install/resolution.zig b/src/install/resolution.zig
index 23f3bc5c0..84d43ff1a 100644
--- a/src/install/resolution.zig
+++ b/src/install/resolution.zig
@@ -15,6 +15,14 @@ pub const Resolution = extern struct {
_padding: [7]u8 = .{0} ** 7,
value: Value = .{ .uninitialized = {} },
+ /// Use like Resolution.init(.{ .npm = VersionedURL{ ... } })
+ pub inline fn init(value: anytype) Resolution {
+ return Resolution{
+ .tag = @field(Tag, @typeInfo(@TypeOf(value)).Struct.fields[0].name),
+ .value = Value.init(value),
+ };
+ }
+
pub fn order(
lhs: *const Resolution,
rhs: *const Resolution,
@@ -107,18 +115,22 @@ pub const Resolution = extern struct {
}),
.root => Value.init(.{ .root = {} }),
else => {
- std.debug.panic("Internal error: unexpected resolution tag:,) {}", .{this.tag});
+ std.debug.panic("Internal error: unexpected resolution tag: {}", .{this.tag});
},
},
};
}
- pub fn fmt(this: *const Resolution, buf: []const u8) Formatter {
- return Formatter{ .resolution = this, .buf = buf };
+ pub fn fmt(this: *const Resolution, string_bytes: []const u8) Formatter {
+ return Formatter{ .resolution = this, .buf = string_bytes };
}
- pub fn fmtURL(this: *const Resolution, options: *const PackageManager.Options, buf: []const u8) URLFormatter {
- return URLFormatter{ .resolution = this, .buf = buf, .options = options };
+ pub fn fmtURL(this: *const Resolution, options: *const PackageManager.Options, string_bytes: []const u8) URLFormatter {
+ return URLFormatter{ .resolution = this, .buf = string_bytes, .options = options };
+ }
+
+ pub fn fmtForDebug(this: *const Resolution, string_bytes: []const u8) DebugFormatter {
+ return DebugFormatter{ .resolution = this, .buf = string_bytes };
}
pub fn eql(
@@ -225,6 +237,31 @@ pub const Resolution = extern struct {
}
};
+ pub const DebugFormatter = struct {
+ resolution: *const Resolution,
+ buf: []const u8,
+
+ pub fn format(formatter: DebugFormatter, comptime layout: []const u8, opts: std.fmt.FormatOptions, writer: anytype) !void {
+ try writer.writeAll("Resolution{ .");
+ try writer.writeAll(std.enums.tagName(Tag, formatter.resolution.tag) orelse "invalid");
+ try writer.writeAll(" = ");
+ switch (formatter.resolution.tag) {
+ .npm => try formatter.resolution.value.npm.version.fmt(formatter.buf).format(layout, opts, writer),
+ .local_tarball => try writer.writeAll(formatter.resolution.value.local_tarball.slice(formatter.buf)),
+ .folder => try writer.writeAll(formatter.resolution.value.folder.slice(formatter.buf)),
+ .remote_tarball => try writer.writeAll(formatter.resolution.value.remote_tarball.slice(formatter.buf)),
+ .git => try formatter.resolution.value.git.formatAs("git+", formatter.buf, layout, opts, writer),
+ .github => try formatter.resolution.value.github.formatAs("github:", formatter.buf, layout, opts, writer),
+ .gitlab => try formatter.resolution.value.gitlab.formatAs("gitlab:", formatter.buf, layout, opts, writer),
+ .workspace => try std.fmt.format(writer, "workspace:{s}", .{formatter.resolution.value.workspace.slice(formatter.buf)}),
+ .symlink => try std.fmt.format(writer, "link:{s}", .{formatter.resolution.value.symlink.slice(formatter.buf)}),
+ .single_file_module => try std.fmt.format(writer, "module:{s}", .{formatter.resolution.value.single_file_module.slice(formatter.buf)}),
+ else => try writer.writeAll("{}"),
+ }
+ try writer.writeAll(" }");
+ }
+ };
+
pub const Value = extern union {
uninitialized: void,
root: void,