Fix --args and handle merging in @server and @client (#4212)

* Pass args after -- to the executable during run and serve

* fix clippy

* switch to accepting a string argument for subcommand compatibility

* Handle merging with `@server` and `@client`

* fix clippy

* fix formatting

* always build into the client package

* fix clippy

* more clippy fixes
This commit is contained in:
Evan Almloff authored and GitHub committed 2025-06-17 18:17:06 -07:00
1 parent 6fcb496fd5
commit 3bf8f09c65
10 files changed
+291 -207

No files matched your search

+25 -3
View File
@@ -1,7 +1,8 @@
use super::{AppBuilder, ServeUpdate, WebServer};
use crate::{
BuildArtifacts, BuildId, BuildMode, BuildTargets, Error, HotpatchModuleCache, Platform, Result,
ServeArgs, TailwindCli, TraceSrc, Workspace,
platform_override::CommandWithPlatformOverrides, BuildArtifacts, BuildId, BuildMode,
BuildTargets, Error, HotpatchModuleCache, Platform, Result, ServeArgs, TailwindCli, TraceSrc,
Workspace,
};
use anyhow::Context;
use dioxus_core::internal::{
@@ -73,6 +74,11 @@ pub(crate) struct AppServer {
pub(crate) proxied_port: Option<u16>,
pub(crate) cross_origin_policy: bool,
// The arguments that should be forwarded to the client app when it is opened
pub(crate) client_args: Vec<String>,
// The arguments that should be forwarded to the server app when it is opened
pub(crate) server_args: Vec<String>,
// Additional plugin-type tools
pub(crate) tw_watcher: tokio::task::JoinHandle<Result<()>>,
}
@@ -93,6 +99,13 @@ impl AppServer {
let force_sequential = args.force_sequential;
let cross_origin_policy = args.cross_origin_policy;
// Find the launch args for the client and server
let split_args = |args: &str| args.split(' ').map(|s| s.to_string()).collect::<Vec<_>>();
let server_args = args.platform_args.with_server_or_shared(|c| &c.args);
let server_args = split_args(server_args);
let client_args = args.platform_args.with_client_or_shared(|c| &c.args);
let client_args = split_args(client_args);
// These come from the args but also might come from the workspace settings
// We opt to use the manually specified args over the workspace settings
let hot_reload = args
@@ -125,7 +138,12 @@ impl AppServer {
let (watcher_tx, watcher_rx) = futures_channel::mpsc::unbounded();
let watcher = create_notify_watcher(watcher_tx.clone(), wsl_file_poll_interval as u64);
let BuildTargets { client, server } = args.targets.into_targets().await?;
let target_args = CommandWithPlatformOverrides {
shared: args.platform_args.shared.targets,
server: args.platform_args.server.map(|s| s.targets),
client: args.platform_args.client.map(|c| c.targets),
};
let BuildTargets { client, server } = target_args.into_targets().await?;
// All servers will end up behind us (the devserver) but on a different port
// This is so we can serve a loading screen as well as devtools without anything particularly fancy
@@ -187,6 +205,8 @@ impl AppServer {
cross_origin_policy,
fullstack,
tw_watcher,
server_args,
client_args,
};
// Only register the hot-reload stuff if we're watching the filesystem
@@ -546,6 +566,7 @@ impl AppServer {
false,
false,
BuildId::SERVER,
&self.server_args,
)
.await?;
}
@@ -560,6 +581,7 @@ impl AppServer {
open_browser,
self.always_on_top,
BuildId::CLIENT,
&self.client_args,
)
.await?;