diff options
author | 2022-02-05 19:02:13 -0800 | |
---|---|---|
committer | 2022-02-05 19:02:13 -0800 | |
commit | d8f174e54c959c2cc08c5d0295867f81a984613e (patch) | |
tree | 9694e06e17fcd7d81482a9a4aa3f5c7e5fc84666 | |
parent | 51abe58a1a8873205f0474cde851cfab00951cb3 (diff) | |
download | bun-d8f174e54c959c2cc08c5d0295867f81a984613e.tar.gz bun-d8f174e54c959c2cc08c5d0295867f81a984613e.tar.zst bun-d8f174e54c959c2cc08c5d0295867f81a984613e.zip |
Always try to load bunfig.toml for `install`, `dev`, `bun`, `test`
-rw-r--r-- | src/cli.zig | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/cli.zig b/src/cli.zig index 16ed1f5d1..77cca548f 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -233,12 +233,23 @@ pub const Arguments = struct { opts.absolute_working_dir = cwd; if (comptime Command.Tag.loads_config.get(cmd)) { - if (args.option("--config")) |config_path__| { + load_config: { var config_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var config_path_ = config_path__; - if (config_path_.len == 0) { + + var config_path_: []const u8 = ""; + if (args.option("--config")) |config_path__| { + config_path_ = config_path__; + } + var auto_loaded: bool = false; + if (config_path_.len == 0 and (args.option("--config") != null or Command.Tag.always_loads_config.get(cmd))) { config_path_ = "bunfig.toml"; + auto_loaded = true; + } + + if (config_path_.len == 0) { + break :load_config; } + var config_path: [:0]u8 = undefined; if (config_path_[0] == '/') { @memcpy(&config_buf, config_path_.ptr, config_path_.len); @@ -257,6 +268,7 @@ pub const Arguments = struct { } var config_file = std.fs.openFileAbsoluteZ(config_path, .{ .read = true }) catch |err| { + if (auto_loaded) break :load_config; Output.prettyErrorln("<r><red>error<r>: {s} opening config \"{s}\"", .{ @errorName(err), std.mem.span(config_path), @@ -265,6 +277,7 @@ pub const Arguments = struct { std.os.exit(1); }; var contents = config_file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch |err| { + if (auto_loaded) break :load_config; Output.prettyErrorln("<r><red>error<r>: {s} reading config \"{s}\"", .{ @errorName(err), std.mem.span(config_path), @@ -1126,6 +1139,15 @@ pub const Command = struct { }); pub const loads_config = cares_about_bun_file; + pub const always_loads_config: std.EnumArray(Tag, bool) = std.EnumArray(Tag, bool).initDefault(false, .{ + .BuildCommand = true, + .BunCommand = true, + .DevCommand = true, + .TestCommand = true, + .InstallCommand = true, + .AddCommand = true, + .RemoveCommand = true, + }); pub const uses_global_options: std.EnumArray(Tag, bool) = std.EnumArray(Tag, bool).initDefault(true, .{ .CreateCommand = false, |