summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
authorWilliam Tetlow <9057181+williamtetlow@users.noreply.github.com>2022-02-15 12:33:46 +0000
committerGitHub <noreply@github.com>2022-02-15 18:03:46 +0530
commit7b893bd57f2f013c4a11e1e9f0ba435a3cfc96c0 (patch)
tree41bc082445edd7c18ec2586050db110a8393c747 /cli/main.rs
parent760f4c9e2427e87815a8e59b0807693c8dcb623a (diff)
feat(cli): Replace bundling with eszip in deno compile (#13563)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs84
1 files changed, 41 insertions, 43 deletions
diff --git a/cli/main.rs b/cli/main.rs
index f8c8e695a..ca6b36f0a 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -415,23 +415,14 @@ async fn compile_command(
"An executable name was not provided. One could not be inferred from the URL. Aborting.",
))?;
- let graph =
- create_graph_and_maybe_check(module_specifier.clone(), &ps, debug).await?;
-
- let source = (graph.as_ref().modules().len() == 1)
- .then(|| {
- let root_module = graph.as_ref().modules()[0];
- match root_module.media_type {
- MediaType::JavaScript if root_module.maybe_source.is_some() => {
- Some(Ok(root_module.maybe_source.clone().unwrap().to_string()))
- }
- _ => None,
- }
- })
- .flatten()
- .unwrap_or_else(|| {
- bundle_module_graph(graph.as_ref(), &ps, &ps.flags).map(|r| r.0)
- })?;
+ let graph = Arc::try_unwrap(
+ create_graph_and_maybe_check(module_specifier.clone(), &ps, debug).await?,
+ )
+ .map_err(|_| {
+ generic_error("There should only be one reference to ModuleGraph")
+ })?;
+
+ let eszip = eszip::EszipV2::from_graph(graph, Default::default())?;
info!(
"{} {}",
@@ -446,7 +437,8 @@ async fn compile_command(
let final_bin = tools::standalone::create_standalone_binary(
original_binary,
- source,
+ eszip,
+ module_specifier.clone(),
run_flags,
)?;
@@ -1430,34 +1422,40 @@ pub fn main() {
colors::enable_ansi(); // For Windows 10
let args: Vec<String> = env::args().collect();
- let standalone_res = match standalone::extract_standalone(args.clone()) {
- Ok(Some((metadata, bundle))) => {
- run_basic(standalone::run(bundle, metadata))
- }
- Ok(None) => Ok(()),
- Err(err) => Err(err),
- };
- // TODO(bartlomieju): doesn't handle exit code set by the runtime properly
- unwrap_or_exit(standalone_res);
-
- let flags = match flags::flags_from_vec(args) {
- Ok(flags) => flags,
- Err(err @ clap::Error { .. })
- if err.kind == clap::ErrorKind::DisplayHelp
- || err.kind == clap::ErrorKind::DisplayVersion =>
- {
- err.print().unwrap();
- std::process::exit(0);
+
+ let exit_code = async move {
+ let standalone_res =
+ match standalone::extract_standalone(args.clone()).await {
+ Ok(Some((metadata, eszip))) => standalone::run(eszip, metadata).await,
+ Ok(None) => Ok(()),
+ Err(err) => Err(err),
+ };
+ // TODO(bartlomieju): doesn't handle exit code set by the runtime properly
+ unwrap_or_exit(standalone_res);
+
+ let flags = match flags::flags_from_vec(args) {
+ Ok(flags) => flags,
+ Err(err @ clap::Error { .. })
+ if err.kind == clap::ErrorKind::DisplayHelp
+ || err.kind == clap::ErrorKind::DisplayVersion =>
+ {
+ err.print().unwrap();
+ std::process::exit(0);
+ }
+ Err(err) => unwrap_or_exit(Err(AnyError::from(err))),
+ };
+ if !flags.v8_flags.is_empty() {
+ init_v8_flags(&*flags.v8_flags);
}
- Err(err) => unwrap_or_exit(Err(AnyError::from(err))),
- };
- if !flags.v8_flags.is_empty() {
- init_v8_flags(&*flags.v8_flags);
- }
- logger::init(flags.log_level);
+ logger::init(flags.log_level);
+
+ let exit_code = get_subcommand(flags).await;
+
+ exit_code
+ };
- let exit_code = unwrap_or_exit(run_basic(get_subcommand(flags)));
+ let exit_code = unwrap_or_exit(run_basic(exit_code));
std::process::exit(exit_code);
}