From b64ec7926831896f4e43b685891111409de45e85 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Sun, 19 Mar 2023 00:43:07 +0100 Subject: 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". --- cli/args/flags.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'cli/args') 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, pub args: Vec, pub target: Option, + pub include: Vec, } #[derive(Clone, Debug, Eq, PartialEq)] @@ -908,6 +909,20 @@ fn compile_subcommand<'a>() -> Command<'a> { runtime_args(Command::new("compile"), true, false) .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") @@ -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, -- cgit v1.2.3