1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
const Command = @import("../cli.zig").Command;
const PackageManager = @import("../install/install.zig").PackageManager;
const ComamndLineArguments = PackageManager.CommandLineArguments;
const std = @import("std");
const strings = @import("strings");
const Global = @import("../global.zig").Global;
const Output = @import("../global.zig").Output;
const Fs = @import("../fs.zig");
const Path = @import("../resolver/resolve_path.zig");
pub const PackageManagerCommand = struct {
pub fn printHelp(_: std.mem.Allocator) void {}
pub fn printHash(ctx: Command.Context, lockfile_: []const u8) !void {
@setCold(true);
var lockfile_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
@memcpy(&lockfile_buffer, lockfile_.ptr, lockfile_.len);
lockfile_buffer[lockfile_.len] = 0;
var lockfile = lockfile_buffer[0..lockfile_.len :0];
var pm = try PackageManager.init(ctx, null, &PackageManager.install_params);
const load_lockfile = pm.lockfile.loadFromDisk(ctx.allocator, ctx.log, lockfile);
if (load_lockfile == .not_found) {
if (pm.options.log_level != .silent)
Output.prettyError("Lockfile not found", .{});
Global.exit(1);
}
if (load_lockfile == .err) {
if (pm.options.log_level != .silent)
Output.prettyError("Error loading lockfile: {s}", .{@errorName(load_lockfile.err.value)});
Global.exit(1);
}
Output.flush();
Output.disableBuffering();
try Output.writer().print("{}", .{load_lockfile.ok.fmtMetaHash()});
Output.enableBuffering();
Global.exit(0);
}
pub fn exec(ctx: Command.Context) !void {
var args = try std.process.argsAlloc(ctx.allocator);
args = args[1..];
var pm = try PackageManager.init(ctx, null, &PackageManager.install_params);
var first: []const u8 = if (pm.options.positionals.len > 0) pm.options.positionals[0] else "";
if (strings.eqlComptime(first, "pm")) {
if (pm.options.positionals.len > 1) {
pm.options.positionals = pm.options.positionals[1..];
} else {
return;
}
}
first = pm.options.positionals[0];
if (pm.options.global) {
try pm.setupGlobalDir(&ctx);
}
if (strings.eqlComptime(first, "bin")) {
var output_path = Path.joinAbs(Fs.FileSystem.instance.top_level_dir, .auto, std.mem.span(pm.options.bin_path));
Output.prettyln("{s}", .{output_path});
if (Output.stdout_descriptor_type == .terminal) {
Output.prettyln("\n", .{});
}
if (pm.options.global) {
warner: {
if (Output.enable_ansi_colors_stderr) {
if (std.os.getenvZ("PATH")) |path| {
var path_splitter = std.mem.split(u8, path, ":");
while (path_splitter.next()) |entry| {
if (strings.eql(entry, output_path)) {
break :warner;
}
}
Output.prettyErrorln("\n<r><yellow>warn<r>: not in $PATH\n", .{});
}
}
}
}
Output.flush();
return;
} else if (strings.eqlComptime(first, "hash")) {
const load_lockfile = pm.lockfile.loadFromDisk(ctx.allocator, ctx.log, "bun.lockb");
if (load_lockfile == .not_found) {
if (pm.options.log_level != .silent)
Output.prettyError("Lockfile not found", .{});
Global.exit(1);
}
if (load_lockfile == .err) {
if (pm.options.log_level != .silent)
Output.prettyError("Error loading lockfile: {s}", .{@errorName(load_lockfile.err.value)});
Global.exit(1);
}
_ = try pm.lockfile.hasMetaHashChanged(false);
Output.flush();
Output.disableBuffering();
try Output.writer().print("{}", .{load_lockfile.ok.fmtMetaHash()});
Output.enableBuffering();
Global.exit(0);
} else if (strings.eqlComptime(first, "hash-print")) {
const load_lockfile = pm.lockfile.loadFromDisk(ctx.allocator, ctx.log, "bun.lockb");
if (load_lockfile == .not_found) {
if (pm.options.log_level != .silent)
Output.prettyError("Lockfile not found", .{});
Global.exit(1);
}
if (load_lockfile == .err) {
if (pm.options.log_level != .silent)
Output.prettyError("Error loading lockfile: {s}", .{@errorName(load_lockfile.err.value)});
Global.exit(1);
}
Output.flush();
Output.disableBuffering();
try Output.writer().print("{}", .{load_lockfile.ok.fmtMetaHash()});
Output.enableBuffering();
Global.exit(0);
} else if (strings.eqlComptime(first, "hash-string")) {
const load_lockfile = pm.lockfile.loadFromDisk(ctx.allocator, ctx.log, "bun.lockb");
if (load_lockfile == .not_found) {
if (pm.options.log_level != .silent)
Output.prettyError("Lockfile not found", .{});
Global.exit(1);
}
if (load_lockfile == .err) {
if (pm.options.log_level != .silent)
Output.prettyError("Error loading lockfile: {s}", .{@errorName(load_lockfile.err.value)});
Global.exit(1);
}
_ = try pm.lockfile.hasMetaHashChanged(true);
Global.exit(0);
}
}
};
|