Skip to content

Commit

Permalink
implement bun outdated (#13461)
Browse files Browse the repository at this point in the history
Co-authored-by: Zack Radisic <[email protected]>
  • Loading branch information
dylan-conway and zackradisic authored Aug 23, 2024
1 parent 8d34846 commit 6415cc3
Show file tree
Hide file tree
Showing 11 changed files with 1,601 additions and 159 deletions.
23 changes: 16 additions & 7 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -813,14 +813,23 @@ pub fn openDirForIteration(dir: std.fs.Dir, path_: []const u8) !std.fs.Dir {
}

pub fn openDirAbsolute(path_: []const u8) !std.fs.Dir {
if (comptime Environment.isWindows) {
const res = try sys.openDirAtWindowsA(invalid_fd, path_, .{ .iterable = true, .can_rename_or_delete = true, .read_only = true }).unwrap();
return res.asDir();
} else {
const fd = try sys.openA(path_, O.DIRECTORY | O.CLOEXEC | O.RDONLY, 0).unwrap();
return fd.asDir();
}
const fd = if (comptime Environment.isWindows)
try sys.openDirAtWindowsA(invalid_fd, path_, .{ .iterable = true, .can_rename_or_delete = true, .read_only = true }).unwrap()
else
try sys.openA(path_, O.DIRECTORY | O.CLOEXEC | O.RDONLY, 0).unwrap();

return fd.asDir();
}

pub fn openDirAbsoluteNotForDeletingOrRenaming(path_: []const u8) !std.fs.Dir {
const fd = if (comptime Environment.isWindows)
try sys.openDirAtWindowsA(invalid_fd, path_, .{ .iterable = true, .can_rename_or_delete = false, .read_only = true }).unwrap()
else
try sys.openA(path_, O.DIRECTORY | O.CLOEXEC | O.RDONLY, 0).unwrap();

return fd.asDir();
}

pub const MimallocArena = @import("./mimalloc_arena.zig").Arena;
pub fn getRuntimeFeatureFlag(comptime flag: [:0]const u8) bool {
return struct {
Expand Down
31 changes: 29 additions & 2 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub const BunxCommand = @import("./cli/bunx_command.zig").BunxCommand;
pub const ExecCommand = @import("./cli/exec_command.zig").ExecCommand;
pub const PatchCommand = @import("./cli/patch_command.zig").PatchCommand;
pub const PatchCommitCommand = @import("./cli/patch_commit_command.zig").PatchCommitCommand;
pub const OutdatedCommand = @import("./cli/outdated_command.zig").OutdatedCommand;

pub const Arguments = struct {
pub fn loader_resolver(in: string) !Api.Loader {
Expand Down Expand Up @@ -1438,6 +1439,8 @@ pub const Command = struct {

RootCommandMatcher.case("exec") => .ExecCommand,

RootCommandMatcher.case("outdated") => .OutdatedCommand,

// These are reserved for future use by Bun, so that someone
// doing `bun deploy` to run a script doesn't accidentally break
// when we add our actual command
Expand All @@ -1452,7 +1455,6 @@ pub const Command = struct {
RootCommandMatcher.case("whoami") => .ReservedCommand,
RootCommandMatcher.case("publish") => .ReservedCommand,
RootCommandMatcher.case("prune") => .ReservedCommand,
RootCommandMatcher.case("outdated") => .ReservedCommand,
RootCommandMatcher.case("list") => .ReservedCommand,
RootCommandMatcher.case("why") => .ReservedCommand,

Expand Down Expand Up @@ -1574,6 +1576,13 @@ pub const Command = struct {
try PatchCommitCommand.exec(ctx);
return;
},
.OutdatedCommand => {
if (comptime bun.fast_debug_build_mode and bun.fast_debug_build_cmd != .OutdatedCommand) unreachable;
const ctx = try Command.init(allocator, log, .OutdatedCommand);

try OutdatedCommand.exec(ctx);
return;
},
.BunxCommand => {
if (comptime bun.fast_debug_build_mode and bun.fast_debug_build_cmd != .BunxCommand) unreachable;
const ctx = try Command.init(allocator, log, .BunxCommand);
Expand Down Expand Up @@ -2141,6 +2150,7 @@ pub const Command = struct {
ExecCommand,
PatchCommand,
PatchCommitCommand,
OutdatedCommand,

/// Used by crash reports.
///
Expand Down Expand Up @@ -2172,6 +2182,7 @@ pub const Command = struct {
.ExecCommand => 'e',
.PatchCommand => 'x',
.PatchCommitCommand => 'z',
.OutdatedCommand => 'o',
};
}

Expand Down Expand Up @@ -2395,6 +2406,9 @@ pub const Command = struct {
, .{});
Output.flush();
},
.OutdatedCommand => {
Install.PackageManager.CommandLineArguments.printHelp(.outdated);
},
else => {
HelpCommand.printWithReason(.explicit);
},
Expand All @@ -2403,7 +2417,16 @@ pub const Command = struct {

pub fn readGlobalConfig(this: Tag) bool {
return switch (this) {
.BunxCommand, .PackageManagerCommand, .InstallCommand, .AddCommand, .RemoveCommand, .UpdateCommand, .PatchCommand, .PatchCommitCommand => true,
.BunxCommand,
.PackageManagerCommand,
.InstallCommand,
.AddCommand,
.RemoveCommand,
.UpdateCommand,
.PatchCommand,
.PatchCommitCommand,
.OutdatedCommand,
=> true,
else => false,
};
}
Expand All @@ -2420,6 +2443,7 @@ pub const Command = struct {
.UpdateCommand,
.PatchCommand,
.PatchCommitCommand,
.OutdatedCommand,
=> true,
else => false,
};
Expand All @@ -2439,6 +2463,7 @@ pub const Command = struct {
.AutoCommand = true,
.RunCommand = true,
.RunAsNodeCommand = true,
.OutdatedCommand = true,
});

pub const always_loads_config: std.EnumArray(Tag, bool) = std.EnumArray(Tag, bool).initDefault(false, .{
Expand All @@ -2452,6 +2477,7 @@ pub const Command = struct {
.PatchCommitCommand = true,
.PackageManagerCommand = true,
.BunxCommand = true,
.OutdatedCommand = true,
});

pub const uses_global_options: std.EnumArray(Tag, bool) = std.EnumArray(Tag, bool).initDefault(true, .{
Expand All @@ -2466,6 +2492,7 @@ pub const Command = struct {
.LinkCommand = false,
.UnlinkCommand = false,
.BunxCommand = false,
.OutdatedCommand = false,
});
};
};
Expand Down
Loading

0 comments on commit 6415cc3

Please sign in to comment.