From bc51eca70000e809ef3b64f66e9482316768e02a Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 3 Sep 2024 01:27:37 +1000 Subject: BREAKING: remove `deno bundle` (#25339) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `deno bundle` now produces: ``` error: ⚠️ `deno bundle` was removed in Deno 2. See the Deno 1.x to 2.x Migration Guide for migration instructions: https://docs.deno.com/runtime/manual/advanced/migrate_deprecations ``` `deno bundle --help` now produces: ``` ⚠️ `deno bundle` was removed in Deno 2. See the Deno 1.x to 2.x Migration Guide for migration instructions: https://docs.deno.com/runtime/manual/advanced/migrate_deprecations Usage: deno bundle [OPTIONS] Options: -q, --quiet Suppress diagnostic output --unstable Enable all unstable features and APIs. Instead of using this flag, consider enabling individual unstable features To view the list of individual unstable feature flags, run this command again with --help=unstable ``` --- cli/tools/bundle.rs | 164 ---------------------------------------------------- cli/tools/mod.rs | 1 - 2 files changed, 165 deletions(-) delete mode 100644 cli/tools/bundle.rs (limited to 'cli/tools') diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs deleted file mode 100644 index f2157ecd8..000000000 --- a/cli/tools/bundle.rs +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. - -use std::path::PathBuf; -use std::sync::Arc; - -use deno_core::error::AnyError; -use deno_graph::Module; -use deno_terminal::colors; - -use crate::args::BundleFlags; -use crate::args::CliOptions; -use crate::args::Flags; -use crate::args::TsConfigType; -use crate::factory::CliFactory; -use crate::graph_util::error_for_any_npm_specifier; -use crate::util; -use crate::util::display; - -pub async fn bundle( - flags: Arc, - bundle_flags: BundleFlags, -) -> Result<(), AnyError> { - log::info!( - "{}", - colors::yellow("⚠️ Warning: `deno bundle` is deprecated and will be removed in Deno 2.0.\nUse an alternative bundler like \"deno_emit\", \"esbuild\" or \"rollup\" instead."), - ); - - if let Some(watch_flags) = &bundle_flags.watch { - util::file_watcher::watch_func( - flags, - util::file_watcher::PrintConfig::new( - "Bundle", - !watch_flags.no_clear_screen, - ), - move |flags, watcher_communicator, _changed_paths| { - let bundle_flags = bundle_flags.clone(); - Ok(async move { - let factory = CliFactory::from_flags_for_watcher( - flags, - watcher_communicator.clone(), - ); - let cli_options = factory.cli_options()?; - let _ = watcher_communicator.watch_paths(cli_options.watch_paths()); - bundle_action(factory, &bundle_flags).await?; - - Ok(()) - }) - }, - ) - .await?; - } else { - let factory = CliFactory::from_flags(flags); - bundle_action(factory, &bundle_flags).await?; - } - - Ok(()) -} - -async fn bundle_action( - factory: CliFactory, - bundle_flags: &BundleFlags, -) -> Result<(), AnyError> { - let cli_options = factory.cli_options()?; - let module_specifier = cli_options.resolve_main_module()?; - log::debug!(">>>>> bundle START"); - let module_graph_creator = factory.module_graph_creator().await?; - let cli_options = factory.cli_options()?; - - let graph = module_graph_creator - .create_graph_and_maybe_check(vec![module_specifier.clone()]) - .await?; - - let mut paths_to_watch: Vec = graph - .specifiers() - .filter_map(|(_, r)| { - r.ok().and_then(|module| match module { - Module::Js(m) => m.specifier.to_file_path().ok(), - Module::Json(m) => m.specifier.to_file_path().ok(), - // nothing to watch - Module::Node(_) | Module::Npm(_) | Module::External(_) => None, - }) - }) - .collect(); - - if let Ok(Some(import_map_path)) = cli_options - .resolve_specified_import_map_specifier() - .map(|ms| ms.and_then(|ref s| s.to_file_path().ok())) - { - paths_to_watch.push(import_map_path); - } - - // at the moment, we don't support npm specifiers in deno bundle, so show an error - error_for_any_npm_specifier(&graph)?; - - let bundle_output = bundle_module_graph(graph.as_ref(), cli_options)?; - log::debug!(">>>>> bundle END"); - let out_file = &bundle_flags.out_file; - - if let Some(out_file) = out_file { - let out_file = cli_options.initial_cwd().join(out_file); - let output_bytes = bundle_output.code.as_bytes(); - let output_len = output_bytes.len(); - util::fs::write_file(&out_file, output_bytes, 0o644)?; - log::info!( - "{} {:?} ({})", - colors::green("Emit"), - out_file, - colors::gray(display::human_size(output_len as f64)) - ); - if let Some(bundle_map) = bundle_output.maybe_map { - let map_bytes = bundle_map.as_bytes(); - let map_len = map_bytes.len(); - let ext = if let Some(curr_ext) = out_file.extension() { - format!("{}.map", curr_ext.to_string_lossy()) - } else { - "map".to_string() - }; - let map_out_file = out_file.with_extension(ext); - util::fs::write_file(&map_out_file, map_bytes, 0o644)?; - log::info!( - "{} {:?} ({})", - colors::green("Emit"), - map_out_file, - colors::gray(display::human_size(map_len as f64)) - ); - } - } else { - #[allow(clippy::print_stdout)] - { - println!("{}", bundle_output.code); - } - } - Ok(()) -} - -fn bundle_module_graph( - graph: &deno_graph::ModuleGraph, - cli_options: &CliOptions, -) -> Result { - log::info!("{} {}", colors::green("Bundle"), graph.roots[0]); - - let ts_config_result = - cli_options.resolve_ts_config_for_emit(TsConfigType::Bundle)?; - if !cli_options.type_check_mode().is_true() { - if let Some(ignored_options) = ts_config_result.maybe_ignored_options { - log::warn!("{}", ignored_options); - } - } - - let (transpile_options, emit_options) = - crate::args::ts_config_to_transpile_and_emit_options( - ts_config_result.ts_config, - )?; - deno_emit::bundle_graph( - graph, - deno_emit::BundleOptions { - minify: false, - bundle_type: deno_emit::BundleType::Module, - emit_options, - emit_ignore_directives: true, - transpile_options, - }, - ) -} diff --git a/cli/tools/mod.rs b/cli/tools/mod.rs index 1e1c65565..0b720e2ac 100644 --- a/cli/tools/mod.rs +++ b/cli/tools/mod.rs @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. pub mod bench; -pub mod bundle; pub mod check; pub mod clean; pub mod compile; -- cgit v1.2.3