diff options
author | 2022-03-02 03:06:11 -0800 | |
---|---|---|
committer | 2022-03-02 03:06:11 -0800 | |
commit | c0584c510276616ff7540568b4362c5ea3d8b02d (patch) | |
tree | e4c4a3d6f4e2feea004e8d97b628ef202d641ff9 | |
parent | 87c71207e30db17808014020900ad5c88c8d5ae6 (diff) | |
download | bun-c0584c510276616ff7540568b4362c5ea3d8b02d.tar.gz bun-c0584c510276616ff7540568b4362c5ea3d8b02d.tar.zst bun-c0584c510276616ff7540568b4362c5ea3d8b02d.zip |
add `bun pm cache` and `bun pm cache rm` commands
-rw-r--r-- | src/cli/package_manager_command.zig | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/cli/package_manager_command.zig b/src/cli/package_manager_command.zig index 26af4c5b1..b91b1966b 100644 --- a/src/cli/package_manager_command.zig +++ b/src/cli/package_manager_command.zig @@ -139,6 +139,24 @@ pub const PackageManagerCommand = struct { _ = try pm.lockfile.hasMetaHashChanged(true); Global.exit(0); + } else if (strings.eqlComptime(first, "cache")) { + var dir: [_global.MAX_PATH_BYTES]u8 = undefined; + var fd = pm.getCacheDirectory(); + var outpath = std.os.getFdPath(fd.fd, &dir) catch |err| { + Output.prettyErrorln("{s} getting cache directory", .{@errorName(err)}); + Global.crash(); + }; + + if (pm.options.positionals.len > 0 and strings.eqlComptime(pm.options.positionals[0], "rm")) { + std.fs.deleteTreeAbsolute(outpath) catch |err| { + Output.prettyErrorln("{s} deleting cache directory", .{@errorName(err)}); + Global.crash(); + }; + Output.prettyln("Cache directory deleted:\n {s}", .{outpath}); + Global.exit(0); + } + Output.writer().writeAll(outpath) catch {}; + Global.exit(0); } Output.prettyln( @@ -149,6 +167,8 @@ pub const PackageManagerCommand = struct { \\ bun pm <b>hash<r> generate & print the hash of the current lockfile \\ bun pm <b>hash-string<r> print the string used to hash the lockfile \\ bun pm <b>hash-print<r> print the hash stored in the current lockfile + \\ bun pm <b>cache<r> print the path to the cache folder + \\ bun pm <b>cache rm<r> clear the cache \\ , .{}); |