aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-17 19:20:39 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-17 19:20:39 -0700
commit05cb5bb659a7213fc94c67d5836a9f9fb1517a30 (patch)
treee0501e50f622f81426e284a69ed08ec0fb2f7d49 /src
parentdec5b07782d80e972885df2a750ffb76ef05a884 (diff)
downloadbun-05cb5bb659a7213fc94c67d5836a9f9fb1517a30.tar.gz
bun-05cb5bb659a7213fc94c67d5836a9f9fb1517a30.tar.zst
bun-05cb5bb659a7213fc94c67d5836a9f9fb1517a30.zip
Make `bun dev` CLI flags only show in --help for `bun dev --help`
This impacts: --disable-bun.js --disable-react-fast-refresh --bunfile <STR> --server-bunfile <STR> --public-dir <STR> --disable-hmr --use <STR>
Diffstat (limited to 'src')
-rw-r--r--src/cli.zig156
1 files changed, 78 insertions, 78 deletions
diff --git a/src/cli.zig b/src/cli.zig
index 2a368fc39..8ba2b4fd7 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -143,15 +143,10 @@ pub const Arguments = struct {
pub const ParamType = clap.Param(clap.Help);
- const public_params = [_]ParamType{
- clap.parseParam("--use <STR> Choose a framework, e.g. \"--use next\". It checks first for a package named \"bun-framework-packagename\" and then \"packagename\".") catch unreachable,
+ const shared_public_params = [_]ParamType{
clap.parseParam("-b, --bun Force a script or package to use Bun.js instead of Node.js (via symlinking node)") catch unreachable,
- clap.parseParam("--bunfile <STR> Use a .bun file (default: node_modules.bun)") catch unreachable,
- clap.parseParam("--server-bunfile <STR> Use a .server.bun file (default: node_modules.server.bun)") catch unreachable,
clap.parseParam("--cwd <STR> Absolute path to resolve files & entry points from. This just changes the process' cwd.") catch unreachable,
clap.parseParam("-c, --config <PATH>? Config file to load bun from (e.g. -c bunfig.toml") catch unreachable,
- clap.parseParam("--disable-react-fast-refresh Disable React Fast Refresh") catch unreachable,
- clap.parseParam("--disable-hmr Disable Hot Module Reloading (disables fast refresh too) in bun dev") catch unreachable,
clap.parseParam("--extension-order <STR>... defaults to: .tsx,.ts,.jsx,.js,.json ") catch unreachable,
clap.parseParam("--jsx-factory <STR> Changes the function called when compiling JSX elements using the classic JSX runtime") catch unreachable,
clap.parseParam("--jsx-fragment <STR> Changes the function called when compiling JSX fragments") catch unreachable,
@@ -163,8 +158,6 @@ pub const Arguments = struct {
clap.parseParam("--no-summary Don't print a summary (when generating .bun") catch unreachable,
clap.parseParam("-v, --version Print version and exit") catch unreachable,
clap.parseParam("--platform <STR> \"bun\" or \"browser\" or \"node\", used when building or bundling") catch unreachable,
- // clap.parseParam("--production [not implemented] generate production code") catch unreachable,
- clap.parseParam("--public-dir <STR> Top-level directory for .html files, fonts or anything external. Defaults to \"<cwd>/public\", to match create-react-app and Next.js") catch unreachable,
clap.parseParam("--tsconfig-override <STR> Load tsconfig from path instead of cwd/tsconfig.json") catch unreachable,
clap.parseParam("-d, --define <STR>... Substitute K:V while parsing, e.g. --define process.env.NODE_ENV:\"development\". Values are parsed as JSON.") catch unreachable,
clap.parseParam("-e, --external <STR>... Exclude module from transpilation (can use * wildcards). ex: -e react") catch unreachable,
@@ -172,6 +165,12 @@ pub const Arguments = struct {
clap.parseParam("-l, --loader <STR>... Parse files with .ext:loader, e.g. --loader .js:jsx. Valid loaders: jsx, js, json, tsx, ts, css") catch unreachable,
clap.parseParam("-u, --origin <STR> Rewrite import URLs to start with --origin. Default: \"\"") catch unreachable,
clap.parseParam("-p, --port <STR> Port to serve bun's dev server on. Default: \"3000\"") catch unreachable,
+ clap.parseParam("<POS>... ") catch unreachable,
+ };
+
+ // note: we are keeping --port and --origin as it can be reused for bun
+ // build and elsewhere
+ pub const not_bun_dev_flags = [_]ParamType{
clap.parseParam("--hot Enable auto reload in bun's JavaScript runtime") catch unreachable,
clap.parseParam("--watch Automatically restart bun's JavaScript runtime on file change") catch unreachable,
clap.parseParam("--no-install Disable auto install in bun's JavaScript runtime") catch unreachable,
@@ -180,15 +179,25 @@ pub const Arguments = struct {
clap.parseParam("--prefer-offline Skip staleness checks for packages in bun's JavaScript runtime and resolve from disk") catch unreachable,
clap.parseParam("--prefer-latest Use the latest matching versions of packages in bun's JavaScript runtime, always checking npm") catch unreachable,
clap.parseParam("--silent Don't repeat the command for bun run") catch unreachable,
- clap.parseParam("<POS>... ") catch unreachable,
};
+ const public_params = shared_public_params ++ not_bun_dev_flags;
+
const debug_params = [_]ParamType{
clap.parseParam("--dump-environment-variables Dump environment variables from .env and process as JSON and quit. Useful for debugging") catch unreachable,
clap.parseParam("--dump-limits Dump system limits. Useful for debugging") catch unreachable,
- clap.parseParam("--disable-bun.js Disable bun.js from loading in the dev server") catch unreachable,
};
+ pub const dev_params = [_]ParamType{
+ clap.parseParam("--disable-bun.js Disable bun.js from loading in the dev server") catch unreachable,
+ clap.parseParam("--disable-react-fast-refresh Disable React Fast Refresh") catch unreachable,
+ clap.parseParam("--bunfile <STR> Use a .bun file (default: node_modules.bun)") catch unreachable,
+ clap.parseParam("--server-bunfile <STR> Use a .server.bun file (default: node_modules.server.bun)") catch unreachable,
+ clap.parseParam("--public-dir <STR> Top-level directory for .html files, fonts or anything external. Defaults to \"<cwd>/public\", to match create-react-app and Next.js") catch unreachable,
+ clap.parseParam("--disable-hmr Disable Hot Module Reloading (disables fast refresh too) in bun dev") catch unreachable,
+ clap.parseParam("--use <STR> Choose a framework, e.g. \"--use next\". It checks first for a package named \"bun-framework-packagename\" and then \"packagename\".") catch unreachable,
+ } ++ shared_public_params ++ debug_params;
+
pub const params = public_params ++ debug_params;
const build_only_params = [_]ParamType{
@@ -428,16 +437,10 @@ pub const Arguments = struct {
// we never actually supported inject.
// opts.inject = args.options("--inject");
opts.extension_order = args.options("--extension-order");
- if (args.flag("--hot")) {
- ctx.debug.hot_reload = .hot;
- } else if (args.flag("--watch")) {
- ctx.debug.hot_reload = .watch;
- bun.auto_reload_on_crash = true;
- }
+
ctx.passthrough = args.remaining();
opts.no_summary = args.flag("--no-summary");
- opts.disable_hmr = args.flag("--disable-hmr");
if (cmd != .DevCommand) {
const preloads = args.options("--preload");
@@ -451,7 +454,6 @@ pub const Arguments = struct {
}
}
- ctx.debug.silent = args.flag("--silent");
if (opts.port != null and opts.origin == null) {
opts.origin = try std.fmt.allocPrint(allocator, "http://localhost:{d}/", .{opts.port.?});
}
@@ -467,33 +469,8 @@ pub const Arguments = struct {
}
ctx.debug.dump_environment_variables = args.flag("--dump-environment-variables");
- ctx.debug.fallback_only = ctx.debug.fallback_only or args.flag("--disable-bun.js");
ctx.debug.dump_limits = args.flag("--dump-limits");
- ctx.debug.offline_mode_setting = if (args.flag("--prefer-offline"))
- Bunfig.OfflineMode.offline
- else if (args.flag("--prefer-latest"))
- Bunfig.OfflineMode.latest
- else
- Bunfig.OfflineMode.online;
-
- if (args.flag("--no-install")) {
- ctx.debug.global_cache = .disable;
- } else if (args.flag("-i")) {
- ctx.debug.global_cache = .fallback;
- } else if (args.option("--install")) |enum_value| {
- // -i=auto --install=force, --install=disable
- if (options.GlobalCache.Map.get(enum_value)) |result| {
- ctx.debug.global_cache = result;
- // -i, --install
- } else if (enum_value.len == 0) {
- ctx.debug.global_cache = options.GlobalCache.force;
- } else {
- Output.prettyErrorln("Invalid value for --install: \"{s}\". Must be either \"auto\", \"fallback\", \"force\", or \"disable\"\n", .{enum_value});
- Global.exit(1);
- }
- }
-
// var output_dir = args.option("--outdir");
var output_dir: ?string = null;
const production = false;
@@ -587,11 +564,19 @@ pub const Arguments = struct {
var jsx_runtime = args.option("--jsx-runtime");
var jsx_production = args.flag("--jsx-production");
const react_fast_refresh = switch (comptime cmd) {
- .BuildCommand, .DevCommand => !(args.flag("--disable-react-fast-refresh") or jsx_production),
+ .DevCommand => !(args.flag("--disable-react-fast-refresh") or jsx_production),
else => true,
};
- if (comptime Command.Tag.cares_about_bun_file.get(cmd)) {
+ if (comptime cmd == .DevCommand) {
+ ctx.debug.fallback_only = ctx.debug.fallback_only or args.flag("--disable-bun.js");
+ opts.disable_hmr = args.flag("--disable-hmr");
+ if (args.option("--public-dir")) |public_dir| {
+ if (public_dir.len > 0) {
+ opts.router = Api.RouteConfig{ .extensions = &.{}, .dir = &.{}, .static_dir = public_dir };
+ }
+ }
+
opts.node_modules_bundle_path = args.option("--bunfile") orelse opts.node_modules_bundle_path orelse brk: {
const node_modules_bundle_path_absolute = resolve_path.joinAbs(cwd, .auto, "node_modules.bun");
@@ -603,20 +588,46 @@ pub const Arguments = struct {
break :brk std.fs.realpathAlloc(allocator, node_modules_bundle_path_absolute) catch null;
};
- }
- switch (comptime cmd) {
- .AutoCommand,
- .DevCommand,
- .BuildCommand,
- => {
- if (args.option("--public-dir")) |public_dir| {
- if (public_dir.len > 0) {
- opts.router = Api.RouteConfig{ .extensions = &.{}, .dir = &.{}, .static_dir = public_dir };
- }
+ if (args.option("--use")) |entry| {
+ opts.framework = Api.FrameworkConfig{
+ .package = entry,
+ .development = !production,
+ };
+ }
+ } else {
+ if (args.flag("--hot")) {
+ ctx.debug.hot_reload = .hot;
+ } else if (args.flag("--watch")) {
+ ctx.debug.hot_reload = .watch;
+ bun.auto_reload_on_crash = true;
+ }
+
+ ctx.debug.offline_mode_setting = if (args.flag("--prefer-offline"))
+ Bunfig.OfflineMode.offline
+ else if (args.flag("--prefer-latest"))
+ Bunfig.OfflineMode.latest
+ else
+ Bunfig.OfflineMode.online;
+
+ if (args.flag("--no-install")) {
+ ctx.debug.global_cache = .disable;
+ } else if (args.flag("-i")) {
+ ctx.debug.global_cache = .fallback;
+ } else if (args.option("--install")) |enum_value| {
+ // -i=auto --install=force, --install=disable
+ if (options.GlobalCache.Map.get(enum_value)) |result| {
+ ctx.debug.global_cache = result;
+ // -i, --install
+ } else if (enum_value.len == 0) {
+ ctx.debug.global_cache = options.GlobalCache.force;
+ } else {
+ Output.prettyErrorln("Invalid value for --install: \"{s}\". Must be either \"auto\", \"fallback\", \"force\", or \"disable\"\n", .{enum_value});
+ Global.exit(1);
}
- },
- else => {},
+ }
+
+ ctx.debug.silent = args.flag("--silent");
}
// const ResolveMatcher = strings.ExactSizeMatcher(8);
@@ -697,13 +708,6 @@ pub const Arguments = struct {
}
}
- if (args.option("--use")) |entry| {
- opts.framework = Api.FrameworkConfig{
- .package = entry,
- .development = !production,
- };
- }
-
if (cmd == .BuildCommand) {
if (opts.entry_points.len == 0 and opts.framework == null and opts.node_modules_bundle_path == null) {
return error.MissingEntryPoint;
@@ -1513,6 +1517,7 @@ pub const Command = struct {
return &comptime switch (cmd) {
Command.Tag.BuildCommand => Arguments.build_params,
Command.Tag.TestCommand => Arguments.test_params,
+ Command.Tag.DevCommand => Arguments.dev_params,
else => Arguments.params,
};
}
@@ -1531,24 +1536,19 @@ pub const Command = struct {
};
}
- pub const cares_about_bun_file: std.EnumArray(Tag, bool) = std.EnumArray(Tag, bool).initDefault(false, .{
- .AutoCommand = true,
- .BuildCommand = false,
+ pub const loads_config: std.EnumArray(Tag, bool) = std.EnumArray(Tag, bool).initDefault(false, .{
+ .BuildCommand = true,
.DevCommand = true,
- .RunCommand = true,
.TestCommand = true,
+ .InstallCommand = true,
+ .AddCommand = true,
+ .RemoveCommand = true,
+ .PackageManagerCommand = true,
+ .BunxCommand = true,
+ .AutoCommand = true,
+ .RunCommand = true,
});
- pub const loads_config = brk: {
- var cares = cares_about_bun_file;
- cares.set(.InstallCommand, true);
- cares.set(.AddCommand, true);
- cares.set(.RemoveCommand, true);
- cares.set(.LinkCommand, true);
- cares.set(.UnlinkCommand, true);
- cares.set(.BunxCommand, true);
- break :brk cares;
- };
pub const always_loads_config: std.EnumArray(Tag, bool) = std.EnumArray(Tag, bool).initDefault(false, .{
.BuildCommand = true,
.DevCommand = true,