Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(next/dev): allow devserver args serializable #2446

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/next-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ name = "mod"
harness = false

[features]
default = ["cli"]
cli = []
serializable = []
tokio_console = [
"dep:console-subscriber",
"tokio/tracing",
Expand Down Expand Up @@ -59,7 +62,7 @@ regex = "1.6.0"
tempfile = "3.3.0"
test-generator = "0.3.0"
# sync with chromiumoxide's tungstenite requirement.
tungstenite = "0.17.3" # For matching on errors from chromiumoxide. Keep in
tungstenite = "0.17.3" # For matching on errors from chromiumoxide. Keep in
turbopack-create-test-app = { path = "../turbopack-create-test-app" }

[target.'cfg(unix)'.dev-dependencies]
Expand Down
71 changes: 58 additions & 13 deletions crates/next-dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,104 @@ use turbo_tasks_memory::MemoryBackend;
use turbopack_cli_utils::issue::IssueSeverityCliOption;
use turbopack_core::issue::IssueSeverity;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[derive(Debug)]
#[cfg_attr(feature = "cli", derive(Parser))]
#[cfg_attr(feature = "cli", clap(author, version, about, long_about = None))]
#[cfg_attr(feature = "serializable", derive(serde::Deserialize))]
#[cfg_attr(feature = "serializable", serde(rename_all = "camelCase"))]
pub struct DevServerOptions {
/// The directory of the Next.js application.
/// If no directory is provided, the current directory will be used.
#[clap(value_parser)]
#[cfg_attr(feature = "cli", clap(value_parser))]
#[cfg_attr(feature = "serializable", serde(default))]
dir: Option<PathBuf>,

/// The root directory of the project. Nothing outside of this directory can
/// be accessed. e. g. the monorepo root.
/// If no directory is provided, `dir` will be used.
#[clap(long, value_parser)]
#[cfg_attr(feature = "cli", clap(long, value_parser))]
#[cfg_attr(feature = "serializable", serde(default))]
root: Option<PathBuf>,

/// The port number on which to start the application
#[clap(short, long, value_parser, default_value_t = 3000)]
#[cfg_attr(
feature = "cli",
clap(short, long, value_parser, default_value_t = 3000)
)]
#[cfg_attr(feature = "serializable", serde(default = "default_port"))]
port: u16,

/// Hostname on which to start the application
#[clap(short = 'H', long, value_parser, default_value = "0.0.0.0")]
#[cfg_attr(
feature = "cli",
clap(short = 'H', long, value_parser, default_value = "0.0.0.0")
)]
#[cfg_attr(feature = "serializable", serde(default = "default_host"))]
hostname: IpAddr,

/// Compile all, instead of only compiling referenced assets when their
/// parent asset is requested
#[clap(long)]
#[cfg_attr(feature = "cli", clap(long))]
#[cfg_attr(feature = "serializable", serde(default))]
eager_compile: bool,

/// Don't open the browser automatically when the dev server has started.
#[clap(long)]
#[cfg_attr(feature = "cli", clap(long))]
#[cfg_attr(feature = "serializable", serde(default))]
no_open: bool,

#[clap(short, long)]
#[cfg_attr(feature = "cli", clap(short, long))]
#[cfg_attr(feature = "serializable", serde(default))]
/// Filter by issue severity.
log_level: Option<IssueSeverityCliOption>,

#[clap(long)]
#[cfg_attr(feature = "cli", clap(long))]
#[cfg_attr(feature = "serializable", serde(default))]
/// Show all log messages without limit.
show_all: bool,

#[clap(long)]
#[cfg_attr(feature = "cli", clap(long))]
#[cfg_attr(feature = "serializable", serde(default))]
/// Expand the log details.
log_detail: bool,

// Inherited options from next-dev, need revisit later.
// This is not supported by CLI yet.
#[cfg_attr(feature = "serializable", serde(default))]
allow_retry: bool,
#[cfg_attr(feature = "serializable", serde(default))]
dev: bool,
#[cfg_attr(feature = "serializable", serde(default))]
is_next_dev_command: bool,
#[cfg_attr(feature = "serializable", serde(default))]
server_components_external_packages: Vec<String>,
}

#[cfg(feature = "serializable")]
fn default_port() -> u16 {
3000
}

#[cfg(feature = "serializable")]
fn default_host() -> IpAddr {
IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0))
}

#[cfg(not(feature = "cli"))]
fn main() -> Result<()> {
unimplemented!("Cannot run binary without CLI feature enabled");
}

#[tokio::main]
#[cfg(feature = "cli")]
async fn main() -> Result<()> {
let start = Instant::now();

#[cfg(feature = "tokio_console")]
console_subscriber::init();
register();

let args = Cli::parse();
let args = DevServerOptions::parse();

let dir = args
.dir
Expand Down