summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
authorAndreu Botella <andreu@andreubotella.com>2023-03-19 00:43:07 +0100
committerGitHub <noreply@github.com>2023-03-19 00:43:07 +0100
commitb64ec7926831896f4e43b685891111409de45e85 (patch)
treeb91550f9c21931f7bf691a6c298b64ff63c16041 /cli/args
parenta80d1b6e663bd439bd12b7c65cc1ac017bafb886 (diff)
feat(compile): Enable multiple roots for a standalone module graph (#17663)
This change will enable dynamic imports and web workers to use modules not reachable from the main module, by passing a list of extra side module roots as options to `deno compile`. This can be done by specifying "--include" flag that accepts a file path or a URL. This flag can be specified multiple times, to include several modules. The modules specified with "--include" flag, will be added to the produced "eszip".
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/flags.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 0b1ba8c50..9650b9612 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -83,6 +83,7 @@ pub struct CompileFlags {
pub output: Option<PathBuf>,
pub args: Vec<String>,
pub target: Option<String>,
+ pub include: Vec<String>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -909,6 +910,20 @@ fn compile_subcommand<'a>() -> Command<'a> {
.trailing_var_arg(true)
.arg(script_arg().required(true))
.arg(
+ Arg::new("include")
+ .long("include")
+ .help("UNSTABLE: Additional module to include in the module graph")
+ .long_help(
+ "Includes an additional module in the compiled executable's module \
+ graph. Use this flag if a dynamically imported module or a web worker main \
+ module fails to load in the executable. This flag can be passed multiple \
+ times, to include multiple additional modules.",
+ )
+ .takes_value(true)
+ .multiple_occurrences(true)
+ .value_hint(ValueHint::FilePath),
+ )
+ .arg(
Arg::new("output")
.long("output")
.short('o')
@@ -2486,12 +2501,17 @@ fn compile_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
let source_file = script[0].to_string();
let output = matches.value_of("output").map(PathBuf::from);
let target = matches.value_of("target").map(String::from);
+ let include = match matches.values_of("include") {
+ Some(f) => f.map(String::from).collect(),
+ None => vec![],
+ };
flags.subcommand = DenoSubcommand::Compile(CompileFlags {
source_file,
output,
args,
target,
+ include,
});
}
@@ -6242,6 +6262,7 @@ mod tests {
output: None,
args: vec![],
target: None,
+ include: vec![]
}),
type_check_mode: TypeCheckMode::Local,
..Flags::default()
@@ -6261,6 +6282,7 @@ mod tests {
output: Some(PathBuf::from("colors")),
args: svec!["foo", "bar"],
target: None,
+ include: vec![]
}),
import_map_path: Some("import_map.json".to_string()),
no_remote: true,