turbopack_cli/
arguments.rs

1use std::{
2    net::IpAddr,
3    path::{Path, PathBuf},
4};
5
6use clap::{Args, Parser, ValueEnum};
7use serde::{Deserialize, Serialize};
8use turbo_tasks::{NonLocalValue, TaskInput, trace::TraceRawVcs};
9use turbopack_cli_utils::issue::IssueSeverityCliOption;
10
11#[derive(Debug, Parser)]
12#[clap(author, version, about, long_about = None)]
13pub enum Arguments {
14    Build(BuildArguments),
15    Dev(DevArguments),
16}
17
18impl Arguments {
19    /// The directory of the application. see [CommonArguments]::dir
20    pub fn dir(&self) -> Option<&Path> {
21        match self {
22            Arguments::Build(args) => args.common.dir.as_deref(),
23            Arguments::Dev(args) => args.common.dir.as_deref(),
24        }
25    }
26}
27
28#[derive(
29    Copy,
30    Clone,
31    Debug,
32    ValueEnum,
33    PartialEq,
34    Eq,
35    Serialize,
36    Deserialize,
37    Hash,
38    TaskInput,
39    NonLocalValue,
40    TraceRawVcs,
41)]
42pub enum Target {
43    Browser,
44    Node,
45}
46
47#[derive(Debug, Args, Clone)]
48pub struct CommonArguments {
49    /// The entrypoints of the project. Resolved relative to the project's
50    /// directory (`--dir`).
51    #[clap(value_parser)]
52    pub entries: Option<Vec<String>>,
53
54    /// The directory of the application.
55    /// If no directory is provided, the current directory will be used.
56    #[clap(short, long, value_parser)]
57    pub dir: Option<PathBuf>,
58
59    /// The root directory of the project. Nothing outside of this directory can
60    /// be accessed. e. g. the monorepo root.
61    /// If no directory is provided, `dir` will be used.
62    #[clap(long, value_parser)]
63    pub root: Option<PathBuf>,
64
65    /// Filter by issue severity.
66    #[clap(short, long)]
67    pub log_level: Option<IssueSeverityCliOption>,
68
69    /// Show all log messages without limit.
70    #[clap(long)]
71    pub show_all: bool,
72
73    /// Expand the log details.
74    #[clap(long)]
75    pub log_detail: bool,
76
77    /// Whether to enable full task stats recording in Turbo Engine.
78    #[clap(long)]
79    pub full_stats: bool,
80
81    // Enable experimental garbage collection with the provided memory limit in
82    // MB.
83    // #[clap(long)]
84    // pub memory_limit: Option<usize>,
85    /// Whether to build for the `browser` or `node``
86    #[clap(long)]
87    pub target: Option<Target>,
88}
89
90#[derive(Debug, Args)]
91#[clap(author, version, about, long_about = None)]
92pub struct DevArguments {
93    #[clap(flatten)]
94    pub common: CommonArguments,
95
96    /// The port number on which to start the application
97    /// Note: setting env PORT allows to configure port without explicit cli
98    /// args. However, this is temporary measure to conform with existing
99    /// next.js devserver and can be removed in the future.
100    #[clap(short, long, value_parser, default_value_t = 3000, env = "PORT")]
101    pub port: u16,
102
103    /// Hostname on which to start the application
104    #[clap(short = 'H', long, value_parser, default_value = "0.0.0.0")]
105    pub hostname: IpAddr,
106
107    /// Compile all, instead of only compiling referenced assets when their
108    /// parent asset is requested
109    #[clap(long)]
110    pub eager_compile: bool,
111
112    /// Don't open the browser automatically when the dev server has started.
113    #[clap(long)]
114    pub no_open: bool,
115
116    // ==
117    // = Inherited options from next-dev, need revisit later.
118    // ==
119    /// If port is not explicitly specified, use different port if it's already
120    /// in use.
121    #[clap(long)]
122    pub allow_retry: bool,
123}
124
125#[derive(Debug, Args)]
126#[clap(author, version, about, long_about = None)]
127pub struct BuildArguments {
128    #[clap(flatten)]
129    pub common: CommonArguments,
130
131    /// Don't generate sourcemaps.
132    #[clap(long)]
133    pub no_sourcemap: bool,
134
135    /// Don't minify build output.
136    #[clap(long)]
137    pub no_minify: bool,
138
139    /// Drop the `TurboTasks` object upon exit. By default we intentionally leak this memory, as
140    /// we're about to exit the process anyways, but that can cause issues with valgrind or other
141    /// leak detectors.
142    #[clap(long, hide = true)]
143    pub force_memory_cleanup: bool,
144}