summaryrefslogtreecommitdiff
path: root/cli/tools
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/tools
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/tools')
-rw-r--r--cli/tools/bundle.rs3
-rw-r--r--cli/tools/standalone.rs17
2 files changed, 15 insertions, 5 deletions
diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs
index 5a42f834e..9420d9c8f 100644
--- a/cli/tools/bundle.rs
+++ b/cli/tools/bundle.rs
@@ -45,7 +45,8 @@ pub async fn bundle(
log::debug!(">>>>> bundle START");
let ps = ProcState::from_options(cli_options).await?;
let graph =
- create_graph_and_maybe_check(module_specifier.clone(), &ps).await?;
+ create_graph_and_maybe_check(vec![module_specifier.clone()], &ps)
+ .await?;
let mut paths_to_watch: Vec<PathBuf> = graph
.specifiers()
diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs
index f0f53d417..dcd2f5d43 100644
--- a/cli/tools/standalone.rs
+++ b/cli/tools/standalone.rs
@@ -41,6 +41,14 @@ pub async fn compile(
let ps = ProcState::build(flags).await?;
let module_specifier =
resolve_url_or_path(&compile_flags.source_file, ps.options.initial_cwd())?;
+ let module_roots = {
+ let mut vec = Vec::with_capacity(compile_flags.include.len() + 1);
+ vec.push(module_specifier.clone());
+ for side_module in &compile_flags.include {
+ vec.push(resolve_url_or_path(side_module, ps.options.initial_cwd())?);
+ }
+ vec
+ };
let deno_dir = &ps.dir;
let output_path = resolve_compile_executable_output_path(
@@ -49,10 +57,9 @@ pub async fn compile(
)
.await?;
- let graph = Arc::try_unwrap(
- create_graph_and_maybe_check(module_specifier.clone(), &ps).await?,
- )
- .unwrap();
+ let graph =
+ Arc::try_unwrap(create_graph_and_maybe_check(module_roots, &ps).await?)
+ .unwrap();
// at the moment, we don't support npm specifiers in deno_compile, so show an error
error_for_any_npm_specifier(&graph)?;
@@ -351,6 +358,7 @@ mod test {
output: Some(PathBuf::from("./file")),
args: Vec::new(),
target: Some("x86_64-unknown-linux-gnu".to_string()),
+ include: vec![],
},
&std::env::current_dir().unwrap(),
)
@@ -371,6 +379,7 @@ mod test {
output: Some(PathBuf::from("./file")),
args: Vec::new(),
target: Some("x86_64-pc-windows-msvc".to_string()),
+ include: vec![],
},
&std::env::current_dir().unwrap(),
)