summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorAsher Gomez <ashersaupingomez@gmail.com>2024-09-03 01:27:37 +1000
committerGitHub <noreply@github.com>2024-09-02 17:27:37 +0200
commitbc51eca70000e809ef3b64f66e9482316768e02a (patch)
treed9972377959be338e7192e7e53f94584432c263c /cli
parent503f95a54fe290471b0807157e37d2d996ff0357 (diff)
BREAKING: remove `deno bundle` (#25339)
`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 ```
Diffstat (limited to 'cli')
-rw-r--r--cli/args/flags.rs258
-rw-r--r--cli/args/mod.rs21
-rw-r--r--cli/bench/main.rs63
-rw-r--r--cli/graph_util.rs19
-rw-r--r--cli/main.rs4
-rw-r--r--cli/tools/bundle.rs164
-rw-r--r--cli/tools/mod.rs1
7 files changed, 7 insertions, 523 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index f20252352..991e71b06 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -99,13 +99,6 @@ pub struct BenchFlags {
}
#[derive(Clone, Debug, Eq, PartialEq)]
-pub struct BundleFlags {
- pub source_file: String,
- pub out_file: Option<String>,
- pub watch: Option<WatchFlags>,
-}
-
-#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CacheFlags {
pub files: Vec<String>,
}
@@ -445,7 +438,7 @@ pub enum DenoSubcommand {
Add(AddFlags),
Remove(RemoveFlags),
Bench(BenchFlags),
- Bundle(BundleFlags),
+ Bundle,
Cache(CacheFlags),
Check(CheckFlags),
Clean,
@@ -1053,14 +1046,6 @@ impl Flags {
}),
..
})
- | DenoSubcommand::Bundle(BundleFlags {
- watch:
- Some(WatchFlags {
- exclude: excluded_paths,
- ..
- }),
- ..
- })
| DenoSubcommand::Bench(BenchFlags {
watch:
Some(WatchFlags {
@@ -1656,30 +1641,10 @@ glob {*_,*.,}bench.{js,mjs,ts,mts,jsx,tsx}:
}
fn bundle_subcommand() -> Command {
- command("bundle", "⚠️ Warning: `deno bundle` is deprecated and will be removed in Deno 2.0.
-Use an alternative bundler like \"deno_emit\", \"esbuild\" or \"rollup\" instead.
-
-Output a single JavaScript file with all dependencies.
- deno bundle jsr:@std/http/file-server file_server.bundle.js
+ command("bundle", "⚠️ `deno bundle` was removed in Deno 2.
-If no output file is given, the output is written to standard output:
- deno bundle jsr:@std/http/file-server", UnstableArgsConfig::ResolutionOnly)
+See the Deno 1.x to 2.x Migration Guide for migration instructions: https://docs.deno.com/runtime/manual/advanced/migrate_deprecations", UnstableArgsConfig::ResolutionOnly)
.hide(true)
- .defer(|cmd| {
- compile_args(cmd)
- .hide(true)
- .arg(check_arg(true))
- .arg(
- Arg::new("source_file")
- .required_unless_present("help")
- .value_hint(ValueHint::FilePath),
- )
- .arg(Arg::new("out_file").value_hint(ValueHint::FilePath))
- .arg(watch_arg(false))
- .arg(watch_exclude_arg())
- .arg(no_clear_screen_arg())
- .arg(executable_ext_arg())
- })
}
fn cache_subcommand() -> Command {
@@ -4077,29 +4042,8 @@ fn bench_parse(flags: &mut Flags, matches: &mut ArgMatches) {
});
}
-fn bundle_parse(flags: &mut Flags, matches: &mut ArgMatches) {
- flags.type_check_mode = TypeCheckMode::Local;
-
- compile_args_parse(flags, matches);
- unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionOnly);
-
- let source_file = matches.remove_one::<String>("source_file").unwrap();
-
- let out_file =
- if let Some(out_file) = matches.remove_one::<String>("out_file") {
- flags.permissions.allow_write = Some(vec![]);
- Some(out_file)
- } else {
- None
- };
-
- ext_arg_parse(flags, matches);
-
- flags.subcommand = DenoSubcommand::Bundle(BundleFlags {
- source_file,
- out_file,
- watch: watch_arg_parse(matches),
- });
+fn bundle_parse(flags: &mut Flags, _matches: &mut ArgMatches) {
+ flags.subcommand = DenoSubcommand::Bundle;
}
fn cache_parse(flags: &mut Flags, matches: &mut ArgMatches) {
@@ -7722,174 +7666,6 @@ mod tests {
}
#[test]
- fn bundle() {
- let r = flags_from_vec(svec!["deno", "bundle", "source.ts"]);
- assert_eq!(
- r.unwrap(),
- Flags {
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "source.ts".to_string(),
- out_file: None,
- watch: Default::default(),
- }),
- type_check_mode: TypeCheckMode::Local,
- ..Flags::default()
- }
- );
- }
-
- #[test]
- fn bundle_with_config() {
- let r = flags_from_vec(svec![
- "deno",
- "bundle",
- "--no-remote",
- "--config",
- "tsconfig.json",
- "source.ts",
- "bundle.js"
- ]);
- assert_eq!(
- r.unwrap(),
- Flags {
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "source.ts".to_string(),
- out_file: Some("bundle.js".to_string()),
- watch: Default::default(),
- }),
- permissions: PermissionFlags {
- allow_write: Some(vec![]),
- ..Default::default()
- },
- no_remote: true,
- type_check_mode: TypeCheckMode::Local,
- config_flag: ConfigFlag::Path("tsconfig.json".to_owned()),
- ..Flags::default()
- }
- );
- }
-
- #[test]
- fn bundle_with_output() {
- let r = flags_from_vec(svec!["deno", "bundle", "source.ts", "bundle.js"]);
- assert_eq!(
- r.unwrap(),
- Flags {
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "source.ts".to_string(),
- out_file: Some("bundle.js".to_string()),
- watch: Default::default(),
- }),
- type_check_mode: TypeCheckMode::Local,
- permissions: PermissionFlags {
- allow_write: Some(vec![]),
- ..Default::default()
- },
- ..Flags::default()
- }
- );
- }
-
- #[test]
- fn bundle_with_lock() {
- let r =
- flags_from_vec(svec!["deno", "bundle", "--lock=lock.json", "source.ts"]);
- assert_eq!(
- r.unwrap(),
- Flags {
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "source.ts".to_string(),
- out_file: None,
- watch: Default::default(),
- }),
- type_check_mode: TypeCheckMode::Local,
- lock: Some(String::from("lock.json")),
- ..Flags::default()
- }
- );
- }
-
- #[test]
- fn bundle_with_reload() {
- let r = flags_from_vec(svec!["deno", "bundle", "--reload", "source.ts"]);
- assert_eq!(
- r.unwrap(),
- Flags {
- reload: true,
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "source.ts".to_string(),
- out_file: None,
- watch: Default::default(),
- }),
- type_check_mode: TypeCheckMode::Local,
- ..Flags::default()
- }
- );
- }
-
- #[test]
- fn bundle_nocheck() {
- let r = flags_from_vec(svec!["deno", "bundle", "--no-check", "script.ts"])
- .unwrap();
- assert_eq!(
- r,
- Flags {
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "script.ts".to_string(),
- out_file: None,
- watch: Default::default(),
- }),
- type_check_mode: TypeCheckMode::None,
- ..Flags::default()
- }
- );
- }
-
- #[test]
- fn bundle_watch() {
- let r = flags_from_vec(svec!["deno", "bundle", "--watch", "source.ts"]);
- assert_eq!(
- r.unwrap(),
- Flags {
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "source.ts".to_string(),
- out_file: None,
- watch: Some(Default::default()),
- }),
- type_check_mode: TypeCheckMode::Local,
- ..Flags::default()
- }
- )
- }
-
- #[test]
- fn bundle_watch_with_no_clear_screen() {
- let r = flags_from_vec(svec![
- "deno",
- "bundle",
- "--watch",
- "--no-clear-screen",
- "source.ts"
- ]);
- assert_eq!(
- r.unwrap(),
- Flags {
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "source.ts".to_string(),
- out_file: None,
- watch: Some(WatchFlags {
- hmr: false,
- no_clear_screen: true,
- exclude: vec![],
- }),
- }),
- type_check_mode: TypeCheckMode::Local,
- ..Flags::default()
- }
- )
- }
-
- #[test]
fn run_import_map() {
let r = flags_from_vec(svec![
"deno",
@@ -9389,30 +9165,6 @@ mod tests {
}
#[test]
- fn bundle_with_cafile() {
- let r = flags_from_vec(svec![
- "deno",
- "bundle",
- "--cert",
- "example.crt",
- "source.ts"
- ]);
- assert_eq!(
- r.unwrap(),
- Flags {
- subcommand: DenoSubcommand::Bundle(BundleFlags {
- source_file: "source.ts".to_string(),
- out_file: None,
- watch: Default::default(),
- }),
- type_check_mode: TypeCheckMode::Local,
- ca_data: Some(CaData::File("example.crt".to_owned())),
- ..Flags::default()
- }
- );
- }
-
- #[test]
fn upgrade_with_ca_file() {
let r = flags_from_vec(svec!["deno", "upgrade", "--cert", "example.crt"]);
assert_eq!(
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 030b19d80..aed5bc1b2 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -1136,9 +1136,6 @@ impl CliOptions {
pub fn resolve_main_module(&self) -> Result<ModuleSpecifier, AnyError> {
let main_module = match &self.flags.subcommand {
- DenoSubcommand::Bundle(bundle_flags) => {
- resolve_url_or_path(&bundle_flags.source_file, self.initial_cwd())?
- }
DenoSubcommand::Compile(compile_flags) => {
resolve_url_or_path(&compile_flags.source_file, self.initial_cwd())?
}
@@ -1265,23 +1262,7 @@ impl CliOptions {
&self,
config_type: TsConfigType,
) -> Result<TsConfigForEmit, AnyError> {
- let result = self.workspace().resolve_ts_config_for_emit(config_type);
-
- match result {
- Ok(mut ts_config_for_emit) => {
- if matches!(self.flags.subcommand, DenoSubcommand::Bundle(..)) {
- // For backwards compatibility, force `experimentalDecorators` setting
- // to true.
- *ts_config_for_emit
- .ts_config
- .0
- .get_mut("experimentalDecorators")
- .unwrap() = serde_json::Value::Bool(true);
- }
- Ok(ts_config_for_emit)
- }
- Err(err) => Err(err),
- }
+ self.workspace().resolve_ts_config_for_emit(config_type)
}
pub fn resolve_inspector_server(
diff --git a/cli/bench/main.rs b/cli/bench/main.rs
index 68f4c6ce3..72fa7e963 100644
--- a/cli/bench/main.rs
+++ b/cli/bench/main.rs
@@ -143,29 +143,6 @@ const EXEC_TIME_BENCHMARKS: &[(&str, &[&str], Option<i32>)] = &[
],
None,
),
- (
- "bundle",
- &[
- "bundle",
- "--unstable",
- "--config",
- "tests/config/deno.json",
- "tests/util/std/http/file_server_test.ts",
- ],
- None,
- ),
- (
- "bundle_no_check",
- &[
- "bundle",
- "--no-check",
- "--unstable",
- "--config",
- "tests/config/deno.json",
- "tests/util/std/http/file_server_test.ts",
- ],
- None,
- ),
];
const RESULT_KEYS: &[&str] =
@@ -314,40 +291,6 @@ fn get_binary_sizes(target_dir: &Path) -> Result<HashMap<String, i64>> {
Ok(sizes)
}
-const BUNDLES: &[(&str, &str)] = &[
- ("file_server", "./tests/util/std/http/file_server.ts"),
- ("welcome", "./tests/testdata/welcome.ts"),
-];
-fn bundle_benchmark(deno_exe: &Path) -> Result<HashMap<String, i64>> {
- let mut sizes = HashMap::<String, i64>::new();
-
- for (name, url) in BUNDLES {
- let path = format!("{name}.bundle.js");
- test_util::run(
- &[
- deno_exe.to_str().unwrap(),
- "bundle",
- "--unstable",
- "--config",
- "tests/config/deno.json",
- url,
- &path,
- ],
- None,
- None,
- None,
- true,
- );
-
- let file = PathBuf::from(path);
- assert!(file.is_file());
- sizes.insert(name.to_string(), file.metadata()?.len() as i64);
- let _ = fs::remove_file(file);
- }
-
- Ok(sizes)
-}
-
fn run_max_mem_benchmark(deno_exe: &Path) -> Result<HashMap<String, i64>> {
let mut results = HashMap::<String, i64>::new();
@@ -415,7 +358,6 @@ async fn main() -> Result<()> {
let mut args = env::args();
let mut benchmarks = vec![
- "bundle",
"exec_time",
"binary_size",
"cargo_deps",
@@ -465,11 +407,6 @@ async fn main() -> Result<()> {
..Default::default()
};
- if benchmarks.contains(&"bundle") {
- let bundle_size = bundle_benchmark(&deno_exe)?;
- new_data.bundle_size = bundle_size;
- }
-
if benchmarks.contains(&"exec_time") {
let exec_times = run_exec_time(&deno_exe, &target_dir)?;
new_data.benchmark = exec_times;
diff --git a/cli/graph_util.rs b/cli/graph_util.rs
index f1188505e..bfd547a12 100644
--- a/cli/graph_util.rs
+++ b/cli/graph_util.rs
@@ -26,7 +26,6 @@ use deno_graph::ModuleLoadError;
use deno_graph::WorkspaceFastCheckOption;
use deno_runtime::fs_util::specifier_to_file_path;
-use deno_core::anyhow::bail;
use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::parking_lot::Mutex;
@@ -35,7 +34,6 @@ use deno_graph::source::Loader;
use deno_graph::source::ResolutionMode;
use deno_graph::source::ResolveError;
use deno_graph::GraphKind;
-use deno_graph::Module;
use deno_graph::ModuleError;
use deno_graph::ModuleGraph;
use deno_graph::ModuleGraphError;
@@ -722,23 +720,6 @@ impl ModuleGraphBuilder {
}
}
-pub fn error_for_any_npm_specifier(
- graph: &ModuleGraph,
-) -> Result<(), AnyError> {
- for module in graph.modules() {
- match module {
- Module::Npm(module) => {
- bail!("npm specifiers have not yet been implemented for this subcommand (https://github.com/denoland/deno/issues/15960). Found: {}", module.specifier)
- }
- Module::Node(module) => {
- bail!("Node specifiers have not yet been implemented for this subcommand (https://github.com/denoland/deno/issues/15960). Found: node:{}", module.module_name)
- }
- Module::Js(_) | Module::Json(_) | Module::External(_) => {}
- }
- }
- Ok(())
-}
-
/// Adds more explanatory information to a resolution error.
pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String {
let mut message = format_deno_graph_error(error);
diff --git a/cli/main.rs b/cli/main.rs
index 1c545ea45..33ccc198c 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -110,9 +110,7 @@ async fn run_subcommand(flags: Arc<Flags>) -> Result<i32, AnyError> {
tools::bench::run_benchmarks(flags, bench_flags).await
}
}),
- DenoSubcommand::Bundle(bundle_flags) => spawn_subcommand(async {
- tools::bundle::bundle(flags, bundle_flags).await
- }),
+ DenoSubcommand::Bundle => exit_with_message("⚠️ `deno bundle` was removed in Deno 2.\n\nSee the Deno 1.x to 2.x Migration Guide for migration instructions: https://docs.deno.com/runtime/manual/advanced/migrate_deprecations", 1),
DenoSubcommand::Doc(doc_flags) => {
spawn_subcommand(async { tools::doc::doc(flags, doc_flags).await })
}
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<Flags>,
- 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<PathBuf> = 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<deno_emit::BundleEmit, AnyError> {
- 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;